<template>
  <div>
    <!-- 发送放款指令/编辑/查看/复核 -->
    <dialog-edit width="95%" ref="dialogEdit" :visible.sync="dialogVisible" :form="currentForm" :formRules="formRules" :autoSave="autoSave"
      :editModel="editModel" :api="api" :appendToBody="appendToBody" :title="comTitle"
      @onSaved="handleSubmit" :saveLabel="saveLabel" :closeLabel="editModel === 'V' ? $t('common.close') : $t('common.cancel')">
      <div class="assetpkgmgr-box" v-loading="assetpkgmgrButtonLoading">
        <!-- 查询信息 -->
        <div class="viewForm">
          <dym-form :formValue.sync="forms" :componentList="componentList"></dym-form>
          <dividerTitle v-if="dialogVisible" :title="$t('sendLoanInfo.payList')"></dividerTitle>
          <!-- 可放款资产信息一览 -->
          <data-table :api="api" :operateBtnLayout="operateBtnLayout" v-bind="{maxheight:200}" selectable="false" :showPage="false"
            :showSelection="editModel === 'E'" :queryParas="queryParas" :sourceData="modifyData" :toolMenuFlag="toolMenuFlag" :columns="modifyColumns"
            :loadCount.sync="loadCount" :menuFlag="menuFlag" loadList="getInfo" :headTitle="$t('sendLoanInfo.payList')"
            :loadingFlag="loadingFlag" :selectedRows.sync="selectedRows">
            <template v-if="editModel === 'S' || editModel === 'E'" slot="headButton">
                <div align="right">
                  <btn-import btnSize="medium" :openPerms="false" fileType=".xls" :uploadApi="importApi" style="margin-left: 10px;margin-right: 10px" @importSuccess="importSuccess"></btn-import>
                  <auth-button v-if="editModel === 'E'" icon="iconfont iconshanchu" :size="'medium'" :label="$t('common.delete')" @click="deleteItem"></auth-button>
                  <auth-button type="primary" v-else icon="iconfont icondaochu" :size="'medium'" :label="$t('common.export')" @click="exportForm"></auth-button>
                </div>
            </template>
            <!-- 列表结果集 -->
            <template v-if="editModel !== 'V'" slot="paginationLeft">
              <div align="left">
                <div>{{$t('common.pagePromptOne') + modifyData.length + $t('common.pagePromptTwo') + modifyData.length + $t('common.pagePromptThree')}}</div>
              </div>
            </template>
          </data-table>
          <!-- 导出结果 -->
          <dialog-form :attr="{width:'500px'}" :visible.sync="isExport" editModel="E" :headerTitle="$t('sendLoanInfo.exportResult')" :form="form" :saveLabel="$t('sendLoanInfo.exportDownLoad')" :autoSave="false" @onSaved="saveItem" :api="api">
            <template>
              <div style="text-align:center;line-height:1">
                <div style="margin-bottom:10px">{{$t('sendLoanInfo.newResult')}}：{{exportResult.importTotal || 0}}</div>
                <div style="margin-bottom:10px">{{$t('sendLoanInfo.ignoreResult')}}：{{exportResult.ignoreNumber || 0}}</div>
                <div style="margin-bottom:10px">{{$t('sendLoanInfo.errorResult')}}：{{exportResult.failureNumber || 0}}</div>
                <div style="margin-bottom:10px">{{$t('sendLoanInfo.successResult')}}：{{exportResult.successNumber || 0}}</div>
              </div>
            </template>
          </dialog-form>
        </div>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import BaseEdit from '@/pages/baseEditPage'
import * as format from '@/filters/index.js'
import {
  DialogEdit,
  DataTable,
  authButton,
  btnExport,
  amountInput,
  btnImport,
  dymForm
} from 'newepoch-components'
import fileApi from '@/api/fileApi.js'
import {
  downFile
} from '@/utils/devUtils'
import dialogForm from '@/components/element/assetpkgmgr/dialogForm'
import sendLoanInfo from '@/api/assetpkgmgr/sendLoanInfoApi.js'
import { IMPORT_API } from '@/constant'
import dividerTitle from '@/components/element/assetpkgmgr/dividerTitle'

