adminInfo.vue 5.42 KB
Newer Older
乐宝呗666's avatar
乐宝呗666 committed
1 2
<template>
  <div class="admin-detail-content">
乐宝呗666's avatar
乐宝呗666 committed
3
    <Header title="管理员详情" />
4
    <van-form @submit="onSubmit">
乐宝呗666's avatar
乐宝呗666 committed
5 6
      <div class="input-box">
        <van-field
7
          required
乐宝呗666's avatar
乐宝呗666 committed
8 9 10 11 12
          label="管理员姓名"
          :disabled="disabled"
          v-model="form.userName"
          placeholder="请输入管理员姓名"
          input-align="right"
乐宝呗666's avatar
乐宝呗666 committed
13 14 15 16
          :rules="[
              { required: true, message: '请输入管理员姓名' },
              { pattern: /^\S{1,20}$/, message: '输入内容不能包括空格,且最大长度为20.'}
          ]"
乐宝呗666's avatar
乐宝呗666 committed
17 18
        />
        <van-field
19
          required
乐宝呗666's avatar
乐宝呗666 committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
          label="手机号码"
          :disabled="disabled"
          v-model="form.phone"
          placeholder="请输入手机号码"
          input-align="right"
          :rules="[
              { required: true, message: '请填写您的手机号码!' },
              { pattern: /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/, message: '手机号码格式错误!'}
            ]"
        />
        <van-field
          label="固定电话"
          :disabled="disabled"
          v-model="form.telephone"
          placeholder="请输入固定电话"
          input-align="right"
36
          :rules="[{ validator: validatorTel, message: '固定电话格式错误!' }]"
乐宝呗666's avatar
乐宝呗666 committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50
        />
        <van-field
          label="微信"
          :disabled="disabled"
          v-model="form.weChat"
          placeholder="请输入微信"
          input-align="right"
        />
        <van-field
          label="邮箱"
          :disabled="disabled"
          v-model="form.email"
          placeholder="请输入邮箱"
          input-align="right"
51
          :rules="[{ validator: validatorMail, message: '邮箱格式错误' }]"
乐宝呗666's avatar
乐宝呗666 committed
52 53 54
        />
      </div>
      <div class="admin-detail-button" v-if="!disabled">
乐宝呗666's avatar
乐宝呗666 committed
55 56
        <van-button type="default" plain native-type="button" @click="onCancel">取消</van-button>
        <van-button type="default" native-type="submit">提交</van-button>
乐宝呗666's avatar
乐宝呗666 committed
57 58
      </div>
      <div class="admin-detail-button cancel" v-if="disabled">
乐宝呗666's avatar
乐宝呗666 committed
59
        <van-button type="default" native-type="button" @click="onCancel">返回</van-button>
乐宝呗666's avatar
乐宝呗666 committed
60 61
      </div>
    </van-form>
乐宝呗666's avatar
乐宝呗666 committed
62 63 64 65
  </div>
</template>

