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
/** 
  入驻小区 
  **/ 
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROW = 10;
    vc.extends({
        data: {
            parkingSpaceUnits: [],
            carCreateFeeInfo: {
                cars: [],
                states: [],
                total: 0,
                records: 1,
                floorId: '',
                unitId: '',
                state: '',
                num: '',
                moreCondition: false,
                excelFile: '',
                excelFileData: null, // 存储文件的二进制数据
                importAdapt: 'importOwnerCarV2',
                conditions: {
                    psId: '',
                    ownerName: '',
                    carNum: '',
                    carNumLike: '',
                    allNum: '',
                    state: '',
                    carTypeCd: '1001'
                }
            }
        },
        _initMethod: function () {
            $that.listCars(DEFAULT_PAGE, DEFAULT_ROW);
            vc.getDict('owner_car', 'state', function (_data) {
                $that.carCreateFeeInfo.states = _data;
            });
        },
        _initEvent: function () {
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that.listCars(_currentPage, DEFAULT_ROW);
            });
        },
        methods: {
            listCars: function (_page, _row) {
                $that.carCreateFeeInfo.conditions.page = _page;
                $that.carCreateFeeInfo.conditions.row = _row;
                $that.carCreateFeeInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                let _allNum = $that.carCreateFeeInfo.conditions.allNum.trim();
                let _conditions = JSON.parse(JSON.stringify($that.carCreateFeeInfo.conditions));
                let param = {
                    params: _conditions
                };
                if (_allNum.split('-').length == 2) {
                    let _allNums = _allNum.split('-');
                    param.params.areaNum = _allNums[0];
                    param.params.num = _allNums[1];
                }
                //发送get请求
                vc.http.apiGet('/owner.queryOwnerCars',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.carCreateFeeInfo.total = _json.total;
                        $that.carCreateFeeInfo.records = _json.records;
                        $that.carCreateFeeInfo.cars = _json.data;
                        // 计算总页数
                        var totalPages = Math.ceil(_json.total / _rows) || 1;
                        vc.emit('pagination', 'init', {
                            total: totalPages,
                            dataCount: $that.carCreateFeeInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openCarCreateFeeAddModal: function (_car, _isMore) {
                vc.emit('carCreateFeeAdd', 'openCarCreateFeeAddModal', {
                    isMore: _isMore,
                    car: _car
                });
            },
            _openViewParkingSpaceCreateFee: function (_car) {
                vc.jumpToPage("/#/pages/property/listCarFee?carId=" + _car.carId + "&carNum=" + _car.carNum + "&areaNum=" + _car.areaNum + "&num=" + _car.num);
            },
            _toBuyCarMonthCard: function () {
                vc.jumpToPage("/#/pages/fee/buyCarMonthCard");
            },
            //查询
            _queryParkingSpaceMethod: function () {
                $that.listCars(DEFAULT_PAGE, DEFAULT_ROW);
            },
            //重置
            _resetParkingSpaceMethod: function () {
                $that.carCreateFeeInfo.conditions.psId = "";
                $that.carCreateFeeInfo.conditions.ownerName = "";
                $that.carCreateFeeInfo.conditions.carNum = "";
                $that.carCreateFeeInfo.conditions.carNumLike = "";
                $that.carCreateFeeInfo.conditions.allNum = "";
                $that.carCreateFeeInfo.conditions.state = "";
                $that.listCars(DEFAULT_PAGE, DEFAULT_ROW);
            },
            _moreCondition: function () {
                if ($that.carCreateFeeInfo.moreCondition) {
                    $that.carCreateFeeInfo.moreCondition = false;
                } else {
                    $that.carCreateFeeInfo.moreCondition = true;
                }
            },
            _openFeeImportExcel: function () {
                vc.emit('exportCarFeeImportExcel', 'openExportCarFeeImportExcelModal', {})
            },
            _openDoCreateRoomFee: function () {
                vc.emit('doImportCreateFee', 'openDoImportCreateFeeModal', {})
            },
            // 获取导入文件
            getCarExcelFile: function (e) {
                $that.carCreateFeeInfo.excelFile = e.target.files[0];
                // 读取文件内容到内存,避免文件被修改时上传失败
                if ($that.carCreateFeeInfo.excelFile) {
                    var reader = new FileReader();
                    reader.onload = function(e) {
                        // 将文件内容存储为Blob对象
                        $that.carCreateFeeInfo.excelFileData = new Blob([e.target.result], {
                            type: $that.carCreateFeeInfo.excelFile.type
                        });
                    };
                    reader.readAsArrayBuffer($that.carCreateFeeInfo.excelFile);
                }
            },
            // 导入车辆数据
            _importCarDataSubmit: function () {
                if (!$that.carCreateFeeInfo.excelFile || $that.carCreateFeeInfo.excelFile === '') {
                    vc.toast('请选择导入文件');
                    return;
                }
                if (!$that.checkCarFileType($that.carCreateFeeInfo.excelFile.name.split('.')[1])) {
                    vc.toast('不是有效的Excel格式');
                    return;
                }
                // 移除文件大小限制检查
                // if (!$that.checkCarFileSize($that.carCreateFeeInfo.excelFile.size)) {
                //     vc.toast('Excel文件大小不能超过20M');
                //     return;
                // }
                var param = new FormData();
                // 使用内存中的文件数据,避免文件被修改时上传失败
                if ($that.carCreateFeeInfo.excelFileData) {
                    // 创建一个新的File对象,使用内存中的数据和原始文件的名称
                    var file = new File([$that.carCreateFeeInfo.excelFileData], $that.carCreateFeeInfo.excelFile.name, {
                        type: $that.carCreateFeeInfo.excelFile.type
                    });
                    param.append('uploadFile', file);
                } else {
                    param.append('uploadFile', $that.carCreateFeeInfo.excelFile);
                }
                param.append('communityId', vc.getCurrentCommunity().communityId);
                param.append('importAdapt', $that.carCreateFeeInfo.importAdapt);
                let userInfo = vc.getData('/nav/getUserInfo');
                param.append('userId', userInfo ? userInfo.userId : '');
                param.append('userName', userInfo ? userInfo.name : '');
                vc.toast('正在导入中,请稍候...');
                vc.http.upload(
                    'assetImport',
                    'importData',
                    param, {
                        emulateJSON: true,
                        headers: {
                            "Content-Type": "multipart/form-data"
                        }
                    },
                    function (json, res) {
                        var _json = JSON.parse(json);
                        if (_json.code == 0) {
                            $('#importCarDataModal').modal('hide');
                            vc.toast('导入成功');
                            vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=' + $that.carCreateFeeInfo.importAdapt);
                            $that.carCreateFeeInfo.excelFile = '';
                            $that.carCreateFeeInfo.excelFileData = null;
                            $('#carExcelFile').val('');
                        } else {
                            vc.toast(_json.msg, 10000);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast('导入失败:' + errInfo, 10000);
                    }
                );
            },
            // 检查文件类型
            checkCarFileType: function (fileType) {
                var acceptTypes = ['xlsx', 'xls'];
                for (var i = 0; i < acceptTypes.length; i++) {
                    if (fileType === acceptTypes[i]) {
                        return true;
                    }
                }
                return false;
            },
            // 检查文件大小
            checkCarFileSize: function (fileSize) {
                var MAX_SIZE = 20 * 1024 * 1024;
                return fileSize <= MAX_SIZE;
            },
            // 切换车辆类型
            swatchCarTypeCd: function (carTypeCd) {
                $that.carCreateFeeInfo.conditions.carTypeCd = carTypeCd;
                $that.listCars(DEFAULT_PAGE, DEFAULT_ROW);
            },
            // 按类型导入车辆数据
            _importCarDataByType: function (carTypeCd) {
                if (carTypeCd === '1001' || carTypeCd === '1002') {
                    $that.carCreateFeeInfo.importAdapt = 'importOwnerCar';
                } else if (carTypeCd === '1003') {
                    $that.carCreateFeeInfo.importAdapt = 'importCarInout';
                }
                $('#importCarDataModal').modal('show');
            }
        }
    });
})(window.vc);