<!--资料特殊性新增/编辑 -->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :form="form" :editModel="editModel" :api="api" :appendToBody="appendToBody"
                 :title="editModel === 'C'? $t('enterpriseInfoManage.supplierInfoManage.create') : $t('common.update')" labelWidth="155px" :formRules="formRules"
                 width="65%" :beforeSave="true" @onSave="onSave" @beforeSaved="beforeSaved" :loading="saveLoading"
                 :menuCode="menuId" savePerms="dataSave">
        <el-row>
          <el-col :span="24">
            <!--核心企业名称-->
            <el-col :md="24" :lg="7" :xl="7">
              <el-form-item prop="coreEnterpriseName" :label="$t('enterpriseInfoManage.supplierInfoManage.coreEnterpriseName')"
                            :rules="[{ required: 'true', message: $t('regMsg.enterpriseInfoManage.coreEnterpriseName'), trigger: 'change' }]">
                <select-affiliated-enterprises v-model="form.coreEnterpriseName" name="coreEnterpriseName" :disabled="false" :placeholder="$t('common.pleaseInput')" @selectChanged="selectChanged"></select-affiliated-enterprises>
              </el-form-item>
            </el-col>
            <!-- 资产文件 -->
            <el-col :md="24" :lg="7" :xl="7">
              <el-form-item prop="assetFileName" class="margin-left" :label="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.dataFile')">
                  <el-input v-model="form.assetFileName" :disabled="true" :placeholder="$t('common.pleaseSelect')" class="dymForm"></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="24" :lg="2" :xl="2">
              <btn-upload :uploadName="form.assetFileId && form.assetFileId !== '0' ? $t('common.reUpload') : $t('common.upload')" :uploadApi="uploadApi"
                          type="primary" :store="$store" @uploadSuccess="uploadSuccess"
                          :menuCode="menuId" perms="dataUpload" :openPerms="true"></btn-upload>
            </el-col>
            <!--是否发布-->
            <el-col :md="24" :lg="7" :xl="7">
              <el-form-item prop="publishStatus" :label="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.whetherIssue')">
                <select-dictionary v-model="form.publishStatus" dictTypeCode="ZD0003" :store="$store" :placeholder="$t('common.pleaseSelect')">
                </select-dictionary>
              </el-form-item>
            </el-col>
          </el-col>
          <!--审核特殊点-->
          <el-col :span="23">
            <el-form-item prop="approvePoint" :label="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.auditSpecialPoints')"
                          :rules="[{ required: true, message: $t('regMsg.enterpriseInfoManage.auditSpecialPoints'), trigger: 'blur' }]">
              <el-input v-model="form.approvePoint" :rows="3" maxlength="500" class="dymForm" type="textarea"  :placeholder="$t('common.pleaseInput')"></el-input>
            </el-form-item>
          </el-col>
          <!--保理专员建议解决方式-->
          <el-col :span="23">
            <el-form-item prop="commissionerSolutions"
                          :label="editType === '1' ? $t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.factoringSolution') : $t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.areaConSolution')">
              <el-input v-model="form.commissionerSolutions" class="dymForm" :rows="3" maxlength="500" type="textarea" :placeholder="$t('common.pleaseInput')"></el-input>
            </el-form-item>
          </el-col>
          <!--单证解决方式-->
          <el-col :span="23">
            <el-form-item prop="documentSolution" :label="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.documentSolution')">
              <el-input v-model="form.documentSolution" class="dymForm" :rows="3" maxlength="500" type="textarea" :placeholder="$t('common.pleaseInput')"></el-input>
            </el-form-item>
          </el-col>
          <!--审核环节-->
          <el-col :span="24">
            <el-col :md="24" :lg="7" :xl="7">
              <el-form-item prop="approveSegment" :label="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.auditLink')">
                <select-dictionary v-model="form.approveSegment" dictTypeCode="approve_segment" :store="$store"
                                   :placeholder="$t('common.pleaseSelect')">
                </select-dictionary>
              </el-form-item>
            </el-col>
          </el-col>
          <!--备注-->
          <el-col :span="23">
            <el-form-item prop="memo" :label="$t('enterpriseInfoManage.supplierInfoManage.dataSpecificityInfo.remarks')">
              <el-input v-model="form.memo" :rows="3" maxlength="1000" type="textarea" :placeholder="$t('common.pleaseInput')"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
    </dialog-edit>
  </div>
</template>

<script>
import BaseEdit from '@/pages/baseEditPage'
import { UPLOAD_API } from '@/constant.js'
import { DialogEdit, authButton, SelectDictionary, btnUpload, SelectCoreEnterprise } from 'newepoch-components'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
// 核心企业下拉框
import SelectAffiliatedEnterprises from '@/components/element/enterpriseInfoManage/SelectAffiliatedEnterprises.vue'
export default {
  extends: new BaseEdit(),
  name: 'dataSpecificityInfoEdit',
  components: {
    DialogEdit,
    authButton,
    SelectDictionary,
    btnUpload,
    // enterpriseName,
    SelectCoreEnterprise,
    SelectAffiliatedEnterprises
  },
  props: {
    editType: {
      type: String,
      default () {
        return '1'
      }
    }
  },
  computed: {
    api () {
      return supplierInfoManageApi.specialMaterial
    }
  },
  data () {
    return {
      uploadApi: UPLOAD_API,
      appendToBody: true,
      autoSave: false,
      formRules: {},
      saveLoading: false
    }
  },
  methods: {
    selectChanged (index, name, row) {
      if (row) {
        let { enterpriseName, keyId } = row
        this.$set(this.form, 'coreEnterpriseId', keyId)
        this.$set(this.form, 'coreEnterpriseName', enterpriseName)
      } else {
        this.form.coreEnterpriseId = '0'
      }
    },
    uploadSuccess (returnData) {
      this.form.assetFileId = returnData.fileID
      this.$set(this.form, 'assetFileName', returnData.fileName)
    },
    beforeSaved (data) {
      this.saveLoading = true
      if (!data.approveSegment) {
        data.approveSegment = '-1'
      }
    },
    onSave () {
      // this.saveLoading = false
      this.$emit('handleFilter')
    }
  },
  watch: {
    dialogVisible (n) {
      if (n) {
        this.saveLoading = false
        if (this.form && this.form.approveSegment === '-1') {
          this.form.approveSegment = ''
        }
      }
    }
  }
}
</script>

<style scoped lang="scss">
  @import '~@/styles/enterpriseInfoManage/supplierInfoManage/dataSpecificityInfoEdit.scss';
</style>
