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
<template>
<div class="app-content" style="max-height:450px;overflow:auto;">
<a-spin :spinning="loading" style="width: 100%;height: 100%;">
<a-form-model ref="form" :model="formData" :rules="rules" class="from-table">
<a-row>
<a-col :span="24">
<div class="tb-title">
<span>单位信息</span>
</div>
</a-col>
</a-row>
<a-row>
<a-col :span="4" class="bg-gray">
<div>上级单位</div>
</a-col>
<a-col :span="20">
<a-form-model-item prop="upTreeCode">
<unit-tree-select v-model="formData.upTreeCode" :unitType="0" :disable="false"/>
</a-form-model-item>
</a-col>
</a-row>
<a-row>
<a-col :span="4" class="bg-gray">
<div>单位名称</div>
</a-col>
<a-col :span="20">
<a-form-model-item prop="unitName">
<a-input v-model="formData.unitName" placeholder="单位名称" style="width:400px" />
</a-form-model-item>
</a-col>
</a-row>
<a-row>
<a-col :span="4" class="bg-gray">
<div>单位类型</div>
</a-col>
<a-col :span="20">
<a-form-model-item prop="unitType">
<base-select v-model="formData.unitType" :type="6" :isAll="true" />
</a-form-model-item>
</a-col>
</a-row>
<a-row>
<a-col :span="4" class="bg-gray">
<div>单位性质</div>
</a-col>
<a-col :span="20">
<a-form-model-item prop="unitNature">
<para-select v-model="formData.unitNature" :typeId="58" :isAll="true" :width="180" />
</a-form-model-item>
</a-col>
</a-row>
<a-row>
<a-col :span="4" class="bg-gray">
<div>单位地址</div>
</a-col>
<a-col :span="20">
<a-form-model-item prop="unitAddress">
<a-input v-model="formData.unitAddress" :maxLength="30" style="width:400px" />
</a-form-model-item>
</a-col>
</a-row>
<div v-if="managersState">
<manager-add :managers.sync="formData.managers" />
</div>
</a-form-model>
</a-spin>
</div>
</template>
<script>
import { isEmptyParams } from "@/views/utils/common"
import paraMultiSelect from '@/views/components/common/paraMultiSelect'
import paraSelect from '@/views/components/common/paraSelect'
import baseSelect from '@/views/components/common/baseSelect'
import unitTreeSelect from '@/views/components/common/unitTreeSelect'
import managerAdd from './managerAdd.vue'
export default {
name: "unitEdit",
components: {
paraMultiSelect, paraSelect, baseSelect, unitTreeSelect, managerAdd
},
data () {
return {
formData: {
id: null, unitName: null, unitType: null, unitNature: null, unitAddress: null, upTreeCode: null, managers: [{ personName: null, certId: null, mobile: null, username: null, password: null }],
},
rules: {
upTreeCode: [{ required: false, message: '请选择上级单位' }],
unitName: [{ required: false, message: '请输入单位名称' }],
unitType: [{ required: false, message: '请选择单位类型' }],
unitNature: [{ required: false, message: '请选择单位性质' }],
unitAddress: [{ required: false, message: '请输入单位地址' }],
},
managersState: true,
loading: false
}
},
props: {
value: {
type: String,
default: () => {
return null
}
},
},
created () {
if (this.value) {
this.loading = true
this.getUnitById()
this.managersState = false
}
},
methods: {
getUnitById () {
let pars = { id: this.value }
this.$api.unit.getUnitById(pars).then(({ data = {} }) => {
if (data) {
this.formData.id = data.id
this.formData.upTreeCode = data.treeCode.substring(0, data.treeCode.length - 5)
this.formData.unitName = data.unitName
this.formData.unitType = data.unitType + ''
this.formData.unitNature = data.unitNature
this.formData.unitAddress = data.unitAddress
}
this.loading = false
}).catch(() => { this.loading = false })
},
submit () {
if (this.formData.managers.length == 0) {
this.$message.warn('至少添加一位单位管理员!')
return
}
//提交单位数据
this.$refs.form.validate(valid => {
if (valid) {
this.loading = true
let pars = isEmptyParams(this.formData)
let par = { ...pars }
if (!this.value) {
this.$api.unit.addUnit(par).then(({ data = {} }) => {
if (data) {
this.$message.success('添加成功!')
this.$emit('close', 'edit')
}
this.loading = false
}).catch(() => { this.loading = false })
}
else {
this.$api.unit.updateUnit(par).then(({ data = {} }) => {
if (data) {
this.$message.success('修改成功!')
this.$emit('close', 'edit')
}
}).catch(() => { this.loading = false })
}
}
})
}
}
}
</script>