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
| (function (vc) {
| vc.extends({
| data: {
| editAdvertisementInfo: {
| id: '',
| advertsName: '',
| position: '',
| url: '',
| picUrl: '',
| ossUrl: '',
| sort: '',
| supplierName: '',
| desc: '',
| }
| },
| _initEvent: function () {
| vc.on('editAdvertisement', 'openEditAdvertisementModal', function (_params) {
| vc.component.refreshEditAdvertisementInfo();
| // 确保模态框能正常打开
| $('#editAdvertisementModel').modal('show').on('hidden.bs.modal', function () {
| // 模态框完全关闭后的清理工作
| });
| vc.copyObject(_params, vc.component.editAdvertisementInfo);
| if (_params.picUrl) {
| vc.emit('editAdvertisement', 'uploadImageUrl', 'notifyPhotos', [_params.picUrl]);
| }
| });
|
| vc.on("editAdvertisement", "notifyUploadImage", function (_param) {
| vc.component.editAdvertisementInfo.picUrl = _param.length > 0 ? _param[0].fileId : '';
| vc.component.addAdvertisementInfo.ossUrl = _param.length > 0 ? _param[0].url : '';
| });
|
| },
| methods: {
| validateAdvertisement: function () {
| return vc.validate.validate({
| editAdvertisementInfo: vc.component.editAdvertisementInfo
| }, {
| 'editAdvertisementInfo.advertsName': [{
| limit: "required",
| errInfo: "广告名称不能为空"
| },
| {
| limit: "maxLength",
| param: "50",
| errInfo: "广告名称不能超过50个字符"
| }
| ],
| 'editAdvertisementInfo.position': [{
| limit: "required",
| errInfo: "广告位不能为空"
| },
| {
| limit: "maxLength",
| param: "50",
| errInfo: "广告位不能超过50个字符"
| }
| ],
| 'editAdvertisementInfo.sort': [{
| limit: "required",
| errInfo: "排序不能为空"
| },
| {
| limit: "number",
| errInfo: "排序必须为数字"
| }
| ]
| });
| },
| updateAdvertisement: function () {
| if (!vc.component.validateAdvertisement()) {
| vc.toast(vc.validate.errInfo);
| return;
| }
|
| vc.http.apiPost('/smallProgram.updateAdverts',
| JSON.stringify(vc.component.editAdvertisementInfo), {
| emulateJSON: true
| },
| function (json) {
| try {
| let response = typeof json === 'string' ? JSON.parse(json) : json;
| console.log('API Response:', response);
|
| if (response.code === 0) {
| // 确保先关闭模态框再触发其他事件
| $('#editAdvertisementModel').modal('hide');
|
| // 延迟触发列表刷新,确保模态框完全关闭
| setTimeout(() => {
| vc.emit('communityManage', 'listCommunity', {});
| }, 300);
|
| vc.toast("修改成功");
| } else {
| vc.toast(response.msg || "操作失败");
| }
| } catch (e) {
| console.error('JSON解析错误:', e);
| vc.toast("数据处理错误");
| }
| },
| function (errInfo) {
| vc.toast(errInfo || "请求失败");
| }
| );
| },
|
| refreshEditAdvertisementInfo: function () {
| vc.component.editAdvertisementInfo = {
| id: '',
| advertsName: '',
| position: '',
| url: '',
| picUrl: '',
| ossUrl: '',
| sort: '',
| supplierName: '',
| desc: '',
| // status: 1
| };
| }
| }
| });
| })(window.vc);
|
|