<!-- 删除联系人提示 -->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :form="form" :editModel="editModel" :api="api" :appendToBody="appendToBody"
                 :title="$t('common.tip')" :width="width" :autoSave="autoSave" @onSaved="onSaved" labelWidth="0px"
                 :menuCode="menuId" savePerms="contactDeleteSave">
      <div class="result-box">
        <el-row>
          <i class="el-icon-warning"></i>
        </el-row>
        <p class="fontSize">{{$t('enterpriseInfoManage.supplierInfoManage.delEnterpriseTip1')}}</p>
        <!--<select-enterprise v-model="queryParas.trusteeshipId"-->
                        <!--:placeholder="$t('common.pleaseSelect')"-->
                        <!--width="80%"-->
                        <!--:queryParas="queryList">-->
        <!--</select-enterprise>-->
        <!--<p class="fontSize1">{{$t('enterpriseInfoManage.supplierInfoManage.delEnterpriseTip2')}}</p>-->
      </div>
      <div class="margin-top">
        <el-row :gutter="10">
          <el-col :xs="24" :sm="24" :md="24" :lg="24">
            <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.escrowContact')" labelWidth="115px" prop="trusteeshipId">
              <select-enterprise v-model="form.trusteeshipId"
              :placeholder="$t('common.pleaseSelect')"
              width="80%"
              :queryParas="queryList">
              </select-enterprise>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24">
            <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.deleteReson')" labelWidth="115px" prop="deleteReason"
                          :rules="formRules.deleteReason">
              <el-input type="text" v-model="form.deleteReason" maxlength="50" :placeholder="$t('common.pleaseInput')" class="dymForm width80"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import BaseEdit from '@/pages/baseEditPage'
import { DialogEdit } from 'newepoch-components'
import SelectEnterprise from '@/components/element/enterpriseInfoManage/SelectEnterprise.vue'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
export default {
  extends: new BaseEdit(),
  name: 'delHintEdit',
  components: {
    DialogEdit,
    SelectEnterprise
  },
  props: {
    delStatus: {
      type: Boolean,
      default: function () {
        return false
      }
    }
  },
  data () {
    return {
      width: '35%',
      appendToBody: true,
      autoSave: false,
      dataList: {},
      formValue: {
        deleteReason: ''
      },
      queryParas: {
        employeeIds: this.form.keyIds
      },
      formRules: {
        deleteReason: [{
          required: true,
          message: this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.deleteReason,
          trigger: 'blur'
        }]
      }
      // form: {}
    }
  },
  computed: {
    queryList () {
      if (this.form.keyId && this.form.employeeId) {
        return { keyId: this.form.keyId, enterpriseType: this.form.tagCode, accountIds: [this.form.employeeId] }
      } else {
        return { keyId: 0, enterpriseType: this.form.tagCode, accountIds: ['1'] }
      }
    },
    api () {
      return supplierInfoManageApi.employee
    }
  },
  methods: {
    // 保存
    onSaved () {
      let $this = this
      // delStatus 走单条删除
      if ($this.delStatus) {
        $this.queryParas.employeeId = $this.form.employeeId
        // 账号ID
        // $this.queryParas.keyId = $this.form.keyId
        $this.queryParas.accountId = $this.queryParas.account
        $this.queryParas.deleteReason = $this.form.deleteReason
        $this.queryParas.trusteeshipId = $this.form.trusteeshipId
        supplierInfoManageApi.employeeUpdate.del(this.queryParas).then(res => {
          if (res && res.data) {
            $this.$emit('delSuccess')
            this.queryParas = {}
            $this.success(this.$i18n.messages[this.$i18n.locale].common.delSuccess)
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
          }
          this.dialogVisible = false
        })
      } else {
        $this.queryParas.employeeIds = $this.form.employeeIds
        // 账号ID
        $this.queryParas.keyIds = $this.form.keyIds
        supplierInfoManageApi.employeeUpdate.delemployees(this.queryParas).then(res => {
          if (res && res.data) {
            $this.success(this.$i18n.messages[this.$i18n.locale].common.delSuccess)
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
          }
          this.dialogVisible = false
        })
      }
      // this.$emit('delSuccess')
    },
    copyDeep (templateData) {
      // templateData 是要复制的数组或对象，这样的数组或者对象就是指向新的地址的
      return JSON.parse(JSON.stringify(templateData))
    }
  },
  watch: {
    visible (val) {
      if (val) {
        this.dataList = this.copyDeep(this.form)
      } else {
        this.queryParas = {}
        this.dataList = {}
      }
    }
  }
}
</script>

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