edit.vue 6.92 KB
Newer Older
xulili's avatar
xulili committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
<template>
  <el-dialog
    custom-class="party-dialog"
    title="编辑账号"
    :visible.sync="dialogVisible"
    width="720px"
    :before-close="handleClose"
  >
    <div class="dialog-content">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        label-position="top"
        class="party-form"
      >
        <div class="form-row">
          <el-form-item label="系统用户名" prop="userName">
            <el-input v-model="form.userName" placeholder="请填写"></el-input>
          </el-form-item>
          <el-form-item label="所在机构" prop="orgId">
            <el-select v-model="form.orgId" filterable placeholder="请选择">
              <el-option
                v-for="item in organList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <el-form-item label="账号有效期" prop="permanent">
          <el-radio-group v-model="form.permanent">
            <el-radio :label="true">永久有效</el-radio>
            <el-radio :label="false">设置有效期</el-radio>
          </el-radio-group>
          <div v-if="!form.permanent">
            <el-date-picker
              class="mt16"
              v-model="form.date"
              type="daterange"
               value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="账号类型" prop="roleList">
          <el-checkbox-group v-model="form.roleList" :min="1">
            <el-checkbox
              v-for="(item,index) in rolesList"
              :key="index"
              :label="item.id"
            >
              {{ item.name }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button @click="handleClose()">取 消</el-button>
      <el-button type="primary" @click="handleSubmit()">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getOrgListWithOutPage } from "@/config/organ";
import { getRoles } from "@/config/roles";
export default {
  data() {
    return {
      dialogVisible: false,
      organList: [],
      rolesList: [],
      id:'',
      form: {
xulili's avatar
xulili committed
81
        id:'',  
xulili's avatar
xulili committed
82 83 84 85 86
        userName: "",
        orgId: "",
        permanent: true,
        date: "",
        roleList: [],
xulili's avatar
xulili committed
87
        type: 1  //1.用户账号 2.平台单位单位管理员账号 3.机顶盒账号 4.运维账号
xulili's avatar
xulili committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      },
      rules: {
        userName: [
          { required: true, message: "请选择系统用户名", trigger: "change" },
        ],
        orgId: [
          { required: true, message: "请输入所在机构", trigger: "change" },
        ],
        permanent: [
          { required: true, message: "请选择账号有效期", trigger: "change" },
        ],
         roleList: [
          { type: 'array',required: true, message: "请选择账号类型", trigger: "change" },
        ]
      },
    };
  },
  mounted() {
    this.getOrgList();
xulili's avatar
xulili committed
107
    this.getRolesList();  
xulili's avatar
xulili committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  },
  methods: {
    // 获取机构列表
    getOrgList() {
      getOrgListWithOutPage().then((res) => {
        this.organList = res;
      });
    },
    // 获取角色列表
    getRolesList() {
      getRoles().then((res) => {
        this.rolesList = res;
      });
    },
    // 根据id获取获取详情内容
    getDetailById(){
xulili's avatar
xulili committed
124
        let _this = this
xulili's avatar
xulili committed
125 126 127 128 129 130
        this.$https(
            {
              method: "get",
              url: "tUser/getById",
              authType: this.backToken,
            },
xulili's avatar
xulili committed
131
            {id:_this.id}
xulili's avatar
xulili committed
132 133
          )
            .then((res) => {
xulili's avatar
xulili committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
              if(res.status == 200 ){
                if (res.data.resultCode == 200  ) {
                    let resData = res.data.data
                    for(let key in _this.form){
                        this.form[key] = resData[key]
                    }
                    if(!this.form.permanent){
                        this.form.date = [
                          resData.effectiveDate,
                          exiredDate
                        ]
                    }
                } else {
                     _this.$message.error(res.data.message);
               } 
              } else {
                   _this.$message.error(res.data);
              }    
xulili's avatar
xulili committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
            })
            .catch((err) => {
              console.log(err);
            });
    },
    // 弹窗关闭
    handleClose() {
      this.$confirm("确认关闭?")
        .then((_) => {
          this.handleReset()  
        })
        .catch((_) => {});
    },
     handleReset(){
        this.dialogVisible = false
        this.$refs.form.resetFields()
        this.form = {
xulili's avatar
xulili committed
169
            userName: "",
xulili's avatar
xulili committed
170 171 172 173
            orgId: "",
            permanent: true,
            date: "",
            roleList: [],
xulili's avatar
xulili committed
174
            type:1
xulili's avatar
xulili committed
175 176 177 178 179
        }
    },
    // 提交
     handleSubmit() {
      // 校验用户输入值
xulili's avatar
xulili committed
180 181
      let _this = this
      _this.$refs.form.validate((valid) => {
xulili's avatar
xulili committed
182 183
        if (valid) {
           let user = {};
xulili's avatar
xulili committed
184 185
           if(!_this.form.permanent && !_this.form.date){
               _this.$message.error('请选择有效期')
xulili's avatar
xulili committed
186 187
               return false
           } 
xulili's avatar
xulili committed
188 189 190
          if(!_this.form.permanent){
               user.effectiveDate = _this.form.date[0];
               user.exiredDate = _this.form.date[1];
xulili's avatar
xulili committed
191
          }
xulili's avatar
xulili committed
192 193 194 195 196 197
          user.userName = _this.form.userName;
          user.orgId = _this.form.orgId;
          user.roleList = _this.form.roleList
          user.permanent = _this.form.permanent;
          user.id = _this.id
          user.type = this.form.type
xulili's avatar
xulili committed
198 199
          this.$https(
            {
xulili's avatar
xulili committed
200 201 202
              method: "put",
              url: "tUser/update",
              authType: _this.backToken,
xulili's avatar
xulili committed
203 204 205 206 207 208 209 210 211 212
            },
            user
          )
            .then((res) => {
              if(res.status == 200 ){
                if (res.data.resultCode == 200  ) {
                    this.$message({
                        type: "success",
                        message: res.data.message,
                    });
xulili's avatar
xulili committed
213
                    _this.dialogVisible = false
xulili's avatar
xulili committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                    this.$emit('success',true)
                } else {
                     this.$message.error(res.data.message);
                     this.$emit('success',false)
               } 
              } else {
                   this.$message.error(res.data);
                   this.$emit('success',false)
              }    
            })
            .catch((err) => {
              console.log(res);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.form-row {
  display: flex;
  justify-content: space-between;
}
</style>