export default {
  extends: new BaseEdit(),
  name: 'sendLoanCmdEditPop',
  components: {
    DialogEdit,
    DataTable,
    authButton,
    dividerTitle,
    btnExport,
    amountInput,
    btnImport,
    dialogForm,
    dymForm
  },
  props: {
    autoSave: {
      type: [Boolean],
      default: false
    },
    currentRow: {
      type: [Object],
      default () {
        return {}
      }
    },
    selectedList: {
      type: [Array],
      default () {
        return []
      }
    }
  },
  data () {
    let that = this
    // 校验复核意见
    let validatePass = (rule, value, callback) => {
      if (that.reviewForm.reviewStatus === '0') {
        callback(new Error(that.$t('sendLoanInfo.reviewPinionText')))
      } else {
        callback()
      }
    }
    return {
      importApi: IMPORT_API,
      isExport: false, // 导出结果弹窗控件
      selectedRows: [], // 选中项
      chooseIndex: '', // 选中项索引值
      appendToBody: true,
      toolMenuFlag: true,
      isSet: false,
      loadCount: 0,
      exportResult: '', // 导出结果
      submitForms: {},
      menuFlag: false,
      chooseRow: {},
      operateBtnLayout: '',
      loadingFlag: false, // 加载动画控件
      queryParas: {},
      modifyData: [], // 资产信息列表
      packageBankApplyExamine: {}, // 发送放款审核信息
      packageBankApplyReview: {}, // 发送放款复核信息
      forms: {},
      // 复核表单
      reviewForm: {
        reviewStatus: 0,
        reviewPinion: ''
      },
      reviewRule: {
        reviewStatus: [{
          required: true,
          message: this.$t('sendLoanInfo.reviewStatusText'),
          trigger: 'blur'
        }],
        reviewPinion: [{
          validator: validatePass,
          trigger: 'blur'
        }]
      },
      // 基本信息表单验证
      formRules: {
        // productName: [{
        //   required: true,
        //   message: '请选择产品名称',
        //   trigger: 'blur'
        // }]
      },
      submitRules: {
        loanBankName: [{
          required: true,
          message: '请选择划款银行',
          trigger: 'blur'
        }],
        loanDate: [{
          required: true,
          message: '请选择划款日期',
          trigger: 'blur'
        }]
      },
      // 发送放款复审信息组件
      packageBankApplyReviewForm: [
        {
          // 复核结果
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.reviewStatus,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'loanApplyStatus',
          disabled: true,
          componentName: 'el-input',
          labelWidth: '100px',
          clearable: true,
          cols: [12, 12, 8]
        },
        {
          // 复核人
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.reviewUser,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'reviewUser',
          disabled: true,
          componentName: 'el-input',
          labelWidth: '100px',
          clearable: true,
          cols: [12, 12, 8]
        },
        {
          // 复核时间
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.reviewTime,
          value: 'reviewTime',
          disabled: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '100px',
          cols: [12, 12, 8],
          clearable: true,
          componentName: 'el-input'
        },
        {
          // 复核意见
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.reviewPinion,
          value: 'reviewPinion',
          disabled: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '100px',
          cols: [12, 12, 8],
          clearable: true,
          componentName: 'el-input'
        }
      ],
      // 发送放款审核信息组件
      packageBankApplyExamineForm: [
        {
          // 审核结果
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.viewStatus,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'loanApplyStatus',
          disabled: true,
          componentName: 'el-input',
          labelWidth: '100px',
          clearable: true,
          cols: [12, 12, 8]
        },
        {
          // 审核人
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.financeReviewUser,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'financeReviewUser',
          disabled: true,
          componentName: 'el-input',
          labelWidth: '100px',
          clearable: true,
          cols: [12, 12, 8]
        },
        {
          // 审核时间
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.financeReviewTime,
          value: 'financeReviewTime',
          disabled: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '100px',
          cols: [12, 12, 8],
          clearable: true,
          componentName: 'el-input'
        },
        {
          // 审核意见
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.financeReviewPinion,
          value: 'financeReviewPinion',
          disabled: true,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '100px',
          cols: [12, 12, 8],
          clearable: true,
          componentName: 'el-input'
        }
      ],
      // 基础信息组件
      componentList: [
        {
          // 产品名称
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.projectName,
          value: 'projectName',
          disabled: true,
          prop: 'projectName',
          // placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '125px',
          cols: [12, 12, 12, 8],
          clearable: true,
          componentName: 'el-input'
        },
        {
          // 期数
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.periodsNum,
          value: 'periods',
          disabled: true,
          prop: 'periods',
          // placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '125px',
          cols: [12, 12, 12, 8],
          clearable: true,
          componentName: amountInput
        },
        {
          // 划款银行
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.loanBankName,
          value: 'loanBankName',
          disabled: true,
          prop: 'loanBankName',
          // placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          labelWidth: '125px',
          cols: [12, 12, 12, 8],
          clearable: true,
          componentName: 'el-input'
        },
        {
          // 划款日期
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.loanDate,
          // placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'loanDate',
          prop: 'loanDate',
          disabled: true,
          componentName: 'el-date-picker',
          labelWidth: '125px',
          pickerOptions: {
            disabledDate: function (time) {
              return time.getTime() < new Date().getTime() - 60 * 60 * 24 * 1000
            }
          },
          clearable: true,
          cols: [12, 12, 12, 8]
        },
        {
          // 放款笔数
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.loanAssetCount,
          // placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'loanAssetCount',
          prop: 'loanAssetCount',
          disabled: true,
          componentName: 'el-input',
          labelWidth: '125px',
          clearable: true,
          cols: [12, 12, 12, 8]
        },
        {
          // 放款金额合计(元)
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.loanAmountTotal,
          // placeholder: this.$i18n.messages[this.$i18n.locale].common.noForm,
          value: 'loanTotal',
          disabled: true,
          prop: 'loanTotal',
          componentName: 'el-input',
          labelWidth: '125px',
          clearable: true,
          type: 'daterange',
          cols: [12, 12, 12, 8]
        }
      ],
      modifyColumns: [
        // 付款确认书编号
        {
          prop: 'assetCode',
          align: 'center',
          sortable: true,
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.payCode,
          width: '250px'
        },
        // 供应商名称
        {
          prop: 'recipientName',
          headerAlign: 'center',
          showOverflowTooltip: true,
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.suppliersName,
          width: '230px'
        },
        // 收款人名称
        {
          prop: 'recipientAccountName',
          headerAlign: 'center',
          align: 'left',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.recipientAccountName,
          width: '150px'
        },
        // 收款人开户行
        {
          prop: 'recipientBankName',
          headerAlign: 'center',
          align: 'left',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.recipientBankName,
          width: '150px'
        },
        // 收款人银行账号
        {
          prop: 'recipientAccount',
          align: 'center',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.recipientAccount,
          width: '200px'
        },
        // 应收账款金额（元）
        {
          prop: 'factoringMoneyTotal',
          headerAlign: 'center',
          showOverflowTooltip: true,
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.totalPrice,
          width: '150px',
          format: (row) => {
            return format.thousandFilter(row.factoringMoneyTotal)
          }
        },
        // 放款金额
        {
          prop: 'loanTotal',
          headerAlign: 'center',
          align: 'right',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.loanTotal,
          width: '150px',
          format: (row) => {
            return format.thousandFilter(row.loanTotal)
          }
        },
        // 附言
        {
          prop: 'postscript',
          headerAlign: 'center',
          align: 'left',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.postscript,
          width: '250px'
        },
        // 划款类型
        {
          prop: 'loanType',
          headerAlign: 'center',
          align: 'left',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.loanType,
          width: '150px'
        },
        // 大额行号
        {
          prop: 'anapsCode',
          align: 'center',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.anapsCode,
          width: '150px'
        },
        // 银行放款状态
        {
          prop: 'loanApplyStatus',
          headerAlign: 'center',
          showOverflowTooltip: true,
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].sendLoanInfo.bankLoanApplyStatus,
          width: '150px'
        }
      ]
    }
  },
  computed: {
    // api
    api () {
      return sendLoanInfo.sendLoanInfo
    },
    // 设置提交表单
    currentForm () {
      let $this = this
      let keyId = $this.currentRow.keyId
      let modifyData = $this.modifyData
      let form = {}
      let forms = $this.form
      let loanTotal = modifyData.length > 0 ? modifyData
        .map(item => {
          // console.log(item.loanTotal)
          return Number(item.loanTotal).toFixed(2)
        })
        .reduce((total, item) => {
          // console.log(total, item)
          return Number(total) + Number(item)
        }) : '0'
      switch ($this.editModel) {
        case 'S': // 发送放款指令
          form = {
            loanAssetCount: modifyData.length.toString(),
            loanBankName: forms.loanBankName ? forms.loanBankName : '',
            loanBankId: forms.loanBankId ? forms.loanBankId : '',
            loanDate: forms.loanDate ? forms.loanDate.getTime().toString() : '',
            loanTotal: loanTotal || '0',
            projectId: forms.projectId ? forms.projectId : '',
            projectName: forms.projectName ? forms.projectName : '',
            periods: forms.periods ? forms.periods : '',
            list: modifyData
          }
          break
        case 'E': // 编辑
          form = {
            list: modifyData,
            loanTotal: loanTotal,
            loanDate: !$this.UtilJs.isEmpty($this.forms.loanDate) ? new Date($this.forms.loanDate).getTime().toString() : '',
            keyId: keyId
          }
          break
        case 'C': // 复核
          form = $this.reviewForm
          form.keyId = keyId
          break
        default:
          break
      }
      return form
    },
    // 设置标题文本
    comTitle () {
      let $this = this
      let title = ''
      switch ($this.editModel) {
        case 'S': // 发送放款指令
          title = $this.$t('sendLoanInfo.setBtn')
          break
        case 'E': // 编辑
          title = $this.$t('common.edit')
          break
        case 'C': // 复核
          title = $this.$t('common.reCheck')
          break
        case 'V': // 查看
          title = $this.$t('common.view')
          break
        default:
          break
      }
      return title
    },
    // 设置按钮文本
    saveLabel () {
      let $this = this
      let title = ''
      switch ($this.editModel) {
        case 'S': // 发送放款指令
          title = $this.$t('common.save')
          break
        case 'E': // 编辑
          title = $this.$t('common.submit')
          break
        case 'C': // 复核
          title = $this.$t('common.assign')
          break
        case 'V': // 查看
          title = ''
          break
        default:
          break
      }
      return title
    },
    // 计算总数
    calcTotal () {
      let list = this.modifyData
      return format.thousandFilter(list.length > 0 ? list
        .map(item => {
          // console.log(item.loanTotal)
          return Number(item.loanTotal).toFixed(2)
        })
        .reduce((total, item) => {
          // console.log(total, item)
          return Number(total) + Number(item)
        }) : '0.00') || '0.00'
    }
  },
  methods: {
    // 下载
    saveItem (e) {
      let $this = this
      $this.assetpkgmgrFullScreenLoading()
      fileApi.file.download({
        keyId: $this.exportResult.fileId
      }).then(ress => {
        $this.assetpkgmgrFullScreenLoading().close()
        downFile(ress)
      }).catch(res => {
        $this.assetpkgmgrFullScreenLoading().close()
      })
    },
    // 导入
    importSuccess (returnData) {
      let data = []
      let $this = this
      returnData.forEach((item, index) => {
        let flag = true
        item.forEach(it1 => {
          if (!$this.UtilJs.isEmpty(it1)) {
            flag = false
          }
        })
        if (!flag) {
          item.index = index
          data.push(item)
        }
      })
      if (data instanceof Array && data.length > 1) {
        let params = {
          projectId: this.editModel === 'E' ? this.forms.projectId : this.form.projectId,
          bankId: this.editModel === 'E' ? this.forms.bankId : this.form.loanBankId,
          periods: this.editModel === 'E' ? this.forms.periods : this.form.periods,
          loanDate: this.editModel === 'E' ? new Date(this.forms.loanDate).getTime().toString() : this.form.loanDate.getTime().toString(),
          bankTransactionsManageAssetDTO: $this.modifyData,
          importData: data
        }
        $this.assetpkgmgrFullScreenLoading()
        $this.api.importList(params).then(res => {
          if (res.success && res.data) {
            this.isExport = true
            let list = res.data.bankTransactionsManageAssetDTO
            this.exportResult = res.data
            if (res.data.successNumber > 0 && res.data.failureNumber === '0') {
              $this.modifyData = list
              $this.forms.loanAssetCount = list.length.toString()
              $this.forms.loanTotal = $this.calcTotal
              setTimeout(() => {
                $this.success($this.$t('sendLoanInfo.importSuccess'))
              }, 200)
            } else {
              setTimeout(() => {
                $this.error($this.$t('sendLoanInfo.importFaile'))
              }, 200)
            }
          } else {
            $this.error($this.$t('sendLoanInfo.importFaile'))
          }
          $this.assetpkgmgrFullScreenLoading().close()
        }).catch(res => {
          $this.assetpkgmgrFullScreenLoading().close()
        })
      } else {
        $this.warning($this.$t('common.noloadData'))
      }
    },
    // 导出
    exportForm () {
      let $this = this
      let modifyData = $this.modifyData
      if (modifyData.length > 0) {
        let params = {
          bankTransactionsManageAssetList: modifyData,
          bankId: $this.form.loanBankName
        }
        $this.assetpkgmgrFullScreenLoading()
        $this.api.exportList(params).then(res => {
          if (res.success && res.data) {
            fileApi.file.download({
              keyId: res.data
            }).then(ress => {
              $this.assetpkgmgrFullScreenLoading().close()
              downFile(ress)
            }).catch(res => {
              $this.assetpkgmgrFullScreenLoading().close()
            })
            $this.success($this.$t('common.export') + $this.$t('common.successfully'))
          } else {
            $this.error(res.message)
          }
        }).catch(res => {
          $this.assetpkgmgrFullScreenLoading().close()
        })
      } else {
        $this.warning($this.$t('common.nodownData'))
      }
    },
    // 去重
    array_diff (a, b) {
      for (var i = 0; i < b.length; i++) {
        for (var j = 0; j < a.length; j++) {
          if (a[j] === b[i]) {
            a.splice(j, 1)
            j = j - 1
          }
        }
      }
      return a
    },
    // 删除
    deleteItem () {
      let that = this
      let selectedRows = that.selectedRows
      if (selectedRows.length > 0) {
        that.$confirm(that.$t('common.confirmTip'), that.$t('common.tip'), {
          type: 'warning'
        }).then(() => {
          that.modifyData = that.array_diff(that.modifyData, that.selectedRows)
          that.forms.loanTotal = that.calcTotal
        }).catch((e) => {})
      } else {
        that.warning(that.$t('common.delSelectedTip'))
      }
    },
    // 提交表单
    handleSubmit (e) {
      let that = this
      // 检测放款金额（供应商）loanAmountFactoring是否存在，存在则自有资金已放款，则划款账号（recipientAccount）等于原收款人银行账号（formerRecipientAccount），则提示不能放款
      let checkList = [] // 划款账号异常列表
      let checkPropmpty = [] // 提示语
      const h = this.$createElement
      for (let index in this.modifyData) {
        let item = this.modifyData[index]
        // 若放款金额存在
        if (item.loanAmountFactoring > 0) {
          // 划款账号（recipientAccount）等于原收款人银行账号（formerRecipientAccount）
          if (item.formerRecipientAccount === item.recipientAccount) {
            // 添加到划款账号异常列表
            checkList.push(item.assetCode)
          }
        }
      }
      // 若划款账号异常列表不为空，则提示异常划款账号的资产不能放款
      if (checkList.length > 0) {
        checkPropmpty.push(h('span', { style: 'word-break: break-all' }, `资产[${checkList.join('，')}]`))
        checkPropmpty.push(h('span', { style: 'color: red' }, '已使用自有资金放款，请修改收款人账号信息！'))
        this.$msgbox({
          title: this.$t('common.tip'),
          message: h('p', null, checkPropmpty),
          callback: action => {}
        })
        return
      }
      if (that.editModel === 'C') { // 复核
        if (that.modifyData.length > 0) {
          that.$refs['reviewForm'].validate((valid) => {
            if (valid) {
              that.$emit('onSaved', e)
            }
          })
        } else {
          that.warning(that.$t('sendLoanInfo.nodata'))
        }
      } else if (that.editModel === 'S') { // 发送放款指令
        if (that.modifyData.length > 0) {
          // console.log(that.editModel)
          that.$emit('onSaved', e)
        } else {
          that.warning(that.$t('sendLoanInfo.nodata'))
        }
      } else if (that.editModel === 'E') { // 编辑
        // 若放款信息不为空则保存放款信息
        if (this.modifyData.length > 0) {
          that.$emit('onSaved', e)
        } else {
        // 若放款信息为空则删除放款信息
          that.$confirm(that.$t('sendLoanInfo.delSuccessful'), that.$t('common.tip'), {
            type: 'warning'
          }).then(() => {
            // 调用删除接口
            that.assetpkgmgrFullScreenLoading()
            that.api.deleteItem({
              keyId: that.currentRow.keyId
            }).then(function (res) {
              that.assetpkgmgrFullScreenLoading().close()
              if (res.success) {
                that.success(that.$t('common.delSuccess'))
                // 关闭弹窗
                that.dialogVisible = false
                // 重置表格
                that.$parent.$refs.dataTable.loadTableData()
              }
            }).catch(res => {
              that.assetpkgmgrFullScreenLoading().close()
            })
          }).catch((e) => {})
        }
      }
    }

  },
  watch: {
    visible (val) {
      if (val) {
        let $this = this
        $this.loadingFlag = true
        let params = $this.queryParas
        $this.forms = {}
        $this.modifyData = []
        if ($this.editModel !== 'S') {
          let currentRow = $this.currentRow
          if ($this.editModel === 'V') {
            params.isPage = '0'
          } else {
            params.isPage = '1'
          }
          if (currentRow) {
            params.keyId = currentRow.keyId
          }
          if ($this.editModel === 'C') {
          // 重置复核表单
            $this.reviewForm = {
              reviewStatus: '1',
              reviewPinion: ''
            }
          }
          // 获取审核详情
          $this.assetpkgmgrButtonLoading = true
          $this.api.getSendLoanInfo(params).then(res => {
            if (res.success) {
              let datas = res.data
              $this.componentList[3].disabled = !($this.editModel === 'E')
              datas.periods = datas.periods === '0' ? '' : datas.periods
              // 表单赋值
              $this.forms = datas
              $this.modifyData = datas.list
              $this.loadingFlag = false
            }
            $this.assetpkgmgrButtonLoading = false
          }).catch(res => {
            $this.assetpkgmgrButtonLoading = false
            $this.loadingFlag = false
          })
        } else {
          // 表单赋值
          let form = $this.form
          let list = $this.UtilJs.cloneDeep($this.selectedList)
          $this.modifyData = list
          $this.forms = {
            projectName: form.projectName,
            loanBankName: form.loanBankName,
            periods: form.periods,
            loanDate: format.parseTime(form.loanDate.getTime(), '{y}-{m}-{d}'),
            loanAssetCount: list.length.toString(),
            loanTotal: $this.calcTotal
          }
          $this.loadingFlag = false
        }
      }
    },
    modifyData (val) {
      // console.log(val)
      this.forms.loanAssetCount = val.length
      this.forms.loanTotal = this.calcTotal
    }
  }
}
</script>

<style scoped>
  @import "~@/styles/assetpkgmgr/common.scss";
</style>
