<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.id"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="小区名称">
              <j-input placeholder="请输入小区名称" v-model="queryParam.platformName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="对账开始时间">
              <a-date-picker placeholder="对账开始时间" valueFormat="YYYY-MM-DD 00:00:00" v-model="queryParam.beginDate"></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 23:59:59" v-model="queryParam.endDate"></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-model-item label="对账状态">
              <a-select style="width: 100%" v-model="queryParam.companyAuditStatus" placeholder="请选择对账状态">
                <a-select-option v-for="item in audioStatusList" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
              </a-select>
            </a-form-model-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 :disabled="selectedRowKeys.length === 0" @click="onReconciliation()" type="primary" icon="audit">申请对账</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"  :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <a href="javascript:;" @click="propertyDetails(1, record.id)">详情</a>
          <template v-if="record.companyAuditStatus === 'companyWaitAudit'">
            <a-divider type="vertical" />
            <a href="javascript:;" @click="propertyDetails(2, record.id)">审核</a>
          </template>
          <template v-if="record.companyAuditStatus === 'companyAuditPass' && !record.centralAuditStatus">
            <a-divider type="vertical" />
            <a href="javascript:;" @click="onReconciliation(record.id)">申请对账</a>
          </template>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
import { companySubCentralApi } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterDictTextByStatic, COMPANY_AUDIT_STATUS, CENTRAL_AUDIT_STATUS } from '@/assets/static.js'

const columns = [
  {
    title: '对账单号',
    dataIndex: 'id',
    key: 'id',
    align: 'center',
  },
  {
    title: '所属小区',
    dataIndex: 'platformName',
    key: 'platformName',
    align: 'center',
  },
  {
    title: '对账开始日期',
    dataIndex: 'reconciliationBeginDate',
    key: 'reconciliationBeginDate',
    align: 'center',
  },
  {
    title: '对账结束日期',
    dataIndex: 'reconciliationEndDate',
    key: 'reconciliationEndDate',
    align: 'center',
  },
  {
    title: '对账金额',
    dataIndex: 'reconciliationAmount',
    key: 'reconciliationAmount',
    align: 'center',
  },
  {
    title: '操作日期',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center',
  },
  {
    title: '操作人',
    dataIndex: 'createBy',
    key: 'createBy',
    align: 'center',
  },
  {
    title: '审核状态',
    dataIndex: 'companyAuditStatus',
    key: 'companyAuditStatus',
    align: 'center',
    customRender: function (text) {
      return filterDictTextByStatic(COMPANY_AUDIT_STATUS, text)
    }
  },
  {
    title: '总平台审核状态',
    dataIndex: 'centralAuditStatus',
    key: 'centralAuditStatus',
    align: 'center',
    customRender: function (text) {
      return filterDictTextByStatic(CENTRAL_AUDIT_STATUS, text)
    },
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    fixed: 'right',
    width: 150,
  },
]

export default {
  name: 'PermissionListAsync',
  mixins: [JeecgListMixin],
  data() {
    return {
      audioStatusList: COMPANY_AUDIT_STATUS,
      columns: columns,
      url: {
        list: '/property-community/property/communityReconciliation/companyAuditList',
        delete: '/property-central/property/communityReconciliation/delete',
        deleteBatch: '/property-central/property/communityReconciliation/deleteBatch',
      }
    }
  },
  methods: {
    propertyDetails(type, id) {
      this.$router.push({
        path: '/base/RecordDetails?type=' + type +'&id=' + id
      })
    },
    onLoadDetail(record, type) {
      record['registAdress'] = [record.provinceCode, record.cityCode, record.countyCode]
      if (type === 'edit') {
        this.handleEdit(record)
      } else {
        this.handleDetail(record)
      }
    },
    onReconciliation(id) {
      let ids = id || this.selectedRowKeys.join(',')
      let that = this
      this.$confirm({
        title: '确认要申请当前对账吗？',
        closable: true,
        okText: '确认',
        onOk() {
          return companySubCentralApi({
            ids
          }).then((res) => {
            that.$message.success('申请对账成功！')
            that.searchQuery()
          })
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>