<template>
  <!--  前置问题情况说明-->
  <el-dialog  :visible.sync="dialogVisible"    :title="item.name"  :width="'60%'" append-to-body close-on-press-escape :close-on-click-modal="false">
    <el-form :size="'small'"     ref="form" label-width="120px">
      <el-row class="text-center el-dialog__title madding-task-management"> <span  class="">{{$t('traceMgr.theme')}}</span></el-row>
      <el-row >
        <el-col  :span="8">
          <el-form-item  label-width="15.5%" :label="$t('traceMgr.preposedProblemOpeningRemarks')"  >
            <el-input  size="mini" v-model="form.factoring"  :placeholder="$t('traceMgr.GSMC')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row >
        <el-col :span="8">
          <el-form-item class="el-form-item-size"  label-width="37%" :label="$t('traceMgr.confirmLetterorHandInfo')"  >
            <el-input  size="mini"  v-model="form.enterpriseNameOne" :placeholder="$t('traceMgr.enterpriseName')"></el-input>
          </el-form-item>
        </el-col>
        <!--        <el-col :span="1">与</el-col>-->
        <el-col :span="7">
          <el-form-item class="el-form-item-size" label-width="23%" :label="$t('traceMgr.preposedProblemText')" >
            <el-input   size="mini" v-model="form.supplier"  :placeholder="$t('traceMgr.preposedProblemSupplier')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item class="el-form-item-size" :label="$t('traceMgr.preposedProblemOne')"  label-width="25%">
            <el-input  size="mini" v-model="form.contractNo" :placeholder="$t('traceMgr.preposedProblemContractNo')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row >
        <el-col :span="7">
          <el-form-item  class="el-form-item-size" label-width="16%" :label="$t('traceMgr.de')"  >
            <el-input  size="mini" v-model="form.basicContract" :placeholder="$t('traceMgr.preposedProblemTwo')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item class="el-form-item-size" :label="$t('traceMgr.preposedProblemThere')" label-width="38%" >
            <el-input  size="mini" v-model="form.customerReason" :placeholder="$t('traceMgr.preposedProblemReason')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item  class="el-form-item-size" label-width="17%" :label="$t('traceMgr.preposedProblemFive')"  >
            <el-input  size="mini" v-model="form.customerDescription" :placeholder="$t('traceMgr.preposedProblemContentDescription')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row >
        <el-col :span="24">
          <label  class="lineHeight lable-left-mini">{{$t('traceMgr.preposedProblemLableOne')}}</label>
        </el-col>
      </el-row>
      <el-row >
        <el-col :span="24">
          <label  class="lineHeight el-form-item-left3">{{$t('traceMgr.preposedProblemLableTwo')}}</label>
        </el-col>
      </el-row>
      <el-row >
        <el-col class="el-form-item-left4"  :span="24">
          <label   >{{$t('traceMgr.herebyExplain')}}</label>
        </el-col>
      </el-row>
      <el-row >
        <el-col class="el-form-item-rg" :span="8">
          <el-form-item   >
            <el-input  disabled readonly v-model="form.enterpriseNameTwo" size="mini"  :placeholder="$t('traceMgr.enterpriseName')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row  >
        <el-col class="el-form-item-rg" :span="8">
          <el-form-item>
            <el-date-picker
              disabled
              readonly
              type="date"
              size="mini"
              v-model="form.date"
              :placeholder="$t('common.chooseDate')">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button   type="button" size="mini"  @click="dialogVisible=false">{{$t('approval.cancel')}}</el-button>
      <el-button type="primary"  size="mini"  @click="submitFormToHomePage">{{$t('common.complete')}}</el-button>
    </div>
  </el-dialog>
</template>
<script>
// import detailView from '@/components/crm/businessMaintainGroup/detailView.vue'
import tracemgrApi from '@/api/tracemgrApi'
import { BaseSelect } from 'newepoch-components'
export default {
  components: {
    BaseSelect
  },
  props: {
    item: {
      type: Object
    },
    processParas: {
      type: Object
    },
    visible: {
      type: Boolean
    },
    title: {
      type: String
    },
    url: {
      type: String
    },
    needComplete: {
      type: Boolean
    },
    resetHomePageDataTable: {
      type: Function
    },
    gradeId: { type: String },
    getFormDataForchange: {
      type: Boolean
    },
    submitParams: {
      type: Object
    }
  },
  data () {
    return {
      buttonStatus: false,
      gradeIndexsArray: [],
      form: {
        // 保理商
        factoring: '',
        //    第一个项目公司名称
        enterpriseNameOne: '',
        //    第二个项目公司名称
        enterpriseNameTwo: '',
        //    供应商名称
        supplier: '',
        // 合同编号
        contractNo: '',
        //    基础合同名称
        basicContract: '',
        //    客户填写的原因
        customerReason: '',
        //  客户填写的说明内容
        customerDescription: '',
        date: ''
      }
    }
  },
  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)
      }
    },
    xhr () {
      return this.$xhr
    }
  },
  watch: {
    visible: {
      handler: function (newValue) {
        let $this = this
        if (newValue) {
          $this.$nextTick(function () {
            if (this.getFormDataForchange) {
              $this.form.enterpriseNameOne = $this.item.assetInfos.assetPaymentInfoDTO.debtor
              $this.form.enterpriseNameTwo = $this.item.assetInfos.assetPaymentInfoDTO.debtor
              $this.form.supplier = $this.item.assetInfos.assetPaymentInfoDTO.creditor
              $this.form.contractNo = $this.item.assetInfos.assetInvoiceInfoDtos[0].invoiceNo
              $this.form.basicContract = $this.item.assetInfos.assetPaymentInfoDTO.basicContractName
            } else {
              $this.form.factoring = $this.item.assetInfos.factoring
              $this.form.enterpriseNameOne = $this.item.assetInfos.enterpriseNameOne
              $this.form.enterpriseNameTwo = $this.item.assetInfos.enterpriseNameTwo
              $this.form.supplier = $this.item.assetInfos.supplier
              $this.form.contractNo = $this.item.assetInfos.contractNo
              $this.form.basicContract = $this.item.assetInfos.basicContract
              $this.form.customerReason = $this.item.assetInfos.customerReason
              $this.form.customerDescription = $this.item.assetInfos.customerDescription
              $this.form.date = $this.item.assetInfos.date
            }
          })
        }
      }
    }
  },
  methods: {
    getComp: function () {
      if (!this.visible) {
      }
    },
    completed: function () {
      // 业务界面完成成功时回调，关闭dialog
      this.dialogVisible = false
      // 刷新列表数据
      this.$parent.handleFilter()
    },
    submitFormToHomePage () {
      let $this = this
      let params = {
        'descriptionContent': JSON.stringify(this.form),
        'taskId': this.submitParams.taskId,
        'assetId': this.submitParams.assetId,
        'descriptionCode': this.submitParams.descriptionCode
      }
      tracemgrApi['descriptionOfGenerationDialog'].saveDescriptionContent(params).then(res => {
        if (res.data) {
          this.success(this.$i18n.messages[this.$i18n.locale].feedBackMain.submitSuccess)
          $this.dialogVisible = false
          $this.resetHomePageDataTable(this.form)
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].feedBackMain.submitError)
        }
      }, res => {
        this.error(this.$i18n.messages[this.$i18n.locale].feedBackMain.submitError)
      })
    }
  }
}
</script>
<style scoped lang="scss">
  @import '~@/styles/tracemgr/factoringCommissioner/taskManagement/taskManagement.scss';
</style>
