<!--自定义文件盖章任务管理-详情-->
<template>
  <div>
    <dialog-edit :width="'800px'" :visible.sync="dialogVisible" :editModel="editModel"
                 :footerBtnShow="false" :formRules="formRules" :form="form"
                 :title="dialogTitle" :api="api">
      <dym-form :componentList="componentList" :formValue="form" @selectChanged="selectChanged"></dym-form>
      <el-form :rules="formRules" ref="formName" :model="form">
        <!-- 中止原因 -->
        <el-form-item v-if="form.stampStatus === '5'" :label="$t('documentSealingTaskManage.terminationCauses')" label-width="80px">
          <el-input type="text" v-model="form['cause']" :disabled="true"></el-input>
        </el-form-item>
        <!-- 待申请/待盖章 -->
        <el-form-item v-if="form.stampStatus === '1' || form.stampStatus === '2'" :label="$t('documentSealingTaskManage.uploadFile')" label-width="80px">
          <el-row>
            <el-col :sm="17">
              <el-input v-model="form['fileName']" :disabled="true"></el-input>
            </el-col>
            <el-col :sm="7" class="content-center">
<!--              <btn-upload size="small" type="primary"-->
<!--                          :uploadApi="uploadApi" :fileID="form.fileId"-->
<!--                          :disabled="true" :btnDisplay="true"-->
<!--                          :uploadName="$t('common.upload')"-->
<!--                          @uploadSuccess="uploadSuccess"-->
<!--                          :openPerms="false" :classType="false"></btn-upload>-->
              <btn-upload :uploadApi="uploadApi" size="small"  type="primary"
                          :fileID="form.fileId" :classType="false" :openPerms="false"
                          :title="$t('ladingManageList.replenishData')" @uploadSuccess="uploadSuccess"></btn-upload>
              <btn-download
                :fileID="geiFileId(form.fileId)"
                :classType="true" size="small" type="primary"
                :openPerms="false" :downloadButtonMsg="$t('common.downLoad')"></btn-download>
            </el-col>
          </el-row>
        </el-form-item>
        <!-- 待确认/已归档  盖章文件 -->
        <el-form-item v-if="form.stampStatus === '3' || form.stampStatus === '4'" :label="$t('documentSealingTaskManage.stampFile')" label-width="80px">
          <el-row>
            <el-col :sm="21">
              <el-input v-model="form['fileName']" :disabled="true"></el-input>
            </el-col>
            <el-col :sm="3" class="content-center">
              <btn-download
                :fileID="geiFileId(form.fileId)"
                :classType="true" size="small" type="primary"
                :openPerms="false" :downloadButtonMsg="$t('common.downLoad')"></btn-download>
            </el-col>
          </el-row>
        </el-form-item>
        <!-- 已归档  鲜章文件 -->
        <el-form-item v-if="form.stampStatus === '4'" :label="$t('documentSealingTaskManage.freshChapterFile')" label-width="80px">
          <el-row>
            <el-col :sm="21">
              <el-input v-model="form['fileName']" :disabled="true"></el-input>
            </el-col>
            <el-col :sm="3" class="content-center">
              <btn-download
                :fileID="geiFileId(form.fileId)"
                :classType="true" size="small" type="primary"
                :openPerms="false" :downloadButtonMsg="$t('common.downLoad')"></btn-download>
            </el-col>
          </el-row>
        </el-form-item>
        <!-- 已终止  文件上传 -->
        <el-form-item v-if="form.stampStatus === '5'" :label="$t('documentSealingTaskManage.uploadFile')" label-width="80px">
          <el-row>
            <el-col :sm="21">
              <el-input v-model="form['fileName']" :disabled="true"></el-input>
            </el-col>
            <el-col :sm="3" class="content-center">
              <btn-download
                :fileID="geiFileId(form.fileId)"
                :classType="true" size="small" type="primary"
                :openPerms="false" :downloadButtonMsg="$t('common.downLoad')"></btn-download>
            </el-col>
          </el-row>
        </el-form-item>
        <!-- 备注 -->
        <el-form-item :label="$t('documentSealingTaskManage.Remarks')" prop="remark" label-width="80px"
                      :rules="form.stampStatus === '1' || form.stampStatus === '2' ? formRules.remark : {}">
          <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" v-model="form['remark']" :maxlength="60"
                    :disabled="form.stampStatus !== '1' && form.stampStatus !== '2'"></el-input>
        </el-form-item>
      </el-form>
      <template slot="footer">
        <!--确认、提交-->
        <auth-button v-if="form.stampStatus !== '4' && form.stampStatus !== '5'" size="medium" type="primary"
                     :loading="okLoading"
                     :label="form.stampStatus === '3' ? $t('common.confirm') : $t('common.submit')" @click="Submitsave"></auth-button>
        <!--中止-->
        <auth-button v-if="form.stampStatus !== '4' && form.stampStatus !== '5'" size="medium" type="primary"
                     :label="$t('documentSealingTaskManage.termination')" @click="terminationWindow"></auth-button>
        <!--关闭-->
        <auth-button size="medium" :label="$t('common.close')" @click="dialogVisible = false" :openPerms="false"></auth-button>
      </template>
    </dialog-edit>
    <document-sealing-task-manage-termination :visible.sync="editVisible" :form="formItem" @back="back"
                                              :editModel="editModel"></document-sealing-task-manage-termination>
  </div>
