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
<template>
<el-dialog
custom-class="party-dialog"
:title="title"
width="468px"
:visible.sync="formVisible"
:before-close="close"
>
<div class="dialog-content">
<el-form
:model="formItem"
class="party-form"
ref="formItem"
label-width="125px"
label-position="top"
:rules="rules"
>
<el-form-item label="所属单位:" prop="orgId">
<el-select
v-model="formItem.orgId"
clearable
placeholder="请选择所属单位"
@change="selectItem"
>
<el-option
v-for="item in orgOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="机构地理位置:" prop="areaName">
<el-input
v-model="formItem.areaName"
disabled
></el-input>
</el-form-item>
</el-form>
</div>
<div slot="footer" class="dialog-footer btn-group">
<el-button @click="close">取 消</el-button>
<el-button type="primary" @click="submitForm('formItem')">确定</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
title: "", // 标题
formVisible: false,
formItem: {},
orgOptions: [], // 单位信息
rules: {
orgId: [
{ required: true, message: "请选择所属单位", trigger: "change" },
],
},
};
},
mounted() {},
methods: {
backFn(item) {
this.formVisible = true;
this.$nextTick(() => {
this.$refs.formItem.clearValidate();
});
// 新增
this.orgOptions = item;
this.title = "新增";
this.formItem = {};
},
// 关闭
close() {
this.formVisible = false;
for (let key in this.formItem) {
this.formItem[key] = null;
}
this.$refs["formItem"].resetFields();
},
// 联动出地址
selectItem(val) {
this.orgOptions.forEach((item) => {
if (val === item.id) {
this.formItem.areaName = item.areaName;
this.formItem.areaId = item.areaId;
}
if (item.id === this.formItem.orgId) {
this.formItem.userName = item.name;
}
});
},
// 保存编辑信息
submitForm() {
let _this = this;
_this.$refs.formItem.validate((valid) => {
if (valid) {
let searchObj = {};
for (let key in _this.formItem) {
if (this.formItem[key]) {
searchObj[key] = _this.formItem[key]
}
}
_this
.$https(
{
url: "tUser/boxAdd",
method: "post",
authType: this.backToken,
},
_this.$qs.stringify(searchObj)
)
.then(
(res) => {
if (res.data.resultCode === "200") {
_this.$message.success(res.data.message)
_this.formVisible = false
_this.$emit("refreshFn")
} else {
_this.$message.error(res.data.message)
}
},
(error) => {
console.log(error)
}
)
}
})
},
},
};
</script>
<style lang="less">
</style>