<style>
.empowerEdit .mimitBody {
  padding: 20px;
  background-color: #fff;
  margin: 10px 0 20px 0;
  display: table;
  width: 100%;
}
.empowerEdit .tpEdit_header {
    padding: 18px;
    background: #fff;
    color: #606266;
    margin-bottom: 10px;
  }
.empowerEdit .mimitList {
  margin-bottom: 15px;
  display: flex;
  flex-direction: row;
}

.empowerEdit .mimitBody .el-tag {
  min-width: 120px;
  padding-right: 50px;
}

.empowerEdit .el-button--small {
  padding: 9px 25px;
}
</style>
<template>
  <div class="empowerEdit">
    <div class="tpEdit_header">
      <span style="color:rgb(64, 158, 255);cursor:pointer;" @click="CommonJump('empowerManage',{})">授权管理</span><span
        style="margin:0 9px;color:#C0C4CC">/</span><span>新增</span>
    </div>
    <div class="mimitBody">
      <div class="el-col el-col-6">
        <el-form
          :model="msg"
          :rules="rules"
          ref="msg"
          label-width="150px"
        >
          <el-form-item label="集团域名"  size="small" prop="DomainName">
            <el-input
              type="text"
              size="small"
              maxlength="200"
              v-model="msg.DomainName"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="账号"  size="small" prop="Account">
            <el-input
              type="text"
              size="small"
              maxlength="200"
              v-model="msg.Account"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="密码"  size="small" prop="Password">
            <el-input
              type="text"
              size="small"
              maxlength="200"
              v-model="msg.Password"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="绑定用户"  size="small" prop="MallUserId">
              <el-select  style="margin-right: 10px;width:100%" v-model="msg.MallUserId" size="small" 
                      placeholder="请选择" >
                      <el-option v-for="item in options" :key="item.EmpId" :label="item.EmpName" :value="item.EmpId">
                      </el-option>
                  </el-select>
          </el-form-item>
          <el-form-item label="是否推送IM消息">
            <el-switch
                v-model="msg.IsSendIMMsg"
                active-color="#409EFF"
                :active-value="1"
                :inactive-value="0">
            </el-switch>
          </el-form-item>
        </el-form>
      </div>
    </div>
    
    <el-button size="small" type="primary" @click="submitForm('msg')" 
      >保存</el-button
    >
  </div>
</template>
<script>
export default {
  data() {
    return {
      msg:{
          ID:0,
          DomainName:'',
          Account:'',
          Password:'',
          Type:1,
          MallUserId:'',
          IsSendIMMsg:0 //0否 1是
      },
      options:[],
      rules: {
          DomainName: [{
            required: true,
            message: "请输入集团域名",
            trigger: "blur"
          }],
          Account: [{
            required: true,
            message: "请输入账户",
            trigger: "blur"
          }],
          Password: [{
            required: true,
            message: "请输入密码",
            trigger: "blur"
          }],
          MallUserId: [{
            required: true,
            message: "请输入绑定用户",
            trigger: "blur"
          }],
        }
    };
  },
  created() {},
  methods: {
    //获取集团授权信息
    getEmployeeData(data) {
      this.assetsApipost(
        "/api/Authorize/GetAuthorizeModel",
        {
            Type:data.Type,
            ID:data.ID
            },
        res => {
            if (res.data.resultCode == 1) {
                if(res.data.data !=null){
                    let data = res.data.data;
                    this.msg.ID = data.ID;
                    this.msg.DomainName = data.DomainName;
                    this.msg.Account = data.Account;
                    this.msg.Type = data.Type;
                    this.msg.MallUserId = data.MallUserId;
                    this.msg.IsSendIMMsg = data.IsSendIMMsg;
                }
            } else {
            this.Info(res.data.message);
            }
        }
      );
    },
    getEmployeeList(){
    this.assetsApipost(
        "/api/Employee/GetEmployeeList",
        {},
        res => {
          if (res.data.resultCode == 1) {
              this.options = res.data.data
          } else {
            this.Info(res.data.message);
          }
        }
      );
    },
    submitForm(msg){
        this.$refs[msg].validate(valid => {
          if (valid) {
            this.assetsApipost(
              "/api/Authorize/SetAuthorize",
              this.msg,
              res => {
                if (res.data.resultCode == 1) {
                    this.Success(res.data.message);
                   this.CommonJump("empowerManage");
                } else {
                  this.Info(res.data.message);
                }
              }
            );
          } else {
            return false;
          }
        });
    }
  },
  mounted() {
    // this.GetWeiXinAppConfig();
    this.getEmployeeList()
    if( this.$route.query.ID!=0){
        this.getEmployeeData(this.$route.query)
    }
    
  }
};
</script>