</template>

<script>
import { DialogEdit, dymForm, btnDownload, btnUpload, authButton } from 'newepoch-components'
import BasePage from '@/pages/baseEditPage'
import { UPLOAD_API } from '@/constant'
import customizejobApi from '@/api/shourangAssetassignee/customizejobApi'
import DocumentSealingTaskManageTermination from '@/pages/shourang/documentSealingTaskManage/documentSealingTaskManageTermination'
import authcenterApi from '@/api/authcenterApi'
import * as format from '@/filters/index'

export default {
  extends: new BasePage(),
  name: 'documentSealingTaskManageEdit',
  components: {
    DocumentSealingTaskManageTermination,
    // SelectDataSource,
    DialogEdit,
    dymForm,
    btnDownload,
    btnUpload,
    authButton
  },
  computed: {
    api () {
      return authcenterApi
    },
    dialogTitle () {
      return this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.editPageHead + '(' +
        format.formatDict(this.form.stampStatus, 'stamp_status') + ')'
    }
  },
  mounted () {},
  data () {
    return {
      okLoading: false,
      uploadApi: UPLOAD_API,
      remarks: '',
      fileName: 'we',
      formItem: {},
      editVisible: false,
      footerFlag: true,
      sourceData: [
        {
          coreEnterprise: '1',
          invoiceType: 1
        },
        {
          coreEnterprise: '2',
          invoiceType: 2
        }
      ],
      componentList: [
        // 资料名称
        {
          value: 'assetName',
          disabled: false,
          componentName: 'el-input',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.materialName,
          labelWidth: '80px',
          placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.pleasematerialName,
          cols: [24, 24, 24, 24],
          prop: 'assetName'
        },
        // 发起人
        {
          value: 'taskSubmitUserName',
          disabled: false,
          componentName: 'el-input',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.initiator,
          labelWidth: '80px',
          placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.pleaseinitiator,
          cols: [24, 24, 24, 24],
          prop: 'taskSubmitUserName'
        },
        // 发起时间
        {
          value: 'taskSubmitDate',
          disabled: false,
          type: 'datetime',
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.initiatData,
          labelWidth: '80px',
          // format: 'yyyy-MM-dd HH:mm:ss',
          placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectinitiatData,
          cols: [24, 24, 24, 24],
          prop: 'taskSubmitDate'
        },
        // 状态
        {
          value: 'stampStatus',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'stamp_status',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.status,
          labelWidth: '80px',
          placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.selectstatus,
          cols: [24, 24, 24, 24],
          prop: 'stampStatus'
        }
      ],
      formRules: {
        fileName: [
          {
            trigger: 'change',
            required: true,
            message: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.documentMust
          }
        ],
        remark: [
          {
            trigger: 'blur',
            required: true,
            message: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.RemarksMust
          }
        ]
      }
    }
  },
  methods: {
    back () {
      this.$emit('stop-success')
      this.dialogVisible = false
    },
    geiFileId (fileid) {
      return fileid
    },
    // 打开中止窗口
    terminationWindow () {
      this.formItem = Object.assign({}, this.form)
      this.editVisible = true
    },
    // 提交保存
    Submitsave () {
      this.$refs['formName'].validate((valid) => {
        if (valid) {
          let submitForm = Object.create(null)
          submitForm = Object.assign({}, this.form)
          submitForm.operatorId = this.$store.state.user.user.userId
          submitForm.operator = this.$store.state.user.user.userName
          var a = this.form.stampStatus
          if (this.form.stampStatus === '1' || this.form.stampStatus === '2') {
            submitForm.stampStatus = '3'
          } else if (this.form.stampStatus === '3') {
            submitForm.stampStatus = '4'
          }
          // this.okLoading = true
          if (this.form.stampStatus === '3') {
            // 确认
            this.cancelHandler(submitForm)
          } else {
            submitForm.stampStatus = a
            this.submitBtnFun(submitForm)
          }
          // customizejobApi.participateApi.putData(submitForm).then(res => {
          //   if (res.data) {
          //     this.success(this.$i18n.messages[this.$i18n.locale].paymentConfirmationManage.editSuccess)
          //     this.$emit('edit-success')
          //     this.dialogVisible = false
          //   } else {
          //     this.error(this.$i18n.messages[this.$i18n.locale].paymentConfirmationManage.editError)
          //   }
          // }).finally(() => {
          //   this.okLoading = false
          // })
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].common.formrulesMessage)
        }
      })
    },
    // 点击确认的调用
    cancelHandler (submitForm) {
      this.okLoading = true
      customizejobApi.participateApi.putData(submitForm).then(res => {
        if (res.data) {
          this.success(this.$i18n.messages[this.$i18n.locale].paymentConfirmationManage.editSuccess)
          this.$emit('edit-success')
          this.dialogVisible = false
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].paymentConfirmationManage.editError)
        }
      }).finally(() => {
        this.okLoading = false
      })
    },
    // 提交的时候的调用
    submitBtnFun (submitForm) {
      this.okLoading = true
      customizejobApi.participateApi.submitUpdate(submitForm).then(res => {
        if (res.data) {
          this.success(this.$i18n.messages[this.$i18n.locale].paymentConfirmationManage.editSuccess)
          this.$emit('edit-success')
          this.dialogVisible = false
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].paymentConfirmationManage.editError)
        }
      }).finally(() => {
        this.okLoading = false
      })
    },
    check (row) {
      return row.invoiceType === 1
    },
    // 导入逻辑
    uploadSuccess (returnData, rowData, fileList) {
      this.$set(this.form, 'fileName', returnData.fileName)
      this.$set(this.form, 'fileId', returnData.fileID)
    },
    selectChanged (data) {
    }
  },
  watch: {
    dialogVisible: {
      deep: true,
      immediate: true,
      handler (n, o) {
        if (n) {
          if (this.form.taskSubmitDate) {
            this.form.taskSubmitDate = format.formatDateTpcModifyS(this.form.taskSubmitDate)
          }
          // this.form.startDate = format.formatDate(this.form.operatingTime)
          // this.$set(this.form, 'startDate', format.formatDate(this.form.operatingTime))
          this.componentList.forEach(it => {
            this.$set(it, 'disabled', true)
          })
          this.$nextTick(() => {
            this.okLoading = false
          })
        } else {
          if (o !== undefined) {
            this.$refs['formName'].clearValidate()
          }
        }
      }
    }
  }
}
</script>

<style scoped lang="scss" src="@/styles/shourang/documentSealingTaskManage/documentSealingTaskManageEdit.scss">
</style>
