<!--
 * @Author: wanglj 471442253@qq.com
 * @Date: 2022-12-26 17:21:07
 * @LastEditors: wanglj
 * @LastEditTime: 2023-01-11 18:25:49
 * @Description: file content
 * @FilePath: \opms_frontend\src\views\customer\components\Shift.vue
-->
<template>
  <el-dialog title="转移客户" :visible.sync="visible" width="30%" @close="handleClose">
    <select-user ref="selectUser" :query-params="{ roles: ['SalesEngineer'] }" @save="selectUser" />
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item label="接收对象" prop="SalesName">
        <el-input v-model="form.salesName" readonly>
          <el-button slot="append" icon="el-icon-search" @click="choose" />
        </el-input>
      </el-form-item>
      <el-form-item label="转移相关" prop="about">
        <el-checkbox-group v-model="form.about">
          <el-checkbox label="客户" />
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="转移原因" prop="remark">
        <el-input v-model="form.remark" maxlength="500" resize="none" :rows="5" show-word-limit type="textarea" />
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="handleSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
  import SelectUser from '@/components/select/SelectUser'
  import to from 'await-to-js'
  import api from '@/api/customer'

  export default {
    components: {
      SelectUser,
    },
    data() {
      return {
        visible: false,
        form: {
          salesName: '',
          about: ['客户'],
          remark: '',
        },
        rules: {
          salesName: [{ required: true, message: '请选择接收对象', trigger: 'change' }],
          about: [{ required: true, message: '请选择转移相关', trigger: 'change' }],
          remark: [{ required: true, message: '请选择转移原因', trigger: 'change' }],
        },
        userList: [],
      }
    },
    methods: {
      handleClose() {
        this.$refs.form.resetFields()
        this.form.salesName = ''
        this.userList = []
      },
      choose() {
        this.$refs.selectUser.open()
      },
      selectUser(userList) {
        this.userList = userList
        this.form.salesName = userList[0].nickName
      },
      async handleSubmit() {
        if (!this.userList.length) return this.$message.warning('请选择销售代表')
        let params = { ...this.form }
        params.SalesId = this.userList[0].id
        const [err, res] = await to(api.updateBytransfer(params))
        if (err) return
        this.$message.success(res.msg)
        this.visible = false
        this.$emit('refresh')
      },
    },
  }
</script>

<style></style>
