zhangjiaqing
8 天以前 1cef3adee31c6934c0da4b4f0b8a6f5ac03b364f
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
/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            applyRoomDiscountManageInfo: {
                applyRoomDiscounts: [],
                applyTypes: [],
                total: 0,
                records: 1,
                moreCondition: false,
                ardId: '',
                states: [],
                conditions: {
                    roomName: '',
                    applyType: '',
                    state: '',
                    communityId: ''
                }
            }
        },
        _initMethod: function () {
            // 确保组件实例存在
            if (!vc.component) {
                console.error('组件实例不存在,延迟初始化');
                // 延迟执行初始化操作
                setTimeout(function() {
                    if (vc.component) {
                        vc.component._initMethod();
                    }
                }, 100);
                return;
            }
            
            vc.getDict('apply_room_discount', "state", function (_data) {
                if (vc.component && vc.component.applyRoomDiscountManageInfo) {
                    // 确保states是一个数组
                    if (_data && _data.data && Array.isArray(_data.data)) {
                        vc.component.applyRoomDiscountManageInfo.states = _data.data;
                    } else if (Array.isArray(_data)) {
                        vc.component.applyRoomDiscountManageInfo.states = _data;
                    } else {
                        vc.component.applyRoomDiscountManageInfo.states = [];
                    }
                }
            });
            
            if (typeof vc.component._listApplyRoomDiscounts === 'function') {
                vc.component._listApplyRoomDiscounts(DEFAULT_PAGE, DEFAULT_ROWS);
            }
            
            if (typeof vc.component._listApplyRoomDiscountTypes === 'function') {
                vc.component._listApplyRoomDiscountTypes();
            }
        },
        _initEvent: function () {
            vc.on('applyRoomDiscountManage', 'listApplyRoomDiscount', function (_param) {
                if (vc.component && typeof vc.component._listApplyRoomDiscounts === 'function') {
                    vc.component._listApplyRoomDiscounts(DEFAULT_PAGE, DEFAULT_ROWS);
                }
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                if (vc.component && typeof vc.component._listApplyRoomDiscounts === 'function') {
                    vc.component._listApplyRoomDiscounts(_currentPage, DEFAULT_ROWS);
                }
            });
        },
        methods: {
            _listApplyRoomDiscounts: function (_page, _rows) {
                if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                    console.error('组件实例不存在');
                    return;
                }
                
                // 验证社区信息是否存在
                let currentCommunity = vc.getCurrentCommunity();
                if (!currentCommunity || !currentCommunity.communityId) {
                    console.error('社区信息不存在');
                    return;
                }
                
                vc.component.applyRoomDiscountManageInfo.conditions.page = _page;
                vc.component.applyRoomDiscountManageInfo.conditions.row = _rows;
                // 小区id
                vc.component.applyRoomDiscountManageInfo.conditions.communityId = currentCommunity.communityId;
                var param = {
                    params: vc.component.applyRoomDiscountManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/applyRoomDiscount/queryApplyRoomDiscount',
                    param,
                    function (json, res) {
                        if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                            console.error('组件实例不存在');
                            return;
                        }
                        
                        try {
                            let _json = JSON.parse(json);
                            vc.component.applyRoomDiscountManageInfo.total = _json.total;
                            vc.component.applyRoomDiscountManageInfo.records = _json.records;
                            vc.component.applyRoomDiscountManageInfo.applyRoomDiscounts = _json.data || [];
                            vc.emit('pagination', 'init', {
                                total: vc.component.applyRoomDiscountManageInfo.records,
                                dataCount: vc.component.applyRoomDiscountManageInfo.total,
                                currentPage: _page
                            });
                        } catch (e) {
                            console.error('处理API响应失败:', e);
                            if (vc.component && vc.component.applyRoomDiscountManageInfo) {
                                vc.component.applyRoomDiscountManageInfo.applyRoomDiscounts = [];
                            }
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        if (vc.component && vc.component.applyRoomDiscountManageInfo) {
                            vc.component.applyRoomDiscountManageInfo.applyRoomDiscounts = [];
                        }
                    }
                );
            },
            _openAddApplyRoomDiscountModal: function () {
                vc.emit('addApplyRoomDiscount', 'openAddApplyRoomDiscountModal', {});
            },
            //验房
            _openEditApplyRoomDiscountModel: function (_applyRoomDiscount) {
                _applyRoomDiscount = JSON.stringify(_applyRoomDiscount);
                vc.emit('editApplyRoomDiscount', 'openEditApplyRoomDiscountModal', _applyRoomDiscount);
            },
            //跟踪记录
            _openApplyRoomDiscountRecord: function (_applyRoomDiscount) {
                vc.jumpToPage('/#/pages/property/listApplyRoomDiscountRecord?ardId=' + _applyRoomDiscount.ardId +
                    '&roomId=' + _applyRoomDiscount.roomId + '&roomName=' + _applyRoomDiscount.roomName +
                    '&state=' + _applyRoomDiscount.state + '&stateName=' + _applyRoomDiscount.stateName);
            },
            //审核
            _openReviewApplyRoomDiscountModel: function (_applyRoomDiscount) {
                _applyRoomDiscount = JSON.stringify(_applyRoomDiscount);
                vc.emit('reviewApplyRoomDiscount', 'openReviewApplyRoomDiscountModal', _applyRoomDiscount);
            },
            //删除
            _openDeleteApplyRoomDiscountModel: function (_applyRoomDiscount) {
                vc.emit('deleteApplyRoomDiscount', 'openDeleteApplyRoomDiscountModal', _applyRoomDiscount);
            },
            //修改
            _openEditApplyRoomDiscountRecordModel: function (_applyRoomDiscount) {
                vc.emit('editApplyRoomDiscountRecord', 'openEditApplyRoomDiscountRecordModal', _applyRoomDiscount);
            },
            //查询
            _queryApplyRoomDiscountMethod: function () {
                if (vc.component && typeof vc.component._listApplyRoomDiscounts === 'function') {
                    vc.component._listApplyRoomDiscounts(DEFAULT_PAGE, DEFAULT_ROWS);
                }
            },
            //重置
            _resetApplyRoomDiscountMethod: function () {
                if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                    console.error('组件实例不存在');
                    return;
                }
                vc.component.applyRoomDiscountManageInfo.conditions.roomName = "";
                vc.component.applyRoomDiscountManageInfo.conditions.applyType = "";
                vc.component.applyRoomDiscountManageInfo.conditions.state = "";
                if (typeof vc.component._listApplyRoomDiscounts === 'function') {
                    vc.component._listApplyRoomDiscounts(DEFAULT_PAGE, DEFAULT_ROWS);
                }
            },
            _listApplyRoomDiscountTypes: function () {
                if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                    console.error('组件实例不存在');
                    return;
                }
                
                // 验证社区信息是否存在
                let currentCommunity = vc.getCurrentCommunity();
                if (!currentCommunity || !currentCommunity.communityId) {
                    console.error('社区信息不存在');
                    return;
                }
                
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        communityId: currentCommunity.communityId
                    }
                };
                //发送get请求
                vc.http.apiGet('/applyRoomDiscount/queryApplyRoomDiscountType',
                    param,
                    function (json, res) {
                        if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                            console.error('组件实例不存在');
                            return;
                        }
                        
                        try {
                            let _json = JSON.parse(json);
                            vc.component.applyRoomDiscountManageInfo.applyTypes = _json.data && Array.isArray(_json.data) ? _json.data : [];
                        } catch (e) {
                            console.error('处理API响应失败:', e);
                            if (vc.component && vc.component.applyRoomDiscountManageInfo) {
                                vc.component.applyRoomDiscountManageInfo.applyTypes = [];
                            }
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        if (vc.component && vc.component.applyRoomDiscountManageInfo) {
                            vc.component.applyRoomDiscountManageInfo.applyTypes = [];
                        }
                    }
                );
            },
            //导出
            _exportApplyRoomDiscountModal: function () {
                if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                    console.error('组件实例不存在');
                    return;
                }
                
                // 验证社区信息是否存在
                let currentCommunity = vc.getCurrentCommunity();
                if (!currentCommunity || !currentCommunity.communityId) {
                    console.error('社区信息不存在');
                    return;
                }
                
                vc.component.applyRoomDiscountManageInfo.conditions.communityId = currentCommunity.communityId;
                vc.component.applyRoomDiscountManageInfo.conditions.pagePath = 'applyRoomDiscount';
                let param = {
                    params: vc.component.applyRoomDiscountManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/export.exportData', param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.toast(_json.msg);
                        if (_json.code == 0) {
                            vc.jumpToPage('/#/pages/property/downloadTempFile?tab=下载中心')
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    });
            },
            _moreCondition: function () {
                if (!vc.component || !vc.component.applyRoomDiscountManageInfo) {
                    console.error('组件实例不存在');
                    return;
                }
                if (vc.component.applyRoomDiscountManageInfo.moreCondition) {
                    vc.component.applyRoomDiscountManageInfo.moreCondition = false;
                } else {
                    vc.component.applyRoomDiscountManageInfo.moreCondition = true;
                }
            },
            _openDiscountType:function(){
                vc.jumpToPage('/#/pages/fee/discountType?tab=优惠类型');
            }
        }
    });
})(window.vc);