addRole.vue
6.17 KB
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
<template>
<div>
<el-dialog :title="$t('dialog.addRole')" :visible.sync="isShow" class="manage-dialog" :before-close="closeDialog">
<el-form :model="addForm" status-icon :rules="rules" ref="addForm">
<el-form-item :label="$t('table.roleName')" prop="name">
<el-input v-model="addForm.name"></el-input>
<i class="error-tip">*</i>
</el-form-item>
<el-form-item :label="$t('table.englishName')" prop="enName">
<el-input v-model="addForm.enName"></el-input>
<!-- <i class="error-tip">*</i> -->
</el-form-item>
<el-form-item :label="$t('table.state')" prop="stutas">
<el-select class="manage-sel" v-model="addForm.stutas" :placeholder="$t('pholder.state')" :no-data-text="$t('pholder.nodata')">
<el-option :label="$t('table.stateA')" :value="1"></el-option>
<el-option :label="$t('table.stateB')" :value="2"></el-option>
</el-select>
<!-- <i class="error-tip">*</i> -->
</el-form-item>
<!-- <el-form-item :label="$t('table.square')" prop="mallId">
<el-select class="manage-sel" v-model="addForm.mallId" filterable :placeholder="$t('pholder.select')" :no-data-text="$t('pholder.nodata')">
<el-option v-for="item in mallList" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
<i class="error-tip">*</i>
</el-form-item> -->
<el-form-item :label="$t('table.describe')" prop="position">
<el-input v-model="addForm.position"></el-input>
<!-- <i class="error-tip">*</i> -->
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="closeDialog" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
<el-button type="primary" @click="addSubmit('addForm')" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
var checkAge = (rule, value, callback) => {
if (!value) {
return callback(new Error('名字不能为空'));
}
setTimeout(() => {
if (!Number.isInteger(Number(value))) {
callback(new Error('请输入正确格式'));
} else {
// if (value < 18) {
// callback(new Error('必须年满18岁'));
// } else {
callback();
// }
}
}, 1000);
};
return {
isShow: false,
addForm: {
name: '',
mallId: null,
gender: null,
age: null,
position: ''
},
mallList: [],
rules: {
name: [
{ required: true, message: '请输入姓名', trigger: 'blur' }
],
// gender: [
// { required: true, message: '请选择性别', trigger: 'change' }
// ],
// age: [
// { validator: checkAge, trigger: 'blur' }
// ],
// mallId: [
// { required: true, message: '请选择所属广场', trigger: 'change' }
// ]
},
curMallId: null,
}
},
created() {
// this.getMallList();
},
methods: {
dialogInit(mall_id) {
this.curMallId = mall_id;
this.getMallList();
this.isShow = true;
},
getMallList() {
this.mallList = [];
this.$api.base.mall({
accountId: this.$cookie.get('accountId'),
// status: 1,
status_arr: '1,3'
// _t: Date.parse(new Date()) / 1000
},null,true)
.then(res => {
let result = res.data;
result.data.forEach(item => {
if(item.id == this.curMallId) {
this.addForm.mallId = item.id;
}
})
if(result.data.length > 0) {
if(!this.curMallId) {
this.addForm.mallId = result.data[0].id;
}
this.mallList = result.data;
}
})
.catch(err => { })
},
bindRole(role_unid){
this.$api.management.bindRole(this.$cookie.get('user_unid'), {
role_unid: role_unid
})
.then(res => {
this.$message({
showClose: true,
message: this.$t('message.bindSuccess'),
type: 'success'
})
this.$refs.addForm.resetFields();
this.$parent.getTableData();
})
.catch(error => {
// console.log('bind role err', error)
this.$message({
showClose: true,
message: this.$t('message.bindFailed'),
type: 'error'
})
})
},
addSubmit(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.$api.management.addRole({
name: this.addForm.name
})
.then((res) => {
let result = res.data;
if(result){
this.bindRole(result.role_unid)
}
})
.catch((error) => {
})
} else {
return false;
}
});
this.isShow = false
},
closeDialog() {
this.$refs.addForm.resetFields();
this.isShow = false;
// this.$parent.getTableData();
}
}
}
</script>