|
106 | 106 |
|
107 | 107 | <script>
|
108 | 108 | import { DML, crud } from '@/api/public/crud';
|
| 109 | +import { Vue, Component, Watch } from 'vue-property-decorator'; |
109 | 110 |
|
110 | 111 | const STATUS = {
|
111 | 112 | CREATE: 0,
|
112 | 113 | UPDATE: 1,
|
113 | 114 | DETAIL: 2,
|
114 | 115 | };
|
115 |
| -export default { |
| 116 | +@Component({ |
116 | 117 | name: 'Dict',
|
| 118 | +}) |
| 119 | +export default class Dict extends Vue { |
117 | 120 | created() {
|
118 | 121 | this.fetchDictType();
|
119 |
| - }, |
120 |
| - data() { |
121 |
| - return { |
122 |
| - // 搜索text |
123 |
| - filterText: '', |
124 |
| - typeList: [], |
125 |
| - dialogFormVisible: false, |
126 |
| - dialogStatus: 0, |
127 |
| - defaultProps: { |
128 |
| - children: 'children', |
129 |
| - label: 'typeName', |
130 |
| - }, |
131 |
| - textMap: { |
132 |
| - 1: '编辑', |
133 |
| - 0: '新增', |
134 |
| - }, |
135 |
| - entity: { |
136 |
| - id: '', |
137 |
| - codeName: '', |
138 |
| - codeValue: '', |
139 |
| - parentId: '', |
140 |
| - codeOrder: 0, |
141 |
| - remark: '', |
142 |
| - }, |
143 |
| - tableParams: {}, |
144 |
| - // 当前节点,字典类型的id |
145 |
| - codeTypeId: '', |
146 |
| - remoteFuncs: { |
147 |
| - getDictType(resolve) { |
148 |
| - // 请求字典分类 |
149 |
| - crud(DML.SELECT, 'ad_codelist_type').then((res) => { |
150 |
| - const options = res.data.list.map(item => ({ |
151 |
| - label: item.typeName, |
152 |
| - value: item.id, |
153 |
| - })); |
154 |
| - resolve(options); |
155 |
| - }); |
156 |
| - }, |
157 |
| - }, |
158 |
| - }; |
159 |
| - }, |
160 |
| - methods: { |
161 |
| - afterDropDown(node, end, position) { |
162 |
| - if (position === 'inner') { |
163 |
| - const obj = node.data; |
164 |
| - obj.parentId = end.data.id; |
165 |
| - crud(DML.UPDATE, 'ad_codelist_type', obj).then(() => { |
166 |
| - this.$message.success('操作成功'); |
167 |
| - this.fetchDictType(); |
168 |
| - }); |
169 |
| - } else if (position === 'before') { |
170 |
| - const obj = node.data; |
171 |
| - obj.codeorder = Number(end.data.codeorder) - 1; |
172 |
| - crud(DML.UPDATE, 'ad_codelist_type', obj).then(() => { |
173 |
| - this.$message.success('操作成功'); |
174 |
| - this.fetchDictType(); |
175 |
| - }); |
176 |
| - } else if (position === 'after') { |
177 |
| - const obj = node.data; |
178 |
| - obj.codeorder = Number(end.data.codeorder) + 1; |
179 |
| - crud(DML.UPDATE, 'ad_codelist_type', obj).then(() => { |
180 |
| - this.$message.success('操作成功'); |
181 |
| - this.fetchDictType(); |
182 |
| - }); |
183 |
| - } |
184 |
| - }, |
185 |
| - remove(data) { |
186 |
| - this.$confirm('确认删除?', '提示', { |
187 |
| - confirmButtonText: '确定', |
188 |
| - cancelButtonText: '取消', |
189 |
| - type: 'warning', |
190 |
| - }).then(() => { |
191 |
| - crud(DML.DELETE, 'ad_codelist_type', {}, { id: data.id }).then(() => { |
192 |
| - this.dialogFormVisible = false; |
193 |
| - this.fetchDictType(); |
194 |
| - }); |
| 122 | + } |
| 123 | +
|
| 124 | + // 搜索text |
| 125 | + filterText = ''; |
| 126 | +
|
| 127 | + typeList = []; |
| 128 | +
|
| 129 | + dialogFormVisible = false; |
| 130 | +
|
| 131 | + dialogStatus = 0; |
| 132 | +
|
| 133 | + defaultProps = { |
| 134 | + children: 'children', |
| 135 | + label: 'typeName', |
| 136 | + }; |
| 137 | +
|
| 138 | + textMap = { |
| 139 | + 1: '编辑', |
| 140 | + 0: '新增', |
| 141 | + }; |
| 142 | +
|
| 143 | + entity = { |
| 144 | + id: '', |
| 145 | + codeName: '', |
| 146 | + codeValue: '', |
| 147 | + parentId: '', |
| 148 | + codeOrder: 0, |
| 149 | + remark: '', |
| 150 | + }; |
| 151 | +
|
| 152 | + tableParams = {}; |
| 153 | +
|
| 154 | + // 当前节点,字典类型的id |
| 155 | + codeTypeId = ''; |
| 156 | +
|
| 157 | + remoteFuncs = { |
| 158 | + getDictType(resolve) { |
| 159 | + // 请求字典分类 |
| 160 | + crud(DML.SELECT, 'ad_codelist_type').then((res) => { |
| 161 | + const options = res.data.list.map(item => ({ |
| 162 | + label: item.typeName, |
| 163 | + value: item.id, |
| 164 | + })); |
| 165 | + resolve(options); |
195 | 166 | });
|
196 | 167 | },
|
197 |
| - save() { |
198 |
| - this.entity.codeValue = this.entity.codeName; |
199 |
| - if (this.dialogStatus === STATUS.CREATE) { |
200 |
| - crud(DML.INSERT, 'ad_codelist_type', this.entity).then(() => { |
201 |
| - this.fetchDictType(); |
202 |
| - this.dialogFormVisible = false; |
203 |
| - }); |
204 |
| - } else { |
205 |
| - crud(DML.UPDATE, 'ad_codelist_type', this.entity).then(() => { |
206 |
| - this.fetchDictType(); |
207 |
| - this.dialogFormVisible = false; |
208 |
| - }); |
209 |
| - } |
210 |
| - }, |
211 |
| - fetchDictType() { |
212 |
| - crud(DML.TREE, 'ad_codelist_type').then((response) => { |
213 |
| - this.typeList = response.data; |
| 168 | + }; |
| 169 | +
|
| 170 | + afterDropDown(node, end, position) { |
| 171 | + if (position === 'inner') { |
| 172 | + const obj = node.data; |
| 173 | + obj.parentId = end.data.id; |
| 174 | + crud(DML.UPDATE, 'ad_codelist_type', obj).then(() => { |
| 175 | + this.$message.success('操作成功'); |
| 176 | + this.fetchDictType(); |
214 | 177 | });
|
215 |
| - }, |
216 |
| - add(data) { |
217 |
| - this.dialogFormVisible = true; |
218 |
| - Object.keys(this.entity).forEach((key) => { |
219 |
| - this.entity[key] = ''; |
| 178 | + } else if (position === 'before') { |
| 179 | + const obj = node.data; |
| 180 | + obj.codeorder = Number(end.data.codeorder) - 1; |
| 181 | + crud(DML.UPDATE, 'ad_codelist_type', obj).then(() => { |
| 182 | + this.$message.success('操作成功'); |
| 183 | + this.fetchDictType(); |
220 | 184 | });
|
221 |
| - this.entity.parentId = data.id; |
222 |
| - this.dialogStatus = STATUS.CREATE; |
223 |
| - }, |
224 |
| - edit(data) { |
225 |
| - this.dialogFormVisible = true; |
226 |
| - this.entity = { ...data }; |
227 |
| - this.dialogStatus = STATUS.UPDATE; |
228 |
| - }, |
229 |
| - treeClick(data) { |
230 |
| - if (data.parentId === '0') { |
231 |
| - delete this.tableParams.codeType; |
232 |
| - } else { |
233 |
| - this.codeTypeId = data.id || ''; |
234 |
| - this.tableParams.codeType = data.id; |
235 |
| - } |
236 |
| - this.$refs.codeListTable.tableReload(); |
237 |
| - }, |
238 |
| - // 树节点过滤 |
239 |
| - filterNode(value, data) { |
240 |
| - if (!value) return true; |
241 |
| - return this.$pinyinmatch.match(data.codeName, value); |
242 |
| - }, |
243 |
| - }, |
244 |
| - watch: { |
245 |
| - filterText(val) { |
246 |
| - this.$refs.dicttypetree.filter(val); |
247 |
| - }, |
248 |
| - }, |
249 |
| -}; |
| 185 | + } else if (position === 'after') { |
| 186 | + const obj = node.data; |
| 187 | + obj.codeorder = Number(end.data.codeorder) + 1; |
| 188 | + crud(DML.UPDATE, 'ad_codelist_type', obj).then(() => { |
| 189 | + this.$message.success('操作成功'); |
| 190 | + this.fetchDictType(); |
| 191 | + }); |
| 192 | + } |
| 193 | + } |
| 194 | +
|
| 195 | + remove(data) { |
| 196 | + this.$confirm('确认删除?', '提示', { |
| 197 | + confirmButtonText: '确定', |
| 198 | + cancelButtonText: '取消', |
| 199 | + type: 'warning', |
| 200 | + }).then(() => { |
| 201 | + crud(DML.DELETE, 'ad_codelist_type', {}, { id: data.id }).then(() => { |
| 202 | + this.dialogFormVisible = false; |
| 203 | + this.fetchDictType(); |
| 204 | + }); |
| 205 | + }); |
| 206 | + } |
| 207 | +
|
| 208 | + save() { |
| 209 | + this.entity.codeValue = this.entity.codeName; |
| 210 | + if (this.dialogStatus === STATUS.CREATE) { |
| 211 | + crud(DML.INSERT, 'ad_codelist_type', this.entity).then(() => { |
| 212 | + this.fetchDictType(); |
| 213 | + this.dialogFormVisible = false; |
| 214 | + }); |
| 215 | + } else { |
| 216 | + crud(DML.UPDATE, 'ad_codelist_type', this.entity).then(() => { |
| 217 | + this.fetchDictType(); |
| 218 | + this.dialogFormVisible = false; |
| 219 | + }); |
| 220 | + } |
| 221 | + } |
| 222 | +
|
| 223 | + fetchDictType() { |
| 224 | + crud(DML.TREE, 'ad_codelist_type').then((response) => { |
| 225 | + this.typeList = response.data; |
| 226 | + }); |
| 227 | + } |
| 228 | +
|
| 229 | + add(data) { |
| 230 | + this.dialogFormVisible = true; |
| 231 | + Object.keys(this.entity).forEach((key) => { |
| 232 | + this.entity[key] = ''; |
| 233 | + }); |
| 234 | + this.entity.parentId = data.id; |
| 235 | + this.dialogStatus = STATUS.CREATE; |
| 236 | + } |
| 237 | +
|
| 238 | + edit(data) { |
| 239 | + this.dialogFormVisible = true; |
| 240 | + this.entity = { ...data }; |
| 241 | + this.dialogStatus = STATUS.UPDATE; |
| 242 | + } |
| 243 | +
|
| 244 | + treeClick(data) { |
| 245 | + if (data.parentId === '0') { |
| 246 | + delete this.tableParams.codeType; |
| 247 | + } else { |
| 248 | + this.codeTypeId = data.id || ''; |
| 249 | + this.tableParams.codeType = data.id; |
| 250 | + } |
| 251 | + this.$refs.codeListTable.tableReload(); |
| 252 | + } |
| 253 | +
|
| 254 | + // 树节点过滤 |
| 255 | + filterNode(value, data) { |
| 256 | + if (!value) return true; |
| 257 | + return this.$pinyinmatch.match(data.codeName, value); |
| 258 | + } |
| 259 | +
|
| 260 | + @Watch('filterText') |
| 261 | + filterTextChange(val) { |
| 262 | + this.$refs.dicttypetree.filter(val); |
| 263 | + } |
| 264 | +} |
250 | 265 | </script>
|
251 | 266 | <style lang="scss" scoped>
|
252 | 267 | .tree {
|
|
0 commit comments