<template>
  <el-dialog
    center
    :title="$t('客服')"
    :visible="show"
    @close="close"
    width="30%">
    <div style="width: 100%;min-height: 200px;text-align: center">
      <el-select filterable v-model="service">
        <el-option v-for="(item,index) in customerServiceList" :key="index" :label="item.deptName ? item.nickname + `（${item.deptName}）`  : item.nickname  " :value="item.id"></el-option>
      </el-select>
      <div style="display: flex;margin-top: 20px;">
        <label style="width:100px;" >申请理由</label>
        <el-input v-model="textarea" type="textarea"></el-input>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
    <el-button @click="$emit('update:show',false)" >{{$t('取 消')}}</el-button>
    <el-button type="primary" @click="submit">{{$t('确 定')}}</el-button>
  </span>
  </el-dialog>
</template>

<script>
import {listServiceUser} from "@/api/system/user";
import {handoverApproval, handOverCustomer} from "@/api/ecw/customer";

export default {
  name: "transferCustomer",
  props:{
    show:{
      type:Boolean ,
      default:false
    },
    customerIds:[Array,String],
    tableName:String
  },
  created() {
    listServiceUser().then(r=>{
      this.customerServiceList = r.data;
    })
  },
  computed:{
    getCustomerIds(){
      console.log(this.customerIds,'this.customerIds')
      if(this.customerIds instanceof Array) return this.customerIds
      else return this.customerIds.split(',')
    }
  },
  data(){
    return {
      customerServiceList:[],
      service:'',
      textarea:''
    }
  },
  methods:{
    submit(){
      if(!this.service){
        return this.$message.warning(this.$t('请选择客户经理！'));
      }
      handoverApproval({
        customerServiceId:this.service,
        customerIdList:this.getCustomerIds,
        reason:this.textarea
      }).then(r=>{
        if(r.code === 0){
          if(r.data){
            this.$message.success(r.data)
            this.$emit('update:show',false)
            this.$emit('update:customerIds',[])
            this. service = '';
            this.textarea = '';
          }else {
            this.$emit('update:show',false)
            this.$emit('update:customerIds',[])
            this. service = '';
            this.textarea = '';
            this.$message.success(this.$t('用户批量转移成功！'))
          }
        }
      })
    },
    close(){
      this. service = '';
      this.textarea = '';
      this.$emit('update:show',false)

    },
  }
}
</script>

<style scoped>

</style>
