chengkun
2025-09-04 0ea78440cb53b7ecf0ef715e3f51d88918c5821d
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
const App = {
    mixins: [sharedMixin],/////共用的方法/////
    data() {
        return {
 
 
            dialogVisible: {
                country: false,
                province: false,
                city: false,
            },
            ifsubmit: false,
            list: [],
            countryList: [],
            currCountryId: 0,
            currProvinceId: 0,
            currCityId: 0,
            currCountryIndex: -1,
            currProvinceIndex: 1,
            currCityIndex: -1,
            countryData: {
                father_id: 0,
            },
            provinceData: {
                father_id: 0,
            },
            cityData: {
                father_id: 0,
            },
            provinceList: [],
            cityList: [],
            countryForm: {
                father_id: 0,
            },
            provinceForm: {
                father_id: 0,
            },
            cityForm: {
                father_id: 0,
            },
            ifloading: {
                country: false,
                province: false,
                city: false,
            },
            countryRules: {
                cate_name: [
                    { required: true, message: '请输入国家名称', trigger: 'blur' }
                ],
                cate_code: [
                    { required: true, message: '请输入国家编码', trigger: 'blur' }
                ],
            },
            provinceRules: {
                cate_name: [
                    { required: true, message: '请输入省份名称', trigger: 'blur' }
                ],
                cate_code: [
                    { required: true, message: '请输入省份编码', trigger: 'blur' }
                ],
            },
            cityRules: {
                cate_name: [
                    { required: true, message: '请输入城市名称', trigger: 'blur' }
                ],
            },
 
        };
    },
    mounted() {
        this.getCountryList();
    },
    created() { },
    methods: {
        setProvince(index) {
            let that = this;
            that.currCountryId = that.countryList[index].id;
            that.currCountryIndex = index;
            that.provinceList = [];
            that.getProvinceList();
        },
        setCity(index) {
            let that = this;
            that.currProvinceId = that.provinceList[index].id;
            that.currProvinceIndex = index;
            that.cityList = [];
            that.getCityList();
        },
        countryCloseForm() {
            this.dialogVisible.country = false
            if (this.$refs['countryForm'] !== undefined) {
                this.$refs['countryForm'].resetFields()
            }
        },
        provinceCloseForm() {
            this.dialogVisible.province = false
            if (this.$refs['provinceForm'] !== undefined) {
                this.$refs['provinceForm'].resetFields()
            }
        },
        cityCloseForm() {
            this.dialogVisible.city = false
            if (this.$refs['cityForm'] !== undefined) {
                this.$refs['cityForm'].resetFields()
            }
        },
        createCountry(index) {
            if (index >= 0) {
                this.createCountryTitle = "编辑国家";
                this.countryForm = JSON.parse(JSON.stringify(this.countryList[index]));
                this.address = this.countryList[index];
            } else {
                this.createCountryTitle = "添加国家";
                this.countryForm = {
                    father_id: 0,
                }
            }
            this.dialogVisible.country = true;
 
        },
        createProvince(index) {
            if (index >= 0) {
                this.createProvinceTitle = "编辑省份(" + this.countryList[this.currCountryIndex].cate_name + ")";
                this.provinceForm = JSON.parse(JSON.stringify(this.provinceList[index]));
            } else {
                this.createProvinceTitle = "添加省份(" + this.countryList[this.currCountryIndex].cate_name + ")";
                this.provinceForm = {
                    father_id: this.currCountryId,
                }
            }
            this.dialogVisible.province = true;
 
        },
        createCity(index) {
            if (index >= 0) {
                this.createCityTitle = "编辑城市(" + this.countryList[this.currCountryIndex].cate_name + '/' + this.provinceList[this.currProvinceIndex].cate_name + ")";
                this.cityForm = JSON.parse(JSON.stringify(this.cityList[index]));
            } else {
                this.createCityTitle = "添加城市(" + this.countryList[this.currCountryIndex].cate_name + '/' + this.provinceList[this.currProvinceIndex].cate_name + ")";
                this.cityForm = {
                    father_id: this.currProvinceId,
                }
            }
            this.dialogVisible.city = true;
 
        },
        getCountryList() {
            let that = this;
            let url = "/admin/" + viewPath + "/getCountryCodeList.html"
            postRequest(url, that.countryData).then(res => {
                
                if (res.data.code == 200) {
                    that.countryList = res.data.list;
                    that.currCountryIndex = 0;
                    that.currCountryId = that.countryList[that.currCountryIndex].id;
                    if (that.ifloading.province == false) {
                        //第一次加载载入
                        that.getProvinceList();
                    }
                }
                else {
                    that.countryList = [];
                    //that.createCountry(-1);
                }
            });
        },
        getProvinceList() {
            let that = this;
            that.provinceData.father_id = that.currCountryId;
            let url = "/admin/" + viewPath + "/getCountryCodeList.html"
            postRequest(url, that.provinceData).then(res => {
                
                that.ifloading.province = true;
                if (res.data.code == 200) {
                    that.provinceList = res.data.list;
                    that.currProvinceIndex = 0;
                    that.currProvinceId = that.provinceList[that.currProvinceIndex].id;
                    // if (that.ifloading.city == false) {
                    //第一次加载载入
                    that.getCityList();
                    // }
                }
                else {
                    that.provinceList = [];
                    //that.createProvince(-1);
                }
            });
        },
        getCityList() {
            let that = this;
            that.cityData.father_id = that.currProvinceId;
            let url = "/admin/" + viewPath + "/getCountryCodeList.html"
            postRequest(url, that.cityData).then(res => {
                that.ifloading.city = true;
                if (res.data.code == 200) {
                    that.cityList = res.data.list;
                    that.currCityIndex = 0;
                    that.currCityId = that.cityList[that.currCityIndex].id;
                }
                else {
                    that.cityList = [];
                    that.currCityIndex = -1;
                    //that.createCity(-1);
                }
            });
        },
        updateShow(row) {
            var { id, status } = row;
            let url = "/admin/" + viewPath + "/updateShow.html"
            postRequest(url, { id: id, status: status }).then(res => {
                if (res.data.code != 200) {
                    row.status = status == 1 ? 0 : 1;//修改失败,恢复状态
                }
            });
        },
        /////保存国家信息/////
        saveCountry() {
            var that = this;
            that.$refs.countryForm.validate(valid => {
                if (valid) {
                    if (that.ifsubmit) {
                        return false;
                    }
                    that.ifsubmit = true;
                    let url = "/admin/" + viewPath + "/saveCountryCode.html";
                    postRequest(url, that.countryForm).then(res => {
                        if (res.data.code == 200) {
                            that.dialogVisible.country = false;
                            that.getCountryList();
                            that.$message({
                                message: res.data.message,
                                type: 'success',
                                duration: 1000,
                                center: true,
                                onClose: function () {
                                    that.ifsubmit = false;
 
                                }
                            });
                        }
                        else {
                            that.ifsubmit = false;
                            that.$message({
                                message: res.data.message,
                                type: 'error',
                                duration: 1500,
                                center: true
                            });
                        }
                    });
                }
            });
 
        },
        /////保存省份信息/////
        saveProvince() {
            var that = this;
            that.$refs.provinceForm.validate(valid => {
                if (valid) {
                    if (that.ifsubmit) {
                        return false;
                    }
                    that.ifsubmit = true;
                    let url = "/admin/" + viewPath + "/saveCountryCode.html";
                    postRequest(url, that.provinceForm).then(res => {
                        if (res.data.code == 200) {
                            that.dialogVisible.province = false;
                            that.getProvinceList();
                            that.$message({
                                message: res.data.message,
                                type: 'success',
                                duration: 1000,
                                center: true,
                                onClose: function () {
                                    that.ifsubmit = false;
 
                                }
                            });
                        }
                        else {
                            that.ifsubmit = false;
                            that.$message({
                                message: res.data.message,
                                type: 'error',
                                duration: 1500,
                                center: true
                            });
                        }
                    });
                }
            });
 
        },
        /////保存省份信息/////
        saveCity() {
            var that = this;
            
            that.$refs.cityForm.validate(valid => {
                if (valid) {
                    if (that.ifsubmit) {
                        return false;
                    }
                    that.ifsubmit = true;
                    let url = "/admin/" + viewPath + "/saveCityCode.html";
                    postRequest(url, that.cityForm).then(res => {
                        if (res.data.code == 200) {
                            that.dialogVisible.city = false;
                            that.getCityList();
                            that.$message({
                                message: res.data.message,
                                type: 'success',
                                duration: 1000,
                                center: true,
                                onClose: function () {
                                    that.ifsubmit = false;
 
                                }
                            });
                        }
                        else {
                            that.ifsubmit = false;
                            that.$message({
                                message: res.data.message,
                                type: 'error',
                                duration: 1500,
                                center: true
                            });
                        }
                    });
                }
            });
 
        },
 
    }
};
const app = Vue.createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus, {
    locale: ElementPlusLocaleZhCn,
});
app.mount("#vue_item");