<!--履历-->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :title="$t('ladingManageList.record')" width="1000px" :api="api" :form="form" :editModel="editModel">
      <data-table :operateBtnLayout="operateBtnLayout" :columns="columns"
                  ref="dataTable" v-bind="styleClass" @getTableData="getTableData"
                  :headTitle="$t('ladingManageList.recordInfoList')" :cellStyle="cellStyle"
                  :menuFlag="false" :sourceData.sync="sourceData" :showPage="false">
      </data-table>
    </dialog-edit>
  </div>
</template>

<script>
import { DialogEdit, DataTable, authButton } from 'newepoch-components'
import BaseEditPage from '@/pages/baseEditPage'
import ladingManageApi from '@/api/ladingManageApi'
import * as format from '@/filters/index'
export default {
  extends: new BaseEditPage(''),
  components: {
    DialogEdit,
    DataTable,
    authButton
  },
  data () {
    return {
      operateBtnLayout: '',
      styleClass: { maxHeight: 400 },
      sourceData: [],
      columns: [
        // 产品名称
        {
          prop: 'projectName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.productName,
          width: '200px'
        },
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.coreEnterprises,
          width: '200px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'planningManagerName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.refactorBank,
          width: '200px'
        },
        // 期数
        {
          prop: 'specialPlanPeriods',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.qishuPiCi,
          width: '120px',
          format: (row) => {
            if (this.UtilJs.isEmpty(row.specialPlanPeriods)) {
              return format.formatDateTpcModify(row.factoringApplyTime)
            } else {
              return row.specialPlanPeriods
            }
          }
        },
        // 提单模式
        // {
        //   prop: 'ladingType',
        //   align: 'left',
        //   label: this.$i18n.messages[this.$i18n.locale].ladingManageList.ladingMode,
        //   width: '200px',
        //   format: (row) => { return format.formatDict(row.ladingType, 'ZD0100') }
        // },
        // 原始权益人
        {
          prop: 'initialOwnersName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.rightsHolder,
          width: '200px'
        },
        // 资产服务机构
        {
          prop: 'assetServiceName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.assetServiceOrgan,
          width: '200px'
        },
        // 供应商名称
        {
          prop: 'creditor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.supplierName,
          width: '200px'
        },
        // 应收账款金额
        {
          prop: 'factoringMoney',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.accountReceivable,
          width: '200px',
          format: (row) => { return format.thousandFilter(row.factoringMoney) }
        },
        // 项目公司名称
        {
          prop: 'debtor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectCompanyName,
          width: '200px'
        },
        // 开户行
        {
          prop: 'receiverBank',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.openingBank,
          width: '200px'
        },
        // 收款账号
        {
          prop: 'receiverBankAccount',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.payAccount,
          width: '200px'
        },
        // 合同名称
        {
          prop: 'basicContractName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.contractName,
          width: '200px'
        },
        // 合同编号
        {
          prop: 'basicContractCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.contractNum,
          width: '200px'
        },
        // 发票号码
        {
          prop: 'invoiceNo',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceNum,
          width: '200px'
        },
        // 发票金额
        {
          prop: 'taxExcludingAmount',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceAmount,
          width: '150px',
          format: (row) => { return format.thousandFilter(row.taxExcludingAmount) }
        },
        // 内引
        {
          prop: 'innerLead',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.internalReference,
          width: '100px'
        },
        // UUID
        {
          prop: 'uuid',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.UUID,
          width: '100px'
        },
        // 确认提单状态
        {
          prop: 'officalLadingConfirmStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.confirmationLadingStatus,
          width: '120px',
          format: (row) => { return format.formatDict(row.officalLadingConfirmStatus, 'ZD0032') }
        },
        // 修改时间
        {
          prop: 'modifyTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.modifyTime,
          width: '160px',
          format: (row) => { return format.formatCheckDatetime(row.modifyTime, 'yyyy-MM-dd hh:mm') }
        },
        // 修改人
        {
          prop: 'modifyUserName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.modifyUser,
          width: '100px'
        }
      ]
    }
  },
  mounted () {
  },
  computed: {
    api: function () {
      return ladingManageApi.recordInfoEdit
    },
    dialogVisible: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      if (row.recordModifyFields instanceof Array) {
        let flag = false
        row.recordModifyFields.forEach(it => {
          if (it === column.property) {
            flag = true
          }
        })
        if (flag) {
          return 'color: red'
        } else {
          return ''
        }
      } else {
        return ''
      }
    },
    getTableData (data) {
      data.forEach(it => {
        it = Object.assign(it, it.poolInfo)
      })
      return data
    },
    getRemetData () {
      let $this = this
      $this.$refs.dataTable.vLoading = true
      this.api.getList({ assetInfoId: this.form.keyId, type: '2' }).then(res => {
        if (res.success) {
          $this.sourceData = this.getTableData(res.data)
          $this.sourceData.forEach(it => {
            if (this.UtilJs.isEmpty(it.specialPlanPeriods) || it.specialPlanPeriods.toString() === '0') {
              it.specialPlanPeriods = ''
            }
          })
        } else {
          $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.getresumeFailed)
        }
      }).finally(res => {
        this.$refs.dataTable.vLoading = false
      })
    }
  },
  watch: {
    dialogVisible (newVal) {
      if (newVal) {
        this.$nextTick(() => {
          this.getRemetData()
        })
      } else {
      }
    }
  }
}
</script>
