<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item label="接收对象" prop="userName">
        <el-input
          v-model="form.userName"
          placeholder="选择人员"
          readonly
          suffix-icon="el-icon-user-solid"
          @focus="selectUser" />
      </el-form-item>
      <el-form-item label="备注信息" prop="remark">
        <el-input
          v-model="form.remark"
          maxlength="300"
          placeholder="请输入备注信息"
          rows="5"
          show-word-limit
          type="textarea" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import businessApi from '@/api/proj/business'

  export default {
    name: 'Transfer',
    data() {
      return {
        form: {},
        rules: {
          userName: [{ required: true, message: '不能为空', trigger: 'blur' }],
        },
        title: '转移项目',
        dialogFormVisible: false,
      }
    },
    methods: {
      selectUser() {},
      open() {
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await businessApi.businessTransfer(this.form)
            this.$baseMessage(msg, 'success')
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
