<template>
  <dialog-edit :visible.sync="dialogVisible"
               :title="$t('traceMgr.descriptionOfGeneration')"
               :footerBtnShow="isFootView"
               :editModel="'V'"
               v-loading.fullscreen.lock="fullscreenLoading"
               :form="form"
               :api="api"
               autoClose
               :before-close="close"
               @close="close"
               :appendToBody="true">
    <component :is="currentComponentName" :ref="currentComponentName" :readonly="!needComplete"></component>
    <el-row>
      <div>
        <payment-info :keyId="assetInfoId" :title="$t('traceMgr.basicInformationOfOrder')"></payment-info>
      </div>
    </el-row>

    <el-row class="textRight marginBottom">
        <auth-button type="primary" size="medium" :label="$t('traceMgr.downloadingData')" @click="showBusinessFileDownloadDialog" class="iconfont iconycxiazai"></auth-button>
    </el-row>

    <el-row>
      <el-tabs>
        <el-tab-pane :label="$t('traceMgr.factSheet')">
        </el-tab-pane>
      </el-tabs>
    </el-row>
    <el-form  :show-message="false" >

      <el-col :span="24" class="bt_left">
        <el-col :span="6">
          <div class="text_left">
            <span>{{$t('common.reviewers')}}:&nbsp;&nbsp;{{examineUserName}}</span>
          </div>
        </el-col>
        <el-col :span="9">
          <div class="text_left">
            <span>{{$t('economyLendingInfoList.auditDate')}}:&nbsp;&nbsp;{{examineDate | parseTime}}</span>
          </div>
        </el-col>
        <el-col :span="9">
          <div class="text_left">
            <span>{{$t('traceMgr.submissionTime')}}:&nbsp;&nbsp;{{submitDate | parseTime}}</span>
          </div>
        </el-col>
      </el-col>

      <el-row></el-row>
      <data-table :cellStyle="cellStyle"  :stripe="true" :loadList="loadList" :spanMethod="mergedCell"
                  :api="api" :handleFlag.sync="handleFlag" :border="true" :showPage="false" :menuFlag="false"
                  :queryParas="queryParas" @getTableData="tableData" :sourceData.sync="sourceData"
                  :loadCount.sync="loadCount" :columns="columns" :operateBtnLayout="operateBtnLayout">

        <el-table-column :label="$t('common.operate')" align="center" fixed="right" :width="200">
          <template slot-scope="scope">

            <!--上传-->
            <btn-upload style="margin-left: 10px" v-if="scope.row.isUpload === 0 || scope.row.isUpload === undefined"
                        :classType="true" :uploadApi="uploadApi" :rowData="scope.row" :fileType="'.pdf'"
                        @uploadSuccess="uploadSuccess"></btn-upload>

            <!-- 重新上传== -->
            <btn-upload style="margin-left: 10px" v-if="scope.row.isUpload === 1"
                        :store="$store" btnSize="small"  :btnDisplay="true"  :classType="true"  perms="import_refunds"
                        :title="$t('common.reUpload')" :fileType="'.pdf'" :uploadApi="uploadApi" :rowData="scope.row" @uploadSuccess="uploadSuccess" :icon="'iconfont iconzhongxinshangchuan'">
            </btn-upload>

            <!--重新生成==1  -->
            <el-button v-if="scope.row.isGenerate === 1" circle size="medium" :icon="'iconfont iconreload'" style="color: #1E90E9" :loading="scope.row.status"
                       :title="$t('factoringBusinessInfoManagerList.reMake')" @click="generateSave(scope.row)"></el-button>

            <!--生成资料==0  -->
            <el-button v-if="scope.row.isGenerate === 0 || scope.row.isGenerate === undefined" :loading="scope.row.status"
                       circle size="medium" :icon="'iconfont iconziliao2'" style="color: #1E90E9" @click="generateSave(scope.row)"
                       :title="$t('common.generateMaterial')"></el-button>

            <btn-download v-if="(scope.row.isUpload !== 0 || scope.row.isGenerate !== 0) && (scope.row.isUpload !== undefined || scope.row.isGenerate !== undefined)"
                          :fileID="scope.row.fileId"></btn-download><!--下载-->

          </template>
        </el-table-column>

        <!--备注-->
        <template slot="memo" slot-scope="scope">
          <el-input type="textarea" :rows="2" maxlength="500" v-model="scope.data.row.comment" :placeholder="$t('common.MultilineInput')"></el-input>
        </template>

        <!--是否后补-->
        <template slot="isLater" slot-scope="scope">
          <select-dictionary dictTypeCode="yes_or_no_dangan" v-model="scope.data.row.isLater"></select-dictionary>
        </template>

        <!--情况说明-->
        <template slot="supplementFileName" slot-scope="scope">
          <span @click="showDialog(scope.data.row)" style="cursor: pointer">{{scope.data.row.supplementFileName}}</span>
        </template>

      </data-table>

      <el-row>
          <el-row class="title" v-if="employees.length > 0">
            <el-col :span="2"><span>{{$t('common.contact')}}：</span></el-col><br/>
          </el-row>
        <el-row class="marginBottom2 title paddingLeft20">
          <el-col  :span="10" v-for="(employee,index) in employees" :key="index">
            <el-col :span="3"><span>&nbsp;</span></el-col>
            <span v-if="employee.employeeName">{{employee.employeeName}}</span>
            <span v-if="employee.telephone">-{{employee.telephone}}</span>
            <span v-if="employee.account">-{{employee.account}}</span>
          </el-col>
        </el-row>
        <!--话术组件-->
        <el-row class="body_msg">
          <el-col :span="0.5" class="text-center">
            <span>{{$t('common.discourse')}}&nbsp;:&nbsp;</span>
          </el-col>
          <el-col :span="14">
            <speech-craft-input :autosize="autosize" v-loading="speechCraftLoading" v-model="discourse"  :defaultSpeechFlag="false" @defaultSpeech="setDefaultSpeech"></speech-craft-input>
          </el-col>
        </el-row>
      </el-row>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="medium" type="primary" :disabled="submitLoading" @click="saveBtn" :loading="vLoading">{{$t('common.saveBtn')}}</el-button>
      <el-button size="medium" type="primary" :disabled="vLoading" @click="complete" :loading="submitLoading">{{$t('common.complete')}}</el-button>
      <el-button size="medium" @click="close">{{$t('common.close')}}</el-button>
    </div>

    <business-file-download-dialog  :visible.sync = "showBusinessFileDownloadDialogValue" :form="downloadForm"></business-file-download-dialog>
    <situationDescriptionDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable" :visible.sync="situationDescriptionDialogShow" :needComplete="true"  :item="item" ></situationDescriptionDialog>
    <accountProof :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable" :visible.sync="accountProofShow" :needComplete="true"  :item="item"  ></accountProof>
    <confirmLetter :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable" :visible.sync="confirmLetterShow" :needComplete="true"  :item="item"  ></confirmLetter>
    <empowerDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable"  :visible.sync="empowerDialogShow" :needComplete="true"  :item="item" ></empowerDialog>
    <entrustReceivablesDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable"  :visible.sync="entrustReceivablesDialogShow" :needComplete="true"  :item="item"  ></entrustReceivablesDialog>
    <preposedProblemDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable"  :visible.sync="preposedProblemDialogShow" :needComplete="true"  :item="item"  ></preposedProblemDialog>
    <electronicChapterDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable"  :visible.sync="electronicChapterDialogShow" :needComplete="true"  :item="item"  ></electronicChapterDialog>
    <changeClauseDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable"  :visible.sync="changeClauseDialogShow" :needComplete="true"  :item="item"  ></changeClauseDialog>
    <authorizedSupervisionAndAcceptanceDialog :submitParams="submitParams"  :getFormDataForchange="getFormDataForchange" :resetHomePageDataTable="resetHomePageDataTable"  :visible.sync="authorizedSupervisionAndAcceptanceDialogShow" :needComplete="true"  :item="item" ></authorizedSupervisionAndAcceptanceDialog>
  </dialog-edit>
