edit.vue 7.98 KB
Newer Older
xulili's avatar
xulili committed
1 2 3 4 5 6 7 8
<template>
  <el-dialog
    custom-class="party-dialog"
    title="编辑账号"
    :visible.sync="dialogVisible"
    width="720px"
    :before-close="handleClose"
  >
xulili's avatar
xulili committed
9
    <div class="dialog-content">
xulili's avatar
xulili committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        label-position="top"
        class="party-form"
      >
        <div class="form-row">
          <div>
            <el-form-item label="管理员姓名" prop="userName">
              <el-input
                v-model="form.userName"
                placeholder="请填写管理员姓名"
xulili's avatar
xulili committed
24
                oninput="value = value.trim()"
xulili's avatar
xulili committed
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
              ></el-input>
            </el-form-item>
            <el-form-item label="固定电话" prop="telephone">
              <el-input
                v-model="form.telephone"
                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>
            <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>
          </div>
          <div>
            <el-form-item label="手机号码" prop="phone">
              <el-input
                v-model="form.phone"
                placeholder="请填写手机号码"
              ></el-input>
            </el-form-item>
            <el-form-item label="微信" prop="wechat">
              <el-input
                v-model="form.weChat"
                placeholder="请填写微信号"
              ></el-input>
            </el-form-item>
            <el-form-item label="邮箱" prop="email">
              <el-input
                v-model="form.email"
                placeholder="请填写邮箱地址"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </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";
export default {
  data() {
xulili's avatar
xulili committed
96
    var validateMobilePhone = (rule, value, callback) => {
xulili's avatar
xulili committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
      if (value === "") {
        callback(new Error("手机号不可为空"));
      } else {
        if (value !== "") {
          var reg = /^1[3456789]\d{9}$/;
          if (!reg.test(value)) {
            callback(new Error("请输入有效的手机号码"));
          }
        }
        callback();
      }
    };
    return {
      dialogVisible: false,
      organList: [],
      rolesList: [],
xulili's avatar
xulili committed
113
      id: "",
xulili's avatar
xulili committed
114
      form: {
xulili's avatar
xulili committed
115
        id: "",
xulili's avatar
xulili committed
116 117 118 119 120 121 122 123
        userName: "",
        telephone: "",
        orgId: "",
        permanent: true,
        date: "",
        phone: "",
        weChat: "",
        email: "",
xulili's avatar
xulili committed
124 125
        roleList: [],
        type: 2, //1.用户账号 2.平台单位管理员账号 3.机顶盒账号 4.运维账号
xulili's avatar
xulili committed
126 127 128 129
      },
      rules: {
        userName: [
          { required: true, message: "请选择系统用户名", trigger: "change" },
xulili's avatar
xulili committed
130
          { min: 1, max: 20, message: "请输入1到20个字" },
xulili's avatar
xulili committed
131 132 133 134 135 136 137
        ],
        orgId: [
          { required: true, message: "请输入所在机构", trigger: "change" },
        ],
        permanent: [
          { required: true, message: "请选择账号有效期", trigger: "change" },
        ],
xulili's avatar
xulili committed
138 139 140 141 142 143 144 145
        roleList: [
          {
            type: "array",
            required: true,
            message: "请选择账号类型",
            trigger: "change",
          },
        ],
xulili's avatar
xulili committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159
      },
    };
  },
  mounted() {
    this.getOrgList();
  },
  methods: {
    // 获取机构列表
    getOrgList() {
      getOrgListWithOutPage().then((res) => {
        this.organList = res;
      });
    },
    // 根据id获取获取详情内容
xulili's avatar
xulili committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    getDetailById() {
      let _this = this;
      this.$https(
        {
          method: "get",
          url: "tUser/getById",
          authType: this.backToken,
        },
        { id: _this.id }
      )
        .then((res) => {
          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, resData.exiredDate];
              }
            } else {
              _this.$message.error(res.data.message);
            }
          } else {
            _this.$message.error(res.data);
          }
        })
        .catch((err) => {
          console.log(err);
        });
xulili's avatar
xulili committed
190 191 192 193 194
    },
    // 弹窗关闭
    handleClose() {
      this.$confirm("确认关闭?")
        .then((_) => {
xulili's avatar
xulili committed
195
          this.handleReset();
xulili's avatar
xulili committed
196 197 198
        })
        .catch((_) => {});
    },
xulili's avatar
xulili committed
199 200 201 202 203 204 205 206 207 208 209
    handleReset() {
      this.dialogVisible = false;
      this.$refs.form.resetFields();
      this.form = {
        userName: "",
        orgId: "",
        permanent: true,
        date: "",
        roleList: [],
        type: 2,
      };
xulili's avatar
xulili committed
210 211
    },
    // 提交
xulili's avatar
xulili committed
212
    handleSubmit() {
xulili's avatar
xulili committed
213
      // 校验用户输入值
xulili's avatar
xulili committed
214
      let _this = this;
xulili's avatar
xulili committed
215 216
      _this.$refs.form.validate((valid) => {
        if (valid) {
xulili's avatar
xulili committed
217 218 219 220 221 222 223 224
          let user = {};
          if (!_this.form.permanent && !_this.form.date) {
            _this.$message.error("请选择有效期");
            return false;
          }
          if (!_this.form.permanent) {
            user.effectiveDate = _this.form.date[0];
            user.exiredDate = _this.form.date[1];
xulili's avatar
xulili committed
225
          }
xulili's avatar
xulili committed
226 227 228 229 230 231 232 233 234
          user.id = _this.id;
          user.telephone = this.form.telephone || "";
          user.email = this.form.email || "";
          user.weChat = this.form.weChat || "";
          user.phone = this.form.phone;
          user.permanent = this.form.permanent;
          user.userName = this.form.userName;
          user.orgId = this.form.orgId;
          user.type = this.form.type;
xulili's avatar
xulili committed
235 236 237 238 239 240 241 242 243
          this.$https(
            {
              method: "put",
              url: "tUser/update",
              authType: _this.backToken,
            },
            user
          )
            .then((res) => {
xulili's avatar
xulili committed
244 245 246 247 248 249 250 251
              if (res.status == 200) {
                if (res.data.resultCode == 200) {
                  this.$message({
                    type: "success",
                    message: res.data.message,
                  });
                  _this.dialogVisible = false;
                  this.$emit("success", true);
xulili's avatar
xulili committed
252
                } else {
xulili's avatar
xulili committed
253 254 255
                  this.$message.error(res.data.message);
                  this.$emit("success", false);
                }
xulili's avatar
xulili committed
256
              } else {
xulili's avatar
xulili committed
257 258 259
                this.$message.error(res.data);
                this.$emit("success", false);
              }
xulili's avatar
xulili committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.form-row {
  display: flex;
  justify-content: space-between;
}
</style>