<style>
  .editGuestTeam .add-tit {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 20px;
  }

  .editGuestTeam .add-tit p {
    display: flex;
    align-items: center;
    font-weight: bold;
    color: rgba(17, 17, 17, 1);
    font-size: 14px;
  }

  .editGuestTeam .add-tit p span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #409efe;
    border-radius: 50%;
    margin-right: 10px;
  }

  .editGuestTeam .el-dialog__header {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 1);
  }

  .editGuestTeam .dialog-footer {
    text-align: center;
    background-color: rgba(248, 250, 251, 1);
    padding-bottom: 20px;
  }

  .editGuestTeam .el-dialog__footer {
    padding: 0;
  }

  .editGuestTeam .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="editGuestTeam">
    <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>
      </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: ["GuestId"],
    data() {
      return {
        dialogTableVisible: true,
        EmployeeList: [],
        EmpIdsS: [],
        TransferOther: [],
        form: {
          GuestId: 0,
          EmployeeIds: "",
          IsRead: 0,
        },
      };
    },
    watch: {},
    created()
    {
       
    },
    mounted() {
      this.Employee();
      let $this = this;
      setTimeout(() => {
        $this.dialogTableVisible = true;
      }, 50);
    },    
    methods: {
      closedDialog() {
        this.MsgBus.$emit("success");
      },
      addData() {
        this.form.GuestId = this.GuestId;
        if (this.EmpIdsS.length < 1) {
          return this.$message.error("请选择成员");
        } else {
          let str = "";
          this.EmpIdsS.map((x, i) => {
            str = str + x + ",";
          });
          this.form.EmployeeIds = str.substring(0, str.length - 1);
        }
        this.apipost("/api/SellEvent/SetGuestTeam", this.form, (res) => {
          if (res.data.resultCode == 1) {
            this.resetForm("form");
            this.dialogTableVisible = false;
            this.$emit("success");
            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 = {
          GuestId: 0,
          EmployeeIds: [],
          IsRead: 0,
        };
        this.$refs[formName].resetFields();
      },
    },
  };
</script>