<script>
乐宝呗666's avatar
乐宝呗666 committed
66
// { pattern: /^[a-zA-Z][a-zA-Z0-9_-]{5,19}$/, message: '微信号格式错误!'}
乐宝呗666's avatar
乐宝呗666 committed
67
import Header from "@/components/Header/index.vue";
乐宝呗666's avatar
乐宝呗666 committed
68
export default {
乐宝呗666's avatar
乐宝呗666 committed
69
  components: { Header },
乐宝呗666's avatar
乐宝呗666 committed
70 71 72
  data() {
    return {
      disabled: false,
乐宝呗666's avatar
乐宝呗666 committed
73
      form: {},
乐宝呗666's avatar
乐宝呗666 committed
74 75 76 77 78 79
    };
  },
  mounted() {
    this.adminId = this.$route.query.id;
    // 查询管理员信息
    if (this.$route.query.disabled === "true") {
乐宝呗666's avatar
乐宝呗666 committed
80
      this.disabled = true
乐宝呗666's avatar
乐宝呗666 committed
81 82 83
      // 新增
    } else {
      // 修改
乐宝呗666's avatar
乐宝呗666 committed
84
      this.disabled = false
乐宝呗666's avatar
乐宝呗666 committed
85
    }
乐宝呗666's avatar
乐宝呗666 committed
86
    this.getUserInfo();
乐宝呗666's avatar
乐宝呗666 committed
87 88
  },
  methods: {
89 90 91 92 93 94 95 96 97 98 99 100
    validatorTel(val){
      if(val !== 0 && val){
        return /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/.test(val);
      }
      return true
    },
    validatorMail(val) {
      if(val !== 0 && val){
        return /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(val);
      }
      return true
    },
乐宝呗666's avatar
乐宝呗666 committed
101 102
    getUserInfo() {
      let vm = this
乐宝呗666's avatar
乐宝呗666 committed
103
      let param = {
乐宝呗666's avatar
乐宝呗666 committed
104
        id: this.adminId,
乐宝呗666's avatar
乐宝呗666 committed
105 106 107 108 109
      };
      vm.$https(
        {
          url: "tUser/getById",
          method: "get",
乐宝呗666's avatar
乐宝呗666 committed
110 111 112 113 114 115 116 117
          authType: this.backToken,
        },
        param
      )
        .then((res) => {
          if (res.data.resultCode === "200") {
            this.form = res.data.data
          } else {
乐宝呗666's avatar
乐宝呗666 committed
118 119 120
            this.$toast(res.data.message)
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
121
        .catch(function (err) {
乐宝呗666's avatar
乐宝呗666 committed
122 123 124
          console.log(err);
        });
    },
乐宝呗666's avatar
乐宝呗666 committed
125
    onCancel() {
乐宝呗666's avatar
乐宝呗666 committed
126
      this.$router.go(-1)
乐宝呗666's avatar
乐宝呗666 committed
127 128 129
    },
    // 提交数据
    onSubmit() {
乐宝呗666's avatar
乐宝呗666 committed
130 131
      let vm = this
      let param = {}
乐宝呗666's avatar
乐宝呗666 committed
132 133 134 135 136 137 138 139 140
      for (let key in this.form) {
        if (this.form[key]) {
          param[key] = this.form[key];
        }
      }
      vm.$https(
        {
          url: "tUser/update",
          method: "put",
乐宝呗666's avatar
乐宝呗666 committed
141 142 143 144 145 146 147 148 149 150 151 152
          authType: this.backToken,
        },
        param
      )
        .then((res) => {
          if (res.data.resultCode === "200") {
            this.$router.replace({
              path: "/success",
              query: { txt: "信息修改成功", url: "/admin" },
            });
          } else {
            this.$toast(res.data.message);
乐宝呗666's avatar
乐宝呗666 committed
153 154
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
155
        .catch(function (err) {
乐宝呗666's avatar
乐宝呗666 committed
156 157
          console.log(err);
        });
乐宝呗666's avatar
乐宝呗666 committed
158
      
乐宝呗666's avatar
乐宝呗666 committed
159 160
    },
  },
乐宝呗666's avatar
乐宝呗666 committed
161 162 163 164 165
};
</script>

<style lang="scss" scoped>
.admin-detail-content {
乐宝呗666's avatar
乐宝呗666 committed
166
  padding: 50px 24px 0;
乐宝呗666's avatar
乐宝呗666 committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180
  overflow-y: auto;
  .input-box {
    padding-bottom: 32px;
    .van-cell {
      line-height: 40px;
      padding-left: 0;
      padding-right: 0;
      border-bottom: 1px solid #eee;
    }
    .van-cell:after {
      display: none;
    }
  }
  .admin-detail-button {
乐宝呗666's avatar
乐宝呗666 committed
181
    padding: 0 24px;
乐宝呗666's avatar
乐宝呗666 committed
182 183 184
    box-sizing: border-box;
    width: 100%;
    margin: 0 auto;
乐宝呗666's avatar
乐宝呗666 committed
185

乐宝呗666's avatar
乐宝呗666 committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    .van-button--normal {
      background: #a4151d;
      border-radius: 4px;
      height: 40px;
      width: 45%;
      color: #fff;
      border: none;
      font-size: 16px;
      &:first-child {
        margin-right: 5%;
      }
    }
    .van-button--plain {
      background: rgba(164, 21, 29, 0.1);
      border: 1px solid #b40011;
      border-radius: 4px;
      color: #b40011;
    }
  }
乐宝呗666's avatar
乐宝呗666 committed
205 206 207 208
  .cancel {
    .van-button--normal {
      width: 100%;
    }
乐宝呗666's avatar
乐宝呗666 committed
209
  }
210 211 212 213
  ::v-deep .van-cell--required::before {
    left: -10px;
    color:#A4151D;
  }
乐宝呗666's avatar
乐宝呗666 committed
214 215 216 217 218 219
  .van-field__control,
  .van-cell__value {
    color: #333;
  }
}
</style>