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
/**
 权限组
 **/
(function (vc) {
    vc.extends({
        data: {
            historyFeeDetailImportInfo: {
                communityId: vc.getCurrentCommunity().communityId,
                excelTemplate: '',
                objType: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
        },
        methods: {
            historyFeeDetailImportValidate: function () {
                return vc.validate.validate({
                    historyFeeDetailImportInfo: $that.historyFeeDetailImportInfo
                }, {
 
                    'historyFeeDetailImportInfo.excelTemplate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "文件不能为空"
                        }
                    ],
                    'historyFeeDetailImportInfo.communityId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "还未入驻小区,请先入驻小区"
                        }
                    ]
                });
            },
            _openDownloadHcExcelTemplate: function () {
                //下载 模板
                vc.jumpToPage('/import/importFeeDetail.xlsx')
            },
            _openDownloadHcCarExcelTemplate: function () {
                //下载 模板
                vc.jumpToPage('/import/importCarFeeDetail.xlsx')
            },
            getExcelTemplate: function (e) {
                //console.log("getExcelTemplate 开始调用")
                $that.historyFeeDetailImportInfo.excelTemplate = e.target.files[0];
            },
            _importData: function() {
                if (!$that.historyFeeDetailImportValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                // 导入数据
                if (!$that.checkFileType($that.historyFeeDetailImportInfo.excelTemplate.name.split('.')[1])) {
                    vc.toast('不是有效的Excel格式');
                    return;
                }
                // 移除文件大小限制检查
                // if (!$that.checkFileSize($that.historyFeeDetailImportInfo.excelTemplate.size)) {
                //     vc.toast('Excel文件大小不能超过20M');
                //     return;
                // }
                var param = new FormData();
                param.append("uploadFile", $that.historyFeeDetailImportInfo.excelTemplate);
                param.append('communityId', $that.historyFeeDetailImportInfo.communityId);
                param.append('objType', $that.historyFeeDetailImportInfo.objType);
                let _importAdapt = 'importRoomHistoryFeeDetail';
                if ($that.historyFeeDetailImportInfo.objType == '6666') {
                    _importAdapt = 'importCarHistoryFeeDetail';
                }
                param.append('importAdapt', _importAdapt);
                vc.http.upload(
                    'assetImport',
                    'importData',
                    param, {
                        emulateJSON: true,
                        //添加请求头
                        headers: {
                            "Content-Type": "multipart/form-data"
                        }
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast("处理成功");
                            $that.historyFeeDetailImportInfo.excelTemplate = '';
                            vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=' + _importAdapt);
 
                            return;
                        }
                        vc.toast(_json.msg, 10000);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo, 10000);
                    });
            },
            checkFileType: function (fileType) {
                const acceptTypes = ['xls', 'xlsx'];
                for (var i = 0; i < acceptTypes.length; i++) {
                    if (fileType === acceptTypes[i]) {
                        return true;
                    }
                }
                return false;
            },
            checkFileSize: function (fileSize) {
                //2M
                const MAX_SIZE = 20 * 1024 * 1024;
                if (fileSize > MAX_SIZE) {
                    return false;
                }
                return true;
            }
        }
    });
})(window.vc);