<!-- 选择转交人员 — lrj -->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible"
                 :editModel="editModel"
                 :form="forms"
                 :title="$t('transferPersonIndex.choiceTransferPerson')"
                 :api="api"
                 :formRules="rules"
                 :footerVisible="footerVisible"
                 width="500px">
      <div class="titleLine">{{$t('transferPersonIndex.choiceTransferPerson')}}<span class="line"></span></div>
      <div class="transferPerson">
        <div class="box">
          <el-form :model="forms" :rules="rules" ref="formName">
            <el-form-item :label="$t('transferPersonIndex.transferPerson')" class="dropBox" prop="person">
              <!-- 下拉框 -->
              <select-compliance-acceptor v-model="forms.person"
                                          @selectChanged="selectChanged"></select-compliance-acceptor>
            </el-form-item>
          </el-form>
        </div>
        <el-row>
          <!-- 确定 -->
          <auth-button type="primary"
                       size="medium"
                       :label="$t('common.assign')"
                       @click="chooseTransfer"></auth-button>
          <!-- 关闭 -->
          <auth-button size="medium"
                       :label="$t('common.close')"
                       @click="dialogClose"></auth-button>
        </el-row>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import { DialogEdit, authButton } from 'newepoch-components'
import BaseEditPage from '@/pages/baseEditPage'
import SelectComplianceAcceptor from '@/components/element/assetaudit/SelectComplianceAcceptor-zf'
export default {
  extends: new BaseEditPage(),
  name: 'transferPersonIndex',
  props: {
    // status: { // 状态
    //   type: String,
    //   default: ''
    // },
    editModel: {
      type: String,
      default () {
        return ''
      }
    },
    useTemplate: { // 组件模块
      type: String,
      default () {
        return ''
      }
    },
    deliverType: { // 转交类型（评审）
      type: String,
      default () {
        return ''
      }
    },
    form: {
      type: Object,
      required: true,
      default () {
        return {}
      }
    },
    transferApi: {
      type: [Object],
      required: true
    }
  },
  components: {
    DialogEdit,
    SelectComplianceAcceptor,
    authButton
  },
  computed: {
    api () {
      return this.transferApi
    }
  },
  data () {
    return {
      footerVisible: false,
      forms: {
        person: ''
      },
      person: '',
      rules: {
        person: [
          { required: true, message: '请选择转交人员', trigger: 'change' }
        ]
      },
      value: {}
    }
  },
  methods: {
    // 下拉框change事件触发，返回选中的值
    selectChanged (val, name, row) {
      this.value = row
    },
    // 选择数据返回，调用转交接口
    chooseTransfer () {
      this.$refs['formName'].validate(valid => {
        this.$LoadingShow()
        if (valid) {
          let param
          if (!this.useTemplate) {
            param = {
              handlePersonId: this.value.accountId,
              handlePersonName: this.value.nickName
            }
            param = Object.assign({}, param, this.form)
          } else if (this.useTemplate === 'psscgl') {
            param = {
              deliverType: this.deliverType,
              handlePersonId: this.value.accountId,
              handlePersonName: this.value.nickName
            }
            param.keyIds = this.form.keyIdList
          }
          this.api.putData(param).then(res => {
            this.$LoadingClose()
            if (res.data === true) {
              this.$message.success('选择转交人员成功')
              this.dialogClose()
            }
            this.$emit('forwardCall')
          })
        }
      })
    },
    // 关闭弹窗
    dialogClose () {
      this.dialogVisible = false
    }
  }
}
</script>
