<style>

</style>
<template>
    <el-dialog @closed="closedDialog" :visible.sync="dialogTableVisible" width="450px"  
    :close-on-click-modal="false" 
    custom-class="transfer-box add-box add-box2">
        <div class="add-tit" slot="title">
            <p><span></span>商机转订单</p>
            <span icon="el-icon-close"></span>
        </div>
        <div class="form-box" >
            <el-form :model="transferMsg" ref="form" class="MyEditForm" >
            <div class="MyEditForm-item">
                <el-form-item label="变更负责人为" class="label-pad-left">
                    <el-select
                        filterable
                        v-model="transferMsg.EmpId" placeholder="请选择">
                        <el-option
                            v-for="item in EmployeeList"
                            :label='item.EmName'
                            :value='item.EmployeeId'
                            :key='item.EmployeeId'>
                        </el-option>
                    </el-select>
                </el-form-item>
            </div>
            <div class="MyEditForm-item">
                <el-form-item label="将原负责人" class="label-pad-left form-check">
                    <div class="pad-left-10">
                        <el-radio v-model="transferMsg.TransferType" :label="1">移出</el-radio>
                        <el-radio v-model="transferMsg.TransferType" :label="2">转为团队成员</el-radio>
                    </div>
                </el-form-item>
            </div>
            <div class="MyEditForm-item" v-if="transferMsg.TransferType === 2">
                <el-form-item label="权限" class="label-pad-left form-check">
                    <div class="pad-left-10">
                        <el-radio v-model="transferMsg.IsRead" :label="0">只读</el-radio>
                        <el-radio v-model="transferMsg.IsRead" :label="1">读写</el-radio>
                    </div>
                </el-form-item>
            </div>
        </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" class="add-box-btn" @click="submitForm('form')">确 定</el-button>
            <el-button class="add-box-btn add-box-cancel" @click="dialogTableVisible = false, resetForm('form')">取 消</el-button>
        </div>
    </el-dialog>
</template>
<script>
export default {
  props: ["ID","EmployeeList"],
  data() {
    return {
      dialogTableVisible: true,
      EmployeeList: [],
      EmpIdsS: [],
      form: {
        BusinessIds: 0,
        EmpIds: "",
        IsRead: 0,
      },
      transferMsg: {
            CustomerIds: [],
            TransferType: 1, //类型，1-移除，2-转为团员
            IsRead: 0, //0-读写，1-只读
            EmpId: '',
        },
    };
  },
  watch: {},
  mounted() {
    this.Employee();
    let $this = this;
    setTimeout(() => {
      $this.dialogTableVisible = true;
    }, 50);
  },
  methods: {
    closedDialog() {
      this.MsgBus.$emit("closeaddTeamman");
    },
    addData() {
        return
      this.transferMsg.BusinessIds = this.ID;
      if (this.EmpIdsS.length < 1) {
        return this.$message.error("请选择成员");
      } else {
        let str = "";
        this.EmpIdsS.map((x, i) => {
          str = str + x + ",";
        });
        this.transferMsg.EmpIds = str.substring(0, str.length - 1);
      }
      this.apipost("/api/Customer/AddTeamMembersBusiness", this.form, (res) => {
        if (res.data.resultCode == 1) {
          this.resetForm("form");
          this.dialogTableVisible = false;
          this.$emit("TraOrder");
          this.$message.success(res.data.message);
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    submitForm(addMsg) {
      //提交创建、修改表单
      this.$refs[addMsg].validate((valid) => {
        if (valid) {
          this.addData();
        } else {
          return false;
        }
      });
    },
    Employee() {
      let userInfo = this.getLocalStorage();
      let msg = {
        RB_Group_id: userInfo.RB_Group_id,
        BranchId: -1,
        DepartmentId: 0,
        PostId: 0,
        IsLeave: 0,
      };
      this.apipost2(
        "admin_get_EmployeeGetList",
        msg,
        (res) => {
          if (res.data.resultCode == 1) {
            this.EmployeeList = res.data.data;
          } else {
          }
        },
        (err) => {}
      );
    },
    resetForm(formName) {
      // 重置表单
      this.transferMsg = {
        CustomerIds: [],
        TransferType: 1, //类型，1-移除，2-转为团员
        IsRead: 0, //0-读写，1-只读
        EmpId: '',
      };
      this.$refs[formName].resetFields();
      this.$emit('cancel')
    },
  },
};
</script>
