<style>
.addTeamman .add-tit {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 20px;
}
.addTeamman .add-tit p {
  display: flex;
  align-items: center;
  font-weight: bold;
  color: rgba(17, 17, 17, 1);
  font-size: 14px;
}
.addTeamman .add-tit p span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #409efe;
  border-radius: 50%;
  margin-right: 10px;
}
.addTeamman .el-dialog__header {
  padding: 15px 20px;
  background: rgba(255, 255, 255, 1);
}
.addTeamman .dialog-footer {
  text-align: center;
  background-color: rgba(248, 250, 251, 1);
  padding-bottom: 20px;
}
.addTeamman .el-dialog__footer {
  padding: 0;
}
.addTeamman .el-tag.el-tag--info {
  background-color: rgba(0, 0, 0, 0);
  border-color: rgba(0, 0, 0, 0);
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
<template>
    <el-dialog @closed="closedDialog" :modal="false" :visible.sync="dialogTableVisible" width="450px"  :close-on-click-modal="false" class="addTeamman">
        <div class="add-tit" slot="title">
            <p><span></span>添加团队成员</p>
            <span icon="el-icon-close"></span>
        </div>
        <div class="form-box" >
            <el-form :model="form" ref="form" class="MyEditForm">
                <div class="MyEditForm-item">
                    <el-form-item label="成员" class="label-pad-left" prop="ContactDuty">
                        <el-select 
                            multiple
                            filterable
                            v-model="EmpIdsS" 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="form.IsRead" :label="0">只读</el-radio>
                            <el-radio v-model="form.IsRead" :label="1">读写</el-radio>
                        </div>
                    </el-form-item>
                </div>
                <div class="MyEditForm-item">
                    <el-form-item label="同时添加至" class="label-pad-left form-check">
                        <div class="pad-left-10">
                            <el-checkbox-group v-model="TransferOther">
                                <el-checkbox :value="4" :label="4">订单</el-checkbox>
                                <el-checkbox :value="2" :label="2">商机</el-checkbox>
                                <el-checkbox :value="3" :label="3">合同</el-checkbox>
                            </el-checkbox-group>
                        </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"],
  data() {
    return {
      dialogTableVisible: true,
      EmployeeList: [],
      EmpIdsS: [],
      TransferOther: [],
      form: {
        CustomerIds: 0,
        EmpIds: "",
        IsRead: 0,
        TransferOther: "",
      },
    };
  },
  watch: {},
  mounted() {
    this.Employee();
    let $this = this;
    setTimeout(() => {
      $this.dialogTableVisible = true;
    }, 50);
  },
  methods: {
    closedDialog() {
      this.MsgBus.$emit("closeaddTeamman");
    },
    addData() {
      this.form.CustomerIds = this.ID;
      if (this.EmpIdsS.length < 1) {
        return this.$message.error("请选择成员");
      } else {
        let str = "";
        this.EmpIdsS.map((x, i) => {
          str = str + x + ",";
        });
        this.form.EmpIds = str.substring(0, str.length - 1);
      }
      if (this.TransferOther.length < 1) {
        let str2 = "";
        this.TransferOther.map((x, i) => {
          str2 = str2 + x + ",";
        });
        this.form.TransferOther = str2.substring(0, str2.length - 1);
      }
      this.apipost("/api/Customer/AddTeamMembers", this.form, (res) => {
        if (res.data.resultCode == 1) {
          this.resetForm("form");
          this.dialogTableVisible = false;
          this.$emit("addTeammanOk");
          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",
        this.msg,
        (res) => {
          if (res.data.resultCode == 1) {
            this.EmployeeList = res.data.data;
          } else {
          }
        },
        (err) => {}
      );
    },
    resetForm(formName) {
      // 重置表单
      this.form = {
        CustomerId: 0,
        EmpIds: [],
        IsRead: 0,
        TransferOther: [],
      };
      this.$refs[formName].resetFields();
    },
  },
};
</script>
