edit.vue 5.71 KB
Newer Older
xulili's avatar
xulili committed
1 2 3
<template>
  <el-dialog
    custom-class="party-dialog"
xulili's avatar
xulili committed
4
    title="编辑统计账号"
xulili's avatar
xulili committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    :visible.sync="dialogVisible"
    width="468px"
    :before-close="handleClose"
  >
    <div class="dialog-content">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        label-position="top"
        class="party-form"
      >
        <el-form-item label="用户名" prop="userName">
          <el-input
            v-model="form.userName"
            placeholder="请输入用户名"
xulili's avatar
xulili committed
22
            oninput="value = value.trim()"
xulili's avatar
xulili committed
23 24 25
          ></el-input>
        </el-form-item>
        <el-form-item label="所在机构" prop="orgId">
xulili's avatar
xulili committed
26 27 28 29 30 31 32 33 34 35
          <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>
xulili's avatar
xulili committed
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
        <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>
    </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() {
    return {
      dialogVisible: false,
      organList: [],
xulili's avatar
xulili committed
69
      id: "",
xulili's avatar
xulili committed
70
      form: {
xulili's avatar
xulili committed
71
        userName: "",
xulili's avatar
xulili committed
72 73 74
        orgId: "",
        permanent: true,
        date: "",
xulili's avatar
xulili committed
75
        roleList: [],
xulili's avatar
xulili committed
76 77 78 79
      },
      rules: {
        userName: [
          { required: true, message: "请填写管理员姓名", trigger: "change" },
xulili's avatar
xulili committed
80
          { min: 1, max: 20, message: "请输入1到20个字符" },
xulili's avatar
xulili committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
        ],
        orgId: [
          { required: true, message: "请输入所在机构", trigger: "change" },
        ],
        permanent: [
          { required: true, message: "请选择账号有效期", trigger: "change" },
        ],
      },
    };
  },
  mounted() {
    this.getOrgList();
  },
  methods: {
    // 获取机构列表
    getOrgList() {
      getOrgListWithOutPage().then((res) => {
        this.organList = res;
      });
    },

    // 根据id获取获取详情内容
xulili's avatar
xulili committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    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
133 134 135 136 137 138 139 140 141 142 143 144 145
    },
    // 弹窗关闭
    handleClose() {
      this.$confirm("确认关闭?")
        .then((_) => {
          this.handleReset();
        })
        .catch((_) => {});
    },
    handleReset() {
      this.dialogVisible = false;
      this.$refs.form.resetFields();
      this.form = {
xulili's avatar
xulili committed
146
        userName: "",
xulili's avatar
xulili committed
147 148 149
        orgId: "",
        permanent: true,
        date: "",
xulili's avatar
xulili committed
150
        roleList: [],
xulili's avatar
xulili committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
      };
    },
    // 提交
    handleSubmit() {
      // 校验用户输入值
      this.$refs.form.validate((valid) => {
        if (valid) {
          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];
          }
          user.permanent = this.form.permanent;
          user.userName = this.form.userName;
          user.orgId = this.form.orgId;
xulili's avatar
xulili committed
170 171 172
          user.id = this.id;
          user.roleList = this.form.roleList;
          user.type = 5;
xulili's avatar
xulili committed
173 174 175 176 177 178
          this.$https(
            {
              method: "put",
              url: "tUser/update",
              authType: this.backToken,
            },
xulili's avatar
xulili committed
179
            user
xulili's avatar
xulili committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
          )
            .then((res) => {
              if (res.status == 200) {
                if (res.data.resultCode == 200) {
                  this.$message({
                    type: "success",
                    message: res.data.message,
                  });
                  this.handleReset();
                  this.$emit("success", true);
                } else {
                  this.$message.error(res.data.message);
                }
              } else {
                this.$message.error(res.data);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
</style>