</template>
<script>
import { DataTable, btnDownload, DialogEdit, paymentInfo, speechCraftInput, SelectDictionary, btnUpload, authButton } from 'newepoch-components'
import situationDescriptionDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/situationDescriptionDialog.vue'
import accountProof from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/accountProof'
import confirmLetter from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/confirmLetter'
import empowerDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/empowerDialog'
import entrustReceivablesDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/entrustReceivablesDialog'
import preposedProblemDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/preposedProblemDialog.vue'
import electronicChapterDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/electronicChapterDialog'
import changeClauseDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/changeClauseDialog'
import authorizedSupervisionAndAcceptanceDialog from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/authorizedSupervisionAndAcceptanceDialog.vue'
import businessFileDownloadDialog from '@/components/tracemgr/common/businessFileDownloadDialog'
import { UPLOAD_API } from '@/constant.js'
import tracemgrApi from '@/api/tracemgrApi'
import BasePage from '@/pages/basePage'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin'
export default {
  extends: new BasePage(),
  name: 'taskDialog',
  mixins: [mixin],
  components: {
    situationDescriptionDialog,
    accountProof,
    confirmLetter,
    empowerDialog,
    entrustReceivablesDialog,
    preposedProblemDialog,
    electronicChapterDialog,
    changeClauseDialog,
    authorizedSupervisionAndAcceptanceDialog,
    format,
    speechCraftInput,
    tracemgrApi,
    DataTable,
    btnUpload,
    btnDownload,
    DialogEdit,
    SelectDictionary,
    businessFileDownloadDialog,
    authButton,
    paymentInfo
  },
  props: {
    handler: {
      type: Function
    },
    processParas: {
      type: Object
    },
    visible: {
      type: Boolean
    },
    url: {
      type: String
    },
    factType: {
      type: String
    },
    supplierId: {
      type: String
    },
    needComplete: {
      type: Boolean
    },
    form: {}
  },
  mounted () {
  },
  data () {
    return {
      speechCraftLoading: false,
      vLoading: false,
      genera: false,
      submitLoading: false,
      situationDescriptionDialogShow: false,
      accountProofShow: false,
      confirmLetterShow: false,
      fullscreenLoading: false,
      empowerDialogShow: false,
      getFormDataForchange: false,
      entrustReceivablesDialogShow: false,
      preposedProblemDialogShow: false,
      electronicChapterDialogShow: false,
      changeClauseDialogShow: false,
      authorizedSupervisionAndAcceptanceDialogShow: false,
      changeDate: false,
      dialogData: false,
      spanArr: [],
      sameRowArr: [],
      submitParams: {
        descriptionContent: '',
        taskId: '',
        assetId: '',
        descriptionCode: ''
      },
      sort: '',
      loadList: 'getList',
      handleFlag: true,
      uploadApi: UPLOAD_API,
      discourse: '',
      isLater: '0',
      coreArea: '',
      autosize: {
        minRows: 7,
        maxRows: 9
      },
      isFootView: false,
      showBusinessFileDownloadDialogValue: false,
      downloadApi: '',
      examineUserName: '',
      examineDate: '',
      projectCompanyName: '',
      submitDate: '',
      assetInfoId: '',
      assetCodeBl: '',
      itemCompanyName: '',
      itemBaseContractNo: '',
      itemBaseContractName: '',
      supplierNameOne: '',
      bussContractCode: '',
      bussContractName: '',
      reasons: '',
      reasonsNote: '',
      factoringContract: '',
      projectCompanyNameMy: '',
      content: '',
      newTermOfValidity: '',
      oldTermOfValidity: '',
      stampingTime: '',
      pdcPlatform: '',
      pdcNumber: '',
      scheme: '',
      validity: '',
      forceClauseName: '',
      authorizedName: '',
      invoice: '',
      invoiceNo: '',
      basicContractName: '',
      StampWay: '',
      uploadMess: false,
      fileCode: '',
      authorizedCompany: '',
      supplierName: '',
      contractName: '',
      assetCode: '',
      factor: '',
      initialOwnersName: '',
      planOrBankName: '',
      planOrBankId: '',
      receivablesCompanyName: '',
      issuerName: '',
      nameOfTheOtherParty: '',
      basicContract: '',
      submintDate: '',
      item: {
        name: '',
        data: {
        }
      },
      fileIdSaveMess: false,
      taskId: '',
      employees: [],
      downloadForm: {
        assetCode: '',
        assetInfoId: ''
      },
      dialogApi: {},
      queryParas: {
        isLater: ['0'], // 是否后补（保理默认否）
        pageIndex: 1,
        pageSize: 10
      },
      loadCount: 0,
      operateBtnLayout: '',
      sourceData: [],
      returnDate: [],
      columns: [
        /* 文件名称 */
        {
          prop: 'fileName',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].expressDataList.fileName,
          showOverflowTooltip: true,
          width: '20px',
          spanStyle: function (row) {
            return 'color:' + row['prioritycolor']
          }
        },
        /* 审核意见 */
        {
          prop: 'auditContent',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].expressFileReceiveList.auditMind,
          showOverflowTooltip: true,
          width: '30px',
          spanStyle: function (row) {
            return 'color:' + row['prioritycolor']
          }
        },
        /* 情况说明文件 */
        {
          prop: 'supplementFileName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factSheetOpinion,
          showOverflowTooltip: true,
          width: '30px',
          spanStyle: function (row) {
            return 'color:' + row['prioritycolor']
          },
          slot: true
        },
        /* 备注 */
        {
          prop: 'memo',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].uninvoiced.Remarks,
          showOverflowTooltip: true,
          width: '30px',
          slot: true,
          spanStyle: function (row) {
            return 'color:' + row['prioritycolor']
          }
        },
        /* 是否后补 */
        {
          prop: 'isLater',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.ifAfterRepair,
          showOverflowTooltip: true,
          width: '30px',
          slot: true
        }
      ],
      currentProcessParas: {},
      currentComponentName: null
    }
  },
  computed: {
    dialogVisible: {
      get: function () {
        this.getComp()
        return this.visible
      },
      set: function (val) {
        this.$emit('update:visible', val)
      }
    },
    getTitle: {
      get: function () {
        return this.title
      },
      set: function (val) {
        this.$emit('update:title', val)
      }
    },
    api () {
      return tracemgrApi['descriptionOfGenerationDialog']
    }
  },
  watch: {
    visible: {
      handler: function (newValue) {
        let $this = this
        if (newValue) {
          $this.item = {}
          $this.queryParas['assetInfoId'] = this.form.assetInfoId
          $this.queryParas['taskId'] = this.form.taskId
          $this.queryParas['supplierId'] = this.form.creditorId
          $this.queryParas['platformRole'] = (this.factType === '2' ? '1' : '2')
          $this.sourceData = []
          $this.$nextTick(() => {
            $this.handleFilter()
            $this.getAssetInfoByKeyId()
          })
        }
      },
      'sourceData': {
        deep: true,
        handler: function () {
          this.spanArr = []
          this.sameRowArr = []
        }
      }
    },
    uploadMess: {
      handler: function (val) {
        this.sourceData.forEach((item, key) => {
          if (this.sort === item.sort) {
            this.$set(this.sourceData[key], 'isUpload', 1)
            this.$set(this.sourceData[key], 'isGenerate', 0)
          }
        })
      }
    },
    'sourceData': {
      deep: true,
      handler: function () {
        this.spanArr = []
        this.sameRowArr = []
      }
    }
  },
  methods: {
    tableData (data) {
      this.assetInfoId = this.form.assetInfoId
      this.assetCode = this.form.assetCode

      if (data !== undefined && data !== null) {
        this.examineUserName = data.examineUserName
        this.examineDate = data.examineDate
        this.submitDate = data.submitDate
        this.operType = data.operType
        this.sourceData = data.detailList
        for (let i = 0; i < data.detailList.length; i++) {
          if (data.detailList[i].isLater === '') {
            this.sourceData[i].isLater = '0'
          }
        }
      }
      this.spanArr = []
      this.sameRowArr = []
    },
    getComp: function () {
      if (!this.visible) {
        // return
      }
    },
    setDefaultSpeech () {
      if (this.stampWay === '1') {
        this.discourse = this.discourse = this.$i18n.messages[this.$i18n.locale].traceMgr.contentHolle + this.$i18n.messages[this.$i18n.locale].traceMgr.contentOne +
          this.form.assetCode + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListTwo + this.bussContractName + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListThere + this.factorAmount +
          this.$i18n.messages[this.$i18n.locale].traceMgr.end +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMass +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassone + this.supplementFileNameList + '\n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMasstwo + this.auditContentList +
          ' \n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassthree +
          this.$i18n.messages[this.$i18n.locale].traceMgr.four + (this.factoringCommissioner === undefined ? '' : this.factoringCommissioner) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.five + (this.officePhone === undefined ? '' : this.officePhone) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.six + (this.factoringPhoneNumber === undefined ? '' : this.factoringPhoneNumber)
      } else if (this.stampWay === '2') {
        this.discourse = this.discourse = this.$i18n.messages[this.$i18n.locale].traceMgr.contentHolle + this.$i18n.messages[this.$i18n.locale].traceMgr.contentOne +
          this.form.assetCode + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListTwo + this.bussContractName + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListThere + this.factorAmount +
          this.$i18n.messages[this.$i18n.locale].traceMgr.end +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMass +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassone + this.supplementFileNameList + '\n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMasstwo + this.auditContentList +
          ' \n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassfour +
          this.$i18n.messages[this.$i18n.locale].traceMgr.four + (this.factoringCommissioner === undefined ? '' : this.factoringCommissioner) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.five + (this.officePhone === undefined ? '' : this.officePhone) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.six + (this.factoringPhoneNumber === undefined ? '' : this.factoringPhoneNumber)
      }
    },
    getAssetInfoByKeyId () {
      this.speechCraftLoading = true

      tracemgrApi['onlineAuditTaskDialog'].getOrderInfo(this.form.assetInfoId).then(res => {
        // 保理金额
        this.factorAmount = res.data.assetPaymentInfoDTO.factoringMoney
        // 保理专员
        this.customerAccountName = res.data.assetPaymentPoolOperDTO.customerAccountName
        // 合同名称
        this.bussContractName = res.data.assetPaymentInfoDTO.bussContractName

        // 区域编号
        this.coreArea = res.data.assetPaymentPoolOperDTO.coreArea

        // 获取联系人信息
        tracemgrApi['onlineAuditTaskDialog'].getEmployeeInfos({ 'assetCode': this.form.assetCode }).then(res => {
          this.employees = res.data
        })

        this.supplementFileNameList = []
        this.auditContentList = []
        for (let i = 0; i < this.sourceData.length; i++) {
          this.supplementFileNameList = this.supplementFileNameList + (i + 1) + '.' + this.sourceData[i].supplementFileName + ';\n'
          this.auditContentList = this.auditContentList + (i + 1) + '.' + this.sourceData[i].auditContent + ';\n'
        }
        this.getSpeechCraftInfo()
        this.speechCraftLoading = false
      }).catch(res => {
        this.discourse = this.$i18n.messages[this.$i18n.locale].traceMgr.noneData
        this.speechCraftLoading = false
      })
    },
    // 获取话术信息:保理专员(区域专员)、座机、手机号
    getSpeechCraftInfo () {
      tracemgrApi['fileList'].getSpeechCraftInfo({ 'assetId': this.form.assetInfoId }).then(res => {
        // 保理专员
        this.factoringCommissioner = res.data.factoringCommissioner

        // 手机
        this.factoringPhoneNumber = res.data.factoringPhoneNumber

        // 座机
        this.officePhone = res.data.factoringTelephone

        this.getStampWay()
      })
    },
    getStampWay () {
      // 获取盖章方式
      tracemgrApi['descriptionOfGenerationDialog'].getStampWay({ 'debtorId': this.form.creditorId }).then(res => {
        this.stampWay = res.data.stampWay

        this.getContent()
      })
    },
    getContent () {
      if (this.stampWay === '1') {
        this.discourse = this.discourse = this.$i18n.messages[this.$i18n.locale].traceMgr.contentHolle + this.$i18n.messages[this.$i18n.locale].traceMgr.contentOne +
          this.form.assetCode + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListTwo + this.bussContractName + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListThere + this.factorAmount +
          this.$i18n.messages[this.$i18n.locale].traceMgr.end +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMass +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassone + this.supplementFileNameList + '\n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMasstwo + this.auditContentList +
          ' \n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassthree +
          this.$i18n.messages[this.$i18n.locale].traceMgr.four + (this.factoringCommissioner === undefined ? '' : this.factoringCommissioner) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.five + (this.officePhone === undefined ? '' : this.officePhone) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.six + (this.factoringPhoneNumber === undefined ? '' : this.factoringPhoneNumber)
      } else if (this.stampWay === '2') {
        this.discourse = this.discourse = this.$i18n.messages[this.$i18n.locale].traceMgr.contentHolle + this.$i18n.messages[this.$i18n.locale].traceMgr.contentOne +
          this.form.assetCode + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListTwo + this.bussContractName + '    ' + this.$i18n.messages[this.$i18n.locale].traceMgr.fileListThere + this.factorAmount +
          this.$i18n.messages[this.$i18n.locale].traceMgr.end +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMass +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassone + this.supplementFileNameList + '\n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMasstwo + this.auditContentList +
          ' \n' +
          this.$i18n.messages[this.$i18n.locale].traceMgr.generateMassfour +
          this.$i18n.messages[this.$i18n.locale].traceMgr.four + (this.factoringCommissioner === undefined ? '' : this.factoringCommissioner) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.five + (this.officePhone === undefined ? '' : this.officePhone) +
          this.$i18n.messages[this.$i18n.locale].traceMgr.six + (this.factoringPhoneNumber === undefined ? '' : this.factoringPhoneNumber)
      }
    },
    handleFilter: function () {
      this.loadCount = this.loadCount + 1
      this.spanArr = []
      this.sameRowArr = []
    },
    showBusinessFileDownloadDialog () {
      this.downloadForm.assetInfoId = this.form.assetInfoId
      this.downloadForm.assetCode = this.form.assetCode
      this.showBusinessFileDownloadDialogValue = true
    },
    businessFileDownloadDialogClose () {
      this.showBusinessFileDownloadDialogValue = false
    },
    uploadSuccess (returnData, rowData) {
      if (returnData.fileName !== undefined) {
        rowData.fileId = returnData.fileID
        this.sort = rowData.sort
        this.uploadMess = !this.uploadMess
        this.fileIdSaveMess = false
        rowData.isLater = '0'
        // rowData.isUpload = 1
        // rowData.isGenerate = 0
        // this.saveBtn()
        this.success(this.$i18n.messages[this.$i18n.locale].common.uploadSuccess)
      } else {
        this.$message.error(this.$i18n.messages[this.$i18n.locale].common.uploadError)
      }
    },
    generateSave: function (row) {
      row['assetInfoId'] = this.form.assetInfoId
      row['taskId'] = this.form.taskId
      row.supplierName = this.supplierName
      row.projectCompanyName = this.projectCompanyName
      row.projectCompanyName = this.projectCompanyNameMy
      row.bussContractName = this.bussContractName
      row.basicContractName = this.bussContractName
      row.supplierName = this.supplierNameOne
      row.factoringMoney = this.factoringMoney
      row.contractName = this.contractName
      row.assetCode = this.assetCode
      row.factoringContract = this.assetCodeBl
      row.factoringContract = this.factoringContract
      row.factor = this.factor
      row.initialOwnersName = this.initialOwnersName
      row.planOrBankName = this.planOrBankName
      row.planOrBankId = this.planOrBankId
      row.receivablesCompanyName = this.receivablesCompanyName
      row.issuerName = this.issuerName
      row.nameOfTheOtherParty = this.nameOfTheOtherParty
      row.basicContract = this.basicContract
      row.reasons = this.reasons
      row.submintDate = this.submintDate
      row.invoiceNo = this.invoiceNo
      row.itemCompanyName = this.itemCompanyName
      row.itemBaseContractNo = this.itemBaseContractNo
      row.itemBaseContractName = this.itemBaseContractName
      row.bussContractCode = this.bussContractCode
      row.content = this.content
      row.reasonsNote = this.reasonsNote
      row.newTermOfValidity = this.newTermOfValidity
      row.oldTermOfValidity = this.oldTermOfValidity
      row.stampingTime = this.stampingTime
      row.pdcPlatform = this.pdcPlatform
      row.pdcNumber = this.pdcNumber
      row.scheme = this.scheme
      row.validity = this.validity
      row.forceClauseName = this.forceClauseName
      row.authorizedName = this.authorizedName
      row.signDate = this.signDate
      row.status = true
      row.templateCode = ''
      tracemgrApi['descriptionOfGenerationDialog'].descriptionFile(row).then(res => {
        if (res.success === true) {
          this.$set(row, 'fileId', res.data.keyId)
          this.$set(row, 'isGenerate', res.data.isGenerate)
          this.$set(row, 'isUpload', res.data.isUpload)
          this.success(this.$i18n.messages[this.$i18n.locale].traceMgr.generateFailures)
          this.$set(row, 'status', false)
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.generateFailure)
          this.$set(row, 'status', false)
        }
      }, res => {
        this.$set(row, 'status', false)
      }).catch(() => {
        this.$set(row, 'status', false)
      })
    },
    remakeSave: function (row) {
      this.generateSave()
    },
    saveBtn: function () {
      let sub = {}
      sub['assetInfoId'] = this.form.assetInfoId
      sub['taskId'] = this.form.taskId
      sub['factExplainFiles'] = Object.assign([], this.sourceData)
      this.vLoading = true
      tracemgrApi['descriptionOfGenerationDialog'].descriptionSave(sub).then(res => {
        if (res.data === true) {
          this.success(this.$i18n.messages[this.$i18n.locale].complianceCheck.saveSucMsg)
          this.fileIdSaveMess = true
          this.handleFilter()
          this.dialogData = false
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].complianceCheck.saveFailMsg)
          return false
        }
        this.vLoading = false
        this.dialogData = false
      }, res => {
        this.vLoading = false
        this.dialogData = false
        return false
      })
      return true
    },
    complete: function () {
      // 校验数据
      let saveParam = []
      let status = false
      for (let i = 0; i < this.sourceData.length; i++) {
        if (this.sourceData[i].isLater === undefined || this.sourceData[i].isLater === '') {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.messa + this.$i18n.messages[this.$i18n.locale].traceMgr.ifAfterRepair)
          status = true
          break
        } else if (this.sourceData[i].isLater === '0' && (this.sourceData[i].fileId === '0' || this.sourceData[i].fileId === undefined || this.sourceData[i].isUpload === 0 || this.sourceData[i].isUpload === undefined) &&
          (this.sourceData[i].supplementFileCode === undefined || this.sourceData[i].supplementFileCode === '' || this.sourceData[i].isGenerate === 0 || this.sourceData[i].isGenerate === undefined)) {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.uleaseUploadOrGenerateFiles)
          status = true
          break
        } else {
           if ((this.sourceData[i].isLater === '0' || this.sourceData[i].isLater === undefined || this.sourceData[i].isLater === '') && (this.sourceData[i].fileId === '0' || this.sourceData[i].fileId === undefined || this.sourceData[i].fileId === '')) {
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.uleaseUploadOrGenerateFiles)
            return
          }
          saveParam.push(this.sourceData[i])
        }
      }
      if (status) {
        return
      }
      // 保存数据
      let sub = {}
      sub['assetInfoId'] = this.form.assetInfoId
      sub['taskId'] = this.form.taskId
      sub['factExplainFiles'] = Object.assign([], this.sourceData)
      let $this = this
      $this.submitLoading = true
      tracemgrApi['descriptionOfGenerationDialog'].descriptionSave(sub).then(res => {
        if (res.data === true) {
          let sub1 = {}
          sub1['assetInfoId'] = this.form.assetInfoId
          sub1['factType'] = this.factType
          sub1['taskStatus'] = this.form.taskStatus
          sub1['taskId'] = this.form.taskId
          sub1['operType'] = this.operType
          sub1['factExplainFiles'] = Object.assign([], saveParam)
          tracemgrApi['descriptionOfGenerationDialog'].descriptionSubmit(sub1).then(res => {
            if (res.data === true) {
              $this.success(this.$i18n.messages[this.$i18n.locale].complianceCheck.submitSucMsg)
              // 关闭弹窗
              $this.dialogVisible = false
              // 刷新列表数据
              $this.$emit('updateData')
              $this.handler()
              $this.submitLoading = false
            } else {
              $this.submitLoading = false
              $this.error(this.$i18n.messages[this.$i18n.locale].complianceCheck.submitFailMsg)
            }
          }, res => {
            $this.submitLoading = false
          })
        } else {
          $this.submitLoading = false
          $this.error(this.$i18n.messages[this.$i18n.locale].complianceCheck.saveFailMsg)
          return false
        }
        $this.dialogData = false
      }, res => {
        $this.submitLoading = false
      })
    },
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      if (row.errorFields instanceof Array) {
        let flag = false
        row.errorFields.forEach(row => {
          if (row === column.property) {
            flag = true
          }
        })
        if (flag) {
          return 'color: red'
        } else {
          return ''
        }
      } else {
        return ''
      }
    },
    mergedCell: function ({ row, column, rowIndex, columnIndex }) {
      if (this.spanArr.length === 0) {
        this.getSpanArr()
      }
      if (columnIndex === 0) { // 对前1列进行合并
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    getSpanArr () {
      this.spanArr = [] // 避免表格错乱！
      let $this = this
      this.sIdx = 0
      this.sourceData.forEach((item, index) => {
        item.index = index
        if (index === 0) {
          $this.spanArr.push(1)
          $this.position = 0
          $this.sameRowArr.push([index])
        } else {
          if ($this.sourceData[index].fileName === $this.sourceData[index - 1].fileName) { // 这里是要合并行
            $this.spanArr[this.position] += 1
            $this.spanArr.push(0)
            $this.sameRowArr[$this.sIdx].push(index)
          } else {
            $this.spanArr.push(1)
            $this.position = index
            $this.sIdx += 1
            $this.sameRowArr.push([index])
          }
        }
      })
    },
    showDialog: function (row) {
      let $this = this
      $this.submitParams = {}
      let params = {}
      params['taskId'] = this.form.taskId
      params['assetId'] = this.form.assetInfoId
      params['descriptionCode'] = row.descriptionCode
      $this.submitParams.taskId = this.form.taskId
      $this.submitParams.assetId = this.form.assetInfoId
      $this.submitParams.descriptionCode = row.descriptionCode
      let changeOne = false
      let changetwo = false
      tracemgrApi['descriptionOfGenerationDialog'].getdescriptionContent(params).then(res => {
        if (res.data === undefined) {
          $this.getFormDataForchange = true
          changeOne = true
        } else {
          $this.item.assetInfos = Object.assign({}, JSON.parse(res.data.descriptionContent))
          $this.getFormDataForchange = false
          changeOne = true
        }
      })
      if ($this.getFormDataForchange) {
        tracemgrApi['onlineAuditTaskDialog'].getOrderInfo($this.form.assetInfoId).then(info => {
          $this.item.assetInfos = Object.assign({}, info.data)
          changetwo = true
        }, res => {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.generateMasseleven)
        })
      }

      $this.chatTimer = setInterval(() => {
        if (changeOne && $this.getFormDataForchange ? changetwo : true) {
          $this.item.data = $this.form.assetCode
          $this.item.name = row.supplementFileName
          tracemgrApi['descriptionOfGenerationDialog'].getTempleteCode({ 'fileCode': row.descriptionCode }).then(res => {
            let templeteCode = res.data.templeteCode
            if (templeteCode) {
              if (templeteCode === 'tracemgr_pdf_template_No1') {
                //  情况说明
                $this.situationDescriptionDialogShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No2') {
                //  授权书
                $this.empowerDialogShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No3') {
                // 超采集无展期确认函情况说明
                $this.confirmLetterShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No4') {
                //  委托收款函
                $this.entrustReceivablesDialogShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No5') {
                // 前置问题情况说明
                $this.preposedProblemDialogShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No6') {
                //  授权监管验收的授权书
                $this.authorizedSupervisionAndAcceptanceDialogShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No7') {
                //  账户证明
                $this.accountProofShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No8') {
                //  变更生效条款
                $this.changeClauseDialogShow = true
              } else if (templeteCode === 'tracemgr_pdf_template_No9') {
                //  电子章过期的情况说明
                $this.electronicChapterDialogShow = true
              }
              clearInterval($this.chatTimer)
            }
          }, res => {
            clearInterval($this.chatTimer)
            $this.error($this.$i18n.messages[$this.$i18n.locale].traceMgr.getTemplatCodeException)
          })
        }
      }, 200)
    },
    close () {
      if (!this.dialogVisible) {
        return
      }
      let rowData = this.sourceData
      let editInformation = false
      rowData.forEach(row => {
        if (row.fileId === '') {
          row.fileId = undefined
        }
        if (row.fileIdCopy === '') {
          row.fileIdCopy = undefined
        }
        if (row.supplementFileCode === '') {
          row.supplementFileCode = undefined
        }
        if (row.supplementFileCodeCopy === '') {
          row.supplementFileCodeCopy = undefined
        }
        if (row.comment === '') {
          row.comment = undefined
        }
        if (row.commentCopy === '') {
          row.commentCopy = undefined
        }
        if (row.isLater === '') {
          row.isLater = undefined
        }
        if (row.isLaterCopy === undefined) {
          row.isLaterCopy = '0'
        }
        if (row.fileId !== row.fileIdCopy || row.supplementFileCode !== row.supplementFileCodeCopy || row.comment !== row.commentCopy || row.isLater !== row.isLaterCopy) {
          editInformation = true
        }
      })

      if (editInformation) {
        var p = new Promise((resolve, reject) => {
          this.$confirm(this.$i18n.messages[this.$i18n.locale].traceMgr.TipsInfo, this.$i18n.messages[this.$i18n.locale].common.tip, {
            confirmButtonText: this.$i18n.messages[this.$i18n.locale].traceMgr.leaveInfo,
            cancelButtonText: this.$i18n.messages[this.$i18n.locale].approval.cancel,
            type: 'warning'
          }).then(() => {
            // 点击离开
            this.dialogVisible = false
            p.toString()
          }).catch(err => {
            reject(err)
          })
        })
        this.$emit('updateData')
      } else {
        this.dialogVisible = false
      }
    },
    closeDialog () {
      // if (this.changeDate) {
      //   this.dialogData = true
      // } else {
      this.dialogVisible = false
      this.dialogData = false
      this.$emit('updateData')
      this.handler()
      // }
    },
    resetHomePageDataTable (formData) {
      // 供应商名称
      this.supplierName = formData.supplierName
      // 项目公司
      this.projectCompany = formData.projectCompanyOne
      // 合同名称
      this.contractName = formData.contractName
      //  保理合同编号
      this.assetCodeBl = formData.assetCode
      //  付款确认书编号
      this.assetCode = formData.assetCode
      // 保理商
      this.factor = formData.factor
      // 单位名称
      this.initialOwnersName = formData.companyName
      // 开户银行
      this.planOrBankName = formData.bank
      // 账户
      this.planOrBankId = formData.username
      // 收款单位
      this.receivablesCompanyName = formData.receivablesCompanyName
      // 出具方名称
      this.projectCompanyName = formData.nameOfIssuer
      // 合同另一方名称
      this.supplierName = formData.nameOfTheOtherParty
      // 基础合同名称
      this.basicContractName = formData.basicContract
      // 基础合同条款
      this.forceClauseName = formData.basicContractClause
      // 收款单位名称
      this.projectCompanyName = formData.payeeName
      // 第一个过期方名称
      this.projectCompanyName = formData.overduePartyOne
      // 第二个过期方名称
      this.projectCompanyName = formData.overduePartyTwo
      // 第三个过期方名称
      this.projectCompanyName = formData.overduePartyThere
      //    签署合同的另一方
      this.supplierName = formData.theOtherParty
      // 第一个合同名称或履约文件
      this.bussContractName = formData.contractOrPerformanceOne
      // 新证书有效期时间
      this.newTermOfValidity = formData.nowValidityOfCertificate
      // 旧证书有效期时间
      this.oldTermOfValidity = formData.obsoleteValidityOfCertificate
      // 电子章签名时间
      this.stampingTime = formData.time
      // 第二个合同名称或履约文件
      this.bussContractName = formData.contractOrPerformanceTow
      // 第三个合同名称或履约文件
      this.bussContractName = formData.contractOrPerformanceThere
      // 签约编号
      this.factoringContract = formData.signingCode
      // 日期
      this.submintDate = formData.date
      // 我司
      this.projectCompanyNameMy = formData.myCompany
      // 发票号码
      this.invoiceNo = formData.invoice
      // 授权单位
      this.supplierName = formData.authorizedCompanyOne
      // 项目公司名称
      this.itemCompanyName = formData.projectCompany
      // 合同编号
      this.itemBaseContractNo = formData.contractNo
      // 协议名称
      this.itemBaseContractName = formData.agreement
      // 保理商
      this.projectCompanyName = formData.factoring
      //    第一个项目公司名称
      this.supplierName = formData.enterpriseNameOne
      // 合同编号
      this.bussContractCode = formData.contractNo
      //    基础合同名称
      this.bussContractName = formData.basicContract
      //    客户填写的原因
      this.reasons = formData.customerReason
      //  客户填写的说明内容
      this.content = formData.customerDescription
      // 保理商
      this.supplierName = formData.factoring
      // 供应商
      this.projectCompanyName = formData.supplier
      //    债权人
      this.supplierName = formData.creditor
      //    项目公司名称
      this.bussContractName = formData.projectCompanyName
      //    保理金额
      this.factoringMoney = formData.moneny
      // 第一个多行编辑
      this.reasons = formData.explanationOne
      // 第二个多行编辑
      this.reasonsNote = formData.explanationTwo
      // 授权单位
      this.projectCompanyName = formData.authorizedUnitOne
      //    被授权单位
      this.supplierName = formData.authorizedUnitTwo
      //  企业B
      this.supplierName = formData.enterpriseB
      // 签订时间
      this.signDate = formData.signDate
      //  协议名称
      this.bussContractName = formData.agreementName
      //  有效期
      this.validity = formData.termOfValidity
      // 采集商
      this.projectCompanyName = formData.purchaser
      // 供应商
      this.supplierName = formData.supplier
      // 订单名称
      this.pdcPlatform = formData.name
      //  订单编号
      this.pdcNumber = formData.order
      //  订单协议
      this.scheme = formData.orderagreementName
      this.bussContractName = formData.orderagreement
      // 授权单位
      this.supplierNameOne = formData.authorizedCompanyOne
      // 项目公司
      this.projectCompanyName = formData.projectCompanyOne
      // 合同名称
      this.bussContractName = formData.contractName
      // 被授权公司
      this.authorizedName = formData.authorizedCompany
      // 第二个项目公司
      this.projectCompanyName = formData.projectCompanyTow
      // 保理商
      this.authorizedName = formData.factor
      // 单位名称
      this.initialOwnersName = formData.companyName
      // 开户银行
      this.planOrBankName = formData.bank
      // 账户
      this.planOrBankId = formData.username
      // 收款单位
      this.initialOwnersName = formData.receivablesCompanyName
      this.handleFilter()
      //    这里调用接口 封装参数
    }
  }
}
</script>

<style scoped lang="scss">
  @import '~@/styles/tracemgr/factoringCommissioner/taskTable/supplierSealNotice/taskDialog.scss';
</style>
