liangjin
2021-04-02 ea4d603dc171a27e19611902d3d4e97583b816b9
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!--
 * @Author: 小明丶
 * @Date: 2019-08-20 18:12:00
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-11-17 09:39:52
 * @Description:
 -->
<template>
  <div class="account-add h-100-g">
    <v-navbar title="新增账户" fixed>
      <div slot="right" v-if="!isAdd" @click="update">保存</div>
    </v-navbar>
 
    <div class="cell-group">
      <v-cell v-model="form.name" max='6' label="负责人姓名" placeholder="请输入姓名"></v-cell>
      <v-cell v-model="form.mblNo" max='11' type='tel' label="负责人手机号" placeholder="请输入手机号" :readonly="!isAdd"></v-cell>
    </div>
    <p class="tip">*该手机号将作为登录用户名,密码将通过短信发至手机</p>
 
    <div class="cell-group">
      <v-cell v-model="form.email" max="50" label="联系邮箱" placeholder="请输入邮箱地址"></v-cell>
    </div>
 
 
    <footer class="flex-center-g footer">
      <van-button class="btn" :color="$store.state.backColor" v-if="isAdd" @click="add">新增账户</van-button>
      <van-button class="btn" :color="$store.state.backColor" v-else @click="freeze">{{isFreeze?'冻结':'启用'}}</van-button>
    </footer>
  </div>
</template>
 
<script>
import { mapState } from "vuex";
export default {
  name: "account-add",
  data() {
    return {
      form: {
        name: "",
        mblNo: "",
        email: "",
        name: "",
        menuPower: [100001, 100006],
        powerInfoVos: [] //权限列表
      },
      rule:[
        {key:"name",message:"请输入账户名称",type:"isEmpty"},
        {key:"name",message:"请输入正确的账户名称",rule:/^[\u4e00-\u9fa50-9a-zA-Z]{1,6}$/},
        {key:"mblNo",message:"请输入手机号",type:"isEmpty"},
        {key:"mblNo",message:"请输入正确的手机号",type:"isTel"},
        {key:"email",message:"请输入联系邮箱",type:"isEmpty"},
        {key:"email",message:"请输入正确的联系邮箱",type:"isEmail"},
      ],
      isFreeze: false
    };
  },
  computed: {
    ...mapState(["userinfo"]),
    // 判断是新增 还是 详情
    isAdd() {
      return this.$route.query.isAdd == "1";
    },
    //权限列表
    powerInfo() {
      return this.form.powerInfoVos || [];
    },
    id() {
      return this.$route.query.id || "";
    }
  },
  created() {
    this.form.powerInfoVos  = this.userinfo.powerInfoVos;
    if (!this.isAdd) {
      this.init();
    }
  },
  methods: {
    //获取用户详情
    init() {
      this.$api.getUserDetail(this.id).then(({ body }) => {
          let {powerInfoVos} = body;
          if (body.supStatus && body.status) {
            this.isFreeze = true;
          } else {
            this.isFreeze = false;
          }
          let powerInfo = this.userinfo.powerInfoVos;
          if (powerInfoVos.length) {
            powerInfo.forEach(item => {
              let index = powerInfoVos.findIndex(child => {
                return item.powerId === child.powerId;
              });
            });
          }
 
          this.form = {
            ...this.form,
            ...body
          };
          this.form.powerInfoVos = this.userinfo.powerInfoVos;;
        })
        .catch(err => {});
    },
    // 验证form参数
    validatorForm(){
        return this.$validator(this.form,this.rule).check(item=>{
            this.$notify(item.message)
        })
    },
    // 新增
    add() {
      if(!this.validatorForm()) return
      this.$api.userAdd(this.form).then(res => {
          this.$notify("添加成功");
          setTimeout(() => this.$router.go(-1), 1000);
        }).catch(err => {});
    },
    //更新
    update() {
      if(!this.validatorForm()) return
      this.$api.userUpdate(this.form).then(res => {
          this.$notify("保存成功");
        })
        .catch(err => {});
    },
    //冻结账号
    freeze() {
      this.$dialog.confirm({
          message: `请问是否确认${this.isFreeze ? "冻结" : "启用"}该账户?`
        }).then(() => {
          this.$api.userFreezeMgr(this.id).then(() => {
            let text = this.isFreeze ? "冻结成功" : "启用成功";
            this.$notify(text);
            this.isFreeze = !this.isFreeze;
          });
        })
        .catch(() => {
          // on cancel
        });
    }
  }
};
</script>
 
<style scoped lang="less">
.account-add {
  background-color: @c-bg-f5;
  padding-top: 44px;
 
  .tip {
    margin: 10px 0 15px 21px;
    font-size: @font-12;
    color: @c-text-999;
  }
}
 
.cell-group {
  margin: 10px 8px 0;
}
 
.btn {
  width: 340px;
  height: 44px;
  border: none;
  font-size: @font-16;
  border-radius: 22px;
  background-color: @c-bg-default;
  color: @c-text-fff;
}
 
.footer {
  margin-top: 60px;
  padding-bottom: 30px;
}
</style>