<!--
 * @Author: wanglj 471442253@qq.com
 * @Date: 2022-12-26 17:21:07
 * @LastEditors: wanglj
 * @LastEditTime: 2023-01-04 18:06:08
 * @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: ['Sales', 'SalesManager'] }" @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' }],
        },
        userList: [],
      }
    },
    methods: {
      handleClose() {
        this.$refs.form.resetFields()
      },
      choose() {
        this.$refs.selectUser.open()
      },
      selectUser(userList) {
        this.userList = userList
        this.form.SalesName = userList[0].userName
      },
      async handleSubmit() {
        let params = { ...this.form }
        params.SalesIds = 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>
