<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.centralAuditStatus" 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-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div> -->

    <!-- table区域-begin -->
    <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="action" slot-scope="text, record">
          <a href="javascript:;" @click="propertyDetails(1, record.id)">详情</a>
          <template v-if="record.centralAuditStatus === 'centralWaitAudit'">
            <a-divider type="vertical" />
            <a href="javascript:;" @click="propertyDetails(2, record.id)">审核</a>
          </template>
          <template v-if="record.centralAuditStatus === 'centralAuditPass' && record.appropriationStatus !== 'appropriationed'">
            <a-divider type="vertical" />
            <a href="javascript:;" @click="onReconciliation(record.id)">拨款</a>
          </template>
        </span>
      </a-table>

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

    <property-settled-modal ref="modalForm" @ok="modalFormOk"></property-settled-modal>

    <!-- 右侧的角色权限配置 -->
    <user-role-modal ref="modalUserRole"></user-role-modal>
  </a-card>
</template>

<script>
import { appropriationApi } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import PropertySettledModal from './modules/PropertySettledModal'
import UserRoleModal from './modules/UserRoleModal'
import { filterDictTextByStatic, COMPANY_AUDIT_STATUS, CENTRAL_AUDIT_STATUS, APPROPRIATION_STATUS } from '@/assets/static.js'

const columns = [
  {
    title: '对账单号',
    dataIndex: 'id',
    key: 'id',
    align: 'center',
  },
  {
    title: '所属小区',
    dataIndex: 'platformName',
    key: 'platformName',
    align: 'center',
  },
  {
    title: '所属物业集团',
    dataIndex: 'propertyName',
    key: 'propertyName',
    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: 'centralAuditStatus',
    customRender: function (text) {
      return filterDictTextByStatic(CENTRAL_AUDIT_STATUS, text)
    },
    align: 'center',
  },
  {
    title: '物业审核状态',
    dataIndex: 'companyAuditStatus',
    key: 'companyAuditStatus',
    customRender: function (text) {
      return filterDictTextByStatic(COMPANY_AUDIT_STATUS, text)
    }
  },
  {
    title: '拨款状态',
    dataIndex: 'appropriationStatus',
    customRender: function (text) {
      return filterDictTextByStatic(APPROPRIATION_STATUS, text)
    },
    align: 'center',
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    fixed: 'right',
    width: 150,
  },
]

export default {
  name: 'PermissionListAsync',
  mixins: [JeecgListMixin],
  components: {
    PropertySettledModal,
    UserRoleModal,
  },
  data() {
    return {
      audioStatusList: CENTRAL_AUDIT_STATUS,
      columns: columns,
      url: {
        list: '/property-community/property/communityReconciliation/centralAuditList',
        delete: '/property-central/property/communityReconciliation/delete',
        deleteBatch: '/property-central/property/communityReconciliation/deleteBatch',
      }
    }
  },
  methods: {
    propertyDetails(type, id) {
      this.$router.push({
        path: '/settled/RecordDetails?id=' + id +'&type=' + type,
      })
    },
    onReconciliation(id) {
      let that = this
      this.$confirm({
        title: '确认要拨款吗？',
        closable: true,
        okText: '确认',
        onOk() {
          return appropriationApi({
            id
          }).then((res) => {
            that.$message.success('拨款成功！')
            that.searchQuery()
          })
        }
      })
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>