<!-- 保理进度查询 -->
<template>
  <div>
    <up-down-layout :header="$t('factorRateList.head')" :handleFlag.sync="handleFlag" :footerFlag.sync="footerFlag">
      <search-form
        @handleFilter="customHandleFilter"
        @clearParam="clearParam"
        :menuCode="menuId"
        searchPerms="searchPerms"
        :formValue.sync="queryParas"
        :componentList="componentList"
        resetPerms="resetPerms"
        @selectChanged="selectChanged"
        slot="query">
      </search-form>
      <template slot="table">
        <data-table
          :headTitle="$t('factorRateList.headCenter')"
          :toolMenuFlag="true"
          :btnCreate="false"
          :queryParas="queryParas"
          :btnDels="false"
          :menuFlag="true"
          v-bind="elHeightObj"
          :operateBtnLayout="''"
          :columns="columns"
          :sourceData="sourceData"
          :api="api"
          :loadCount="loadCount">
        </data-table>
      </template>
    </up-down-layout>
  </div>
</template>

<script>
import { upDownLayout, searchForm, DataTable } from 'newepoch-components'
import BasePage from '@/pages/basePage'
import SelectProductName from '@/components/element/shourang/SelectProductName'
import SelectArea from '@/components/element/enterpriseInfoManage/SelectArea'
import factorRateListApi from '@/api/factorRateListApi'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin'
import { regExp } from '@/validator/index'
import componentsApi from '@/api/componentsApi'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  name: 'factorRateList',
  components: {
    upDownLayout,
    searchForm,
    DataTable
  },
  computed: {
    api () {
      return factorRateListApi.factorRateList
    }
  },
  data () {
    return {
      footerFlag: true,
      queryParas: {},
      sourceData: [],
      componentList: [
        // 付款确认书编号
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.paymentConfNum,
          value: 'assetCode',
          clearable: true,
          componentName: 'el-input',
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.inputPaymentConfNum,
          labelWidth: '110px'
        },
        // 产品名称
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.productName,
          value: 'projectId',
          name: 'projectId',
          componentName: SelectProductName,
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.selectproductName,
          labelWidth: '110px'
        },
        // 期数
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.periodsNum,
          value: 'specialPlanPeriods',
          componentName: 'el-input',
          clearable: true,
          disabled: false,
          maxlength: '3',
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.inputInt,
          labelWidth: '110px'
        },
        // 供应商名称
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.supplierName,
          value: 'creditor',
          componentName: 'el-input',
          clearable: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.inputSupplierName,
          labelWidth: '110px'
        },
        // 项目公司名称
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.projectCompName,
          value: 'debtor',
          componentName: 'el-input',
          clearable: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.inputProjectCompName,
          labelWidth: '110px'
        },
        // 区域
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.region,
          value: 'coreAreaId',
          componentName: SelectArea,
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.selectregion,
          labelWidth: '110px',
          multiple: false
        },
        // 区域编号
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.areaNumber,
          value: 'regionCode',
          componentName: 'el-input',
          clearable: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.inputAreaNumber,
          labelWidth: '110px'
        },
        // 批次日期
        {
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.batchDate,
          value: 'factoringApplyTime',
          componentName: 'el-date-picker',
          clearable: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].factorRateList.selectBatchDate,
          labelWidth: '110px',
          format: 'timestamp'
        }
      ],
      columns: [
        // 付款确认书编号
        {
          prop: 'assetCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.paymentConfNum,
          width: '150px'
        },
        // 期数
        {
          prop: 'specialPlanPeriods',
          align: 'left',
          sortable: true,
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.periodsNum,
          width: '75px',
          format: (row) => {
            if (!row.specialPlanPeriods || row.specialPlanPeriods.toString() === '0') {
              return ''
            }
            return row.specialPlanPeriods
          }
        },
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.coreEnterprises,
          width: '100px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'planningManagerName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.refactorBank,
          width: '200px'
        },
        // 供应商名称
        {
          prop: 'creditor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.supplierName,
          width: '200px'
        },
        // 项目公司
        {
          prop: 'debtor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.projectComp,
          width: '200px'
        },
        // 区域编号
        {
          prop: 'regionCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.areaNumber,
          width: '150px'
        },
        // 区域
        {
          prop: 'coreAreaName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.region,
          width: '150px'
        },
        // 批次日期
        {
          prop: 'factoringApplyTime',
          align: 'center',
          sortable: true,
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.batchDate,
          width: '120px',
          format: (row) => {
            let batchDate = format.formatDateTpcModify(row.factoringApplyTime)
            return batchDate
          }
        },
        // 账款到期日
        {
          prop: 'dueDate',
          align: 'center',
          sortable: true,
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.accountMaturityDate,
          width: '120px',
          format: (row) => {
            return format.formatDateTpcModify(row.dueDate)
          }
        },
        // 应收账款金额(元)
        {
          prop: 'factoringMoney',
          align: 'right',
          sortable: true,
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.receivableAmount,
          width: '160px',
          format: (row) => {
            if (row.factoringMoney === 0) {
              return ''
            }
            return format.thousandFilter(row.factoringMoney)
          }
        },
        // 保理进度
        {
          prop: 'assetStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.factoringProgress,
          width: '100px',
          format: (row) => {
            if (row.assetStatus === '0') return ''
            return format.formatDict(row.assetStatus, 'SCRS0110')
          }
        },
        // 供应商利率
        {
          prop: 'suppliersInterest',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.supplierInterestRate,
          width: '100px',
          format: (row) => {
            if (row.suppliersInterest === 0 || !row.suppliersInterest) {
              return ''
            }
            return (row.suppliersInterest * 100).toFixed(2)
            // return (row.suppliersRateBiz * 100)
          }
        },
        // 放款日期
        {
          prop: 'loanDateFactoring',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.LoanDate,
          width: '100px',
          format: (row) => {
            return format.formatDateTpcModify(row.loanDateFactoring)
          }
        },
        // 放款金额（元）
        {
          prop: 'loanAmountFactoring',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.loanAmount,
          width: '120px',
          format: (row) => {
            if (row.loanAmountFactoring === 0) {
              return ''
            }
            return format.thousandFilter(row.loanAmountFactoring)
          }
        },
        // 保理利息
        {
          prop: 'factoringRate',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.factoringInterest,
          width: '100px',
          format: (row) => {
            if (row.factoringRate === 0) {
              return ''
            }
            return format.thousandFilter(row.factoringRate)
          }
        },
        // 是否开票
        {
          prop: 'openInvoiceStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.whetherInvoice,
          width: '120px',
          format: (row) => {
            return format.formatDict(row.openInvoiceStatus, 'SCRS0111')
          }
        },
        // 发票号码
        {
          prop: 'invoiceNo',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].factorRateList.invoiceNum,
          width: '100px'
        }
        // // 是否回寄
        // {
        //   prop: 'ifsSendBack',
        //   align: 'left',
        //   label: this.$i18n.messages[this.$i18n.locale].factorRateList.whetherSendBack,
        //   width: '80px',
        //   format: (row) => {
        //     return format.formatDict(row.ifsSendBack, 'ZD0003')
        //   }
        // },
        // // 回寄单号
        // {
        //   prop: 'sendBackNo',
        //   align: 'left',
        //   label: this.$i18n.messages[this.$i18n.locale].factorRateList.returnDocumentNum,
        //   width: '100px',
        //   format: (row) => {
        //     return format.formatDict(row.sendBackNo, 'ZD0003')
        //   }
        // }
      ]
    }
  },
  methods: {
    clearParam () {
      this.queryParas = {
        pageIndex: 1,
        pageSize: 10
      }
      this.selectChangeLocal('1')
    },
    selectChanged (a) {
      if (a.hasOwnProperty('projectIdInfo')) {
        if (a.projectIdInfo && a.projectIdInfo.keyId) {
          this.getTypeById(a.projectIdInfo.keyId)
        } else {
          this.selectChangeLocal('1')
        }
      }
    },
    // 改变选择信息、日期
    selectChangeLocal (isAbs) {
      this.componentList[2].disabled = isAbs !== '1'
      if (this.componentList[2].disabled) {
        this.componentList[2].placeholder = ' '
      } else {
        this.componentList[2].placeholder = this.$i18n.messages[this.$i18n.locale].factorRateList.inputInt
      }
    },
    // 根据ID获取产品类别
    getTypeById (projectId) {
      componentsApi.productenterprise.getclassify({ projectId: projectId }).then(res => {
        var a = res.data ? res.data.productType : '2'
        this.selectChangeLocal(a)
      })
    },
    customHandleFilter () {
      if (!this.UtilJs.isEmpty(this.queryParas.specialPlanPeriods) && !regExp.number.test(this.queryParas.specialPlanPeriods)) {
        return this.warning(this.$i18n.messages[this.$i18n.locale].expressDataList.specialPlanPeriodsCheck)
      }
      this.queryParas.coreArea = ''
      if (this.queryParas.coreAreaId && this.queryParas.coreAreaId.length > 0) {
        this.queryParas.coreArea = this.queryParas.coreAreaId[1]
      }
      this.handleFilter()
    }
  }
}
</script>

<style scoped>

</style>
