<!-- 删除提示 / 删除账号及联系人提示 -->
<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.delTip1')}}</p>
        <select-account v-model="queryParas.account"
                        :placeholder="$t('common.pleaseSelect')"
                        width="80%"
                        :queryParas="{ enterpriseId: form.enterpriseId, enterpriseType: form.tagCode, accountIds: form.accountIds }">
        </select-account>
        <p class="fontSize1">{{$t('enterpriseInfoManage.supplierInfoManage.delTip2')}}</p>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import BaseEdit from '@/pages/baseEditPage'
import { DialogEdit } from 'newepoch-components'
import SelectAccount from '@/components/element/enterpriseInfoManage/SelectAccount.vue'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
export default {
  extends: new BaseEdit(),
  name: 'delHintEdit',
  components: {
    DialogEdit,
    SelectAccount
  },
  props: {
    delStatus: {
      type: Boolean,
      default: function () {
        return false
      }
    }
  },
  data () {
    return {
      width: '35%',
      appendToBody: true,
      autoSave: false,
      queryParas: {
        employeeIds: this.form.keyIds
      }
      // form: {}
    }
  },
  computed: {
    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
        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)
          }
        }).finally(() => {
          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.$emit('delSuccess')
            $this.success(this.$i18n.messages[this.$i18n.locale].common.delSuccess)
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
          }
        }).finally(() => {
          this.dialogVisible = false
        })
      }
      // this.$emit('delSuccess')
    }
  },
  watch: {
    visible (val) {
      if (!val) {
        this.queryParas = {}
      }
    }
  }
}
</script>

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