<!-- 合规抽查审核 -->
<template>
  <div>
    <up-down-layout :header="$t('complianceCheck.complianceAuditTitle')" :handleFlag.sync="handleFlag">
      <search-form @clearParam="clearParam" @handleFilter="handleFilter" :formValue.sync="queryParas"
                   v-model="queryParas" :componentList="componentList" slot="query"
                   :menuCode="menuId" searchPerms="search" resetPerms="reset"></search-form>
      <template slot="table">
        <data-table :handleFlag.sync="handleFlag" :queryParas="queryParas" :menuFlag="true"
                    :sourceData.sync="sourceData" :loadCount.sync="loadCount" ref="sourceTable"
                    operateBtnLayout="" :columns="columns" :api="api" v-bind="elHeightObj"
                    :headTitle="$t('complianceCheck.complianceAuditTable')">
          <el-table-column :label="$t('common.operate')" align="center" fixed="right" width="120px">
            <template slot-scope="scope">
              <auth-button v-if="scope.row.auditStatus === '0'" class="iconCircle" icon="iconfont iconlingqu" :title="$t('complianceCheck.receive')" @click="receive(scope.row)"></auth-button>
              <auth-button v-if="scope.row.auditStatus === '2'" class="iconCircle" icon="iconfont iconbanli-active" :title="$t('complianceCheck.deal')" @click="showEdit(scope.row)"></auth-button>
            </template>
          </el-table-column>
        </data-table>
      </template>
    </up-down-layout>
    <dealEdit :visible.sync="showDetail" :editModel="editModel" :form="item" @deal-success="handleFilter"></dealEdit>
  </div>
</template>
<script>
import BasePage from '@/pages/basePage.js'
import { authButton, upDownLayout, searchForm, DataTable, SelectProductName, SelectCoreEnterpriseCascade, SelectFinancialInstitutionsCascade } from 'newepoch-components'
import dealEdit from '@/pages/dataAudit/compliance/dealDetailEdit.vue'
import complianceApi from '@/api/dataAudit/complianceApi.js'
import * as format from '@/filters/index'
import cn from '@/i18n/langs/cn.js'
import { regExp } from '@/validator/index.js'
import mixin from '@/pages/mixin.js'

const { complianceCheck, common } = cn
// import SelectProduct from '@/components/element/SelectProduct'
// import SelectProCoreEnterprise from '@/components/element/SelectProCoreEnterprise'
// import SelectPlanManager from '@/components/element/SelectPlanManager'
// import * as format from '@/filters/index.js'

export default {
  name: 'complianceAuditList',
  extends: new BasePage(),
  mixins: [mixin],
  components: {
    upDownLayout,
    searchForm,
    DataTable,
    authButton,
    dealEdit,
    SelectProductName,
    SelectCoreEnterpriseCascade,
    SelectFinancialInstitutionsCascade
  },
  data () {
    return {
      item: {},
      editModel: '',
      showDetail: false,
      queryParas: {},
      sourceData: [],
      componentList: [
        // 产品名称
        {
          label: complianceCheck.project,
          value: 'projectId',
          disabled: false,
          componentName: SelectProductName,
          labelWidth: '160px'
        },
        // 核心企业
        {
          label: complianceCheck.coreEnterprise,
          value: 'coreEnterpriseId',
          queryName: 'projectId',
          queryValue: 'projectId',
          disabled: false,
          componentName: SelectCoreEnterpriseCascade,
          labelWidth: '160px'
        },
        // 计划管理人/再保理银行
        {
          label: complianceCheck.planningManagerName,
          value: 'planningManagerId',
          queryName: 'projectId',
          queryValue: 'projectId',
          disabled: false,
          componentName: SelectFinancialInstitutionsCascade,
          labelWidth: '160px'
        },
        // 期数
        {
          label: complianceCheck.periods,
          value: 'specialPlanPeriods',
          disabled: false,
          componentName: 'el-input',
          placeholder: common.pleaseInput,
          labelWidth: '160px'
        },
        // 合规抽查审核状态
        {
          label: this.$i18n.messages[this.$i18n.locale].complianceCheck.auditStatus,
          value: 'auditStatus',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'check_examine_status',
          labelWidth: '160px'
        },
        // 付款确认书编号
        {
          label: this.$i18n.messages[this.$i18n.locale].complianceCheck.payCode,
          value: 'assetCode',
          disabled: false,
          componentName: 'el-input',
          placeholder: common.pleaseInput,
          labelWidth: '160px'
        }
      ],
      columns: [
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: complianceCheck.coreEnterprise,
          width: '200px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'planningManagerName',
          align: 'left',
          label: complianceCheck.planningManagerName,
          width: '200px'
        },
        // 期数
        {
          prop: 'specialPlanPeriods',
          align: 'right',
          label: complianceCheck.periods,
          width: '120px'
        },
        // 供应商名称
        {
          prop: 'creditor',
          align: 'left',
          label: complianceCheck.supplierName,
          width: '200px'
        },
        // 项目公司名称
        {
          prop: 'debtor',
          align: 'left',
          label: complianceCheck.projectCompanyName,
          width: '200px'
        },
        // 付款确认书编号
        {
          prop: 'assetCode',
          align: 'left',
          label: complianceCheck.payCode,
          width: '200px'
        },
        // 审核人
        {
          prop: 'auditorsName',
          align: 'center',
          label: complianceCheck.auditPerson,
          width: '120px'
        },
        // 合规抽查审核状态
        {
          prop: 'auditStatus',
          align: 'center',
          label: complianceCheck.auditStatus,
          format: (row) => { return format.formatDict(row.auditStatus, 'check_examine_status') },
          width: '140px'
        }
      ]
    }
  },
  computed: {
    api () {
      return complianceApi.assetAuditApi
    }
  },
  mounted () {
    this.handleFilter()
  },
  methods: {
    // 重写查询
    handleFilter () {
      // 期数数字校验
      if (!this.UtilJs.isEmpty(this.queryParas.specialPlanPeriods) && !regExp.number.test(this.queryParas.specialPlanPeriods)) {
        return this.warning(complianceCheck.specialPlanPeriodsCheck)
      }
      this.$refs.sourceTable.loadTableData()
    },
    // 领取
    receive (row) {
      let _this = this
      const { keyId, assetCode } = row
      let pushRuleDto = {
        keyId: keyId,
        payCode: assetCode,
        userId: _this.$store.getters.user.userId,
        userName: _this.$store.getters.user.nickName
      }
      complianceApi.assetAuditApi.receiveTask(pushRuleDto).then(res => {
        if (res && res.data) {
          _this.success(complianceCheck.receiveSucMsg)
          _this.handleFilter()
        } else {
          _this.error(complianceCheck.receiveFailMsg)
        }
      })
    },
    // 办理
    showEdit (row) {
      this.item = Object.assign({}, row)
      this.editModel = 'E'
      this.showDetail = true
    },
    // 重置
    clearParam () {
      this.queryParas = {
        projectId: '',
        coreEnterpriseId: '',
        planningManagerId: '',
        specialPlanPeriods: '',
        auditStatus: '',
        assetCode: '',
        pageIndex: 1,
        pageSize: 10
      }
    }
  },
  watch: {
    'queryParas.projectId' (now, old) {
      if (now !== old) {
        this.$set(this.queryParas, 'coreEnterpriseId', '')
        this.$set(this.queryParas, 'planningManagerId', '')
      }
    }
  }
}
</script>
<style scoped>
</style>
