<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="订单编号">
              <j-input placeholder="请输入订单编号" v-model="queryParam.orderNum"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="状态">
              <a-select style="width: 100%" v-model="queryParam.reconciliationStatus" placeholder="请选择状态">
                <a-select-option v-for="item in auditList" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="提交开始时间">
              <a-date-picker placeholder="提交开始时间" valueFormat="YYYY-MM-DD" v-model="queryParam.createTime_begin"></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="提交结束时间">
              <a-date-picker placeholder="提交结束时间" valueFormat="YYYY-MM-DD" v-model="queryParam.createTime_end"></a-date-picker>
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="propertyDetails(1)" type="primary" icon="plus">新增</a-button> -->
      <!-- <a-button icon="download" @click="handleExportXls('t_property_settled')">导出</a-button> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="onBatchVerify"><a-icon type="audit" />批量审核</a-menu-item>
        </a-menu>
        <a-button type="primary" style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" v-if="selectedRowKeys.length > 0" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="orderSource">小程序</span>
        <span slot="communityName" slot-scope="text, record">
          <span>{{record.platformType === 'company' ? record.communityName : ''}}</span>
        </span>
        <span slot="partnersName" slot-scope="text, record">
          <span>{{record.platformType === 'partner' ? record.partnersName : ''}}</span>
        </span>
        <span slot="shopName" slot-scope="text, record">
          <span>{{record.platformType === 'shop' ? record.shopName : ''}}</span>
        </span>
        <span slot="action" slot-scope="text, record">
          <a href="javascript:;" @click="propertyDetails(1, record.id)">详情</a>

          <template v-if="record.reconciliationStatus === 2">
            <a-divider type="vertical" />
            <a href="javascript:;" @click="propertyDetails(2, record.id)">审核</a>
          </template>
        </span>
      </a-table>

    </div>
    <!-- table区域-end -->

  </a-card>
</template>

<script>
import { auditPropertyApi, freezeOrPropertyApi } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterDictTextByStatic, FENLICENTRAL_AUDIT_STATUS, PAY_WAY } from '@/assets/static.js'

const columns = [
  {
    title: '结算单号',
    dataIndex: 'balanceNum',
    key: 'balanceNum',
    align: 'center',
  },
  {
    title: '订单编号',
    dataIndex: 'orderNum',
    key: 'orderNum',
    align: 'center',
  },
  {
    title: '提交时间',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center',
  },
  {
    title: '用户账号',
    dataIndex: 'buyerName',
    key: 'buyerName',
    align: 'center',
  },
  {
    title: '分利金额',
    dataIndex: 'shareMoney',
    key: 'shareMoney',
    align: 'center',
  },
  {
    title: '支付方式',
    dataIndex: 'payWay',
    key: 'payWay',
    align: 'center',
    customRender: function (text) {
      return filterDictTextByStatic(PAY_WAY, text)
    }
  },
  {
    title: '订单来源',
    dataIndex: 'orderSource',
    key: 'orderSource',
    align: 'center',
    scopedSlots: { customRender: 'orderSource' }
  },
  {
    title: '订单状态',
    dataIndex: 'reconciliationStatus',
    key: 'reconciliationStatus',
    align: 'center',
    customRender: function (text) {
      return filterDictTextByStatic(FENLICENTRAL_AUDIT_STATUS, text)
    }
  },
  {
    title: '备注',
    dataIndex: 'remarks',
    key: 'remarks',
    align: 'center',
  },
  {
    title: '所属平台',
    dataIndex: 'propertyName',
    key: 'propertyName',
    align: 'center',
  },
  {
    title: '所属小区',
    dataIndex: 'communityName',
    key: 'communityName',
    align: 'center',
    scopedSlots: { customRender: 'communityName' }
  },
  {
    title: '合作伙伴',
    dataIndex: 'partnersName',
    key: 'partnersName',
    align: 'center',
    scopedSlots: { customRender: 'partnersName' }
  },
  {
    title: '商铺',
    dataIndex: 'shopName',
    key: 'shopName',
    align: 'center',
    scopedSlots: { customRender: 'shopName' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    fixed: 'right',
    width: 150
  },
]

export default {
  name: 'PermissionListAsync',
  mixins: [JeecgListMixin],
  data() {
    return {
      auditList: FENLICENTRAL_AUDIT_STATUS,
      columns: columns,
      url: {
        list: '/property-central/partners/shareBenefit/list'
      }
    }
  },
  methods: {
    propertyDetails(type, id) {
      this.$router.push({
        path: '/benefits/ReconciliationDetails?id=' + id +'&type=' + type,
      })
    },
    onLoadDetail(record, type) {
      record['registAdress'] = [record.provinceCode, record.cityCode, record.countyCode]
      if (type === 'edit') {
        this.handleEdit(record)
      } else {
        this.handleDetail(record)
      }
    },
    onBatchVerify(record) {
      let that = this
      this.$confirm({
        title: '确认批量审核此?',
        closable: true,
        okText: '审核通过',
        cancelText: '审核驳回',
        onOk() {
          // return auditPropertyApi({
          //   id: record.id,
          //   auditStatus: 'auditPass',
          // }).then((res) => {
          //   that.searchQuery()
          // })
        },
        onCancel() {
          // return auditPropertyApi({
          //   id: record.id,
          //   auditStatus: 'refuse',
          // }).then((res) => {
          //   that.searchQuery()
          // })
        },
      })
    },
    onStatus(record) {
      let that = this
      this.$confirm({
        title: `确认${record.propertyStatus === 'normal' ? '冻结' : '解冻'}此物业?`,
        closable: true,
        okText: `${record.propertyStatus === 'normal' ? '冻结' : '解冻'}`,
        onOk() {
          return freezeOrPropertyApi({
            id: record.id,
            status: `${record.propertyStatus === 'normal' ? 'freeze' : 'normal'}`,
          }).then((res) => {
            that.searchQuery()
          })
        },
        onCancel() {},
      })
    },
    handlePerssion(roleId) {
      this.$refs.modalUserRole.show(roleId)
    },
    // loadData() {
    //   console.log('不请求')
    // }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>