| | |
| | | (function (vc) { |
| | | (function(vc) { |
| | | /** |
| | | * 导入合同组件 |
| | | * 功能:实现合同信息的导入功能,包括文件上传、验证、导入处理等 |
| | | */ |
| | | vc.extends({ |
| | | data: { |
| | | /** |
| | | * 导入合同信息 |
| | | * @property {string} communityId - 小区ID,从当前入驻小区获取 |
| | | * @property {File} excelTemplate - 上传的Excel文件 |
| | | */ |
| | | importContractInfo: { |
| | | communityId: vc.getCurrentCommunity().communityId, |
| | | excelTemplate: '', |
| | | feeTypeCd: '', |
| | | feeTypeCds: [], |
| | | objType: '3333' |
| | | excelTemplate: '' |
| | | } |
| | | }, |
| | | _initMethod: function() { |
| | | vc.getDict('pay_fee_config', "fee_type_cd", function(_data) { |
| | | $that.importContractInfo.feeTypeCds = _data; |
| | | /** |
| | | * 初始化方法 |
| | | */ |
| | | _initMethod: function() {}, |
| | | /** |
| | | * 初始化事件 |
| | | */ |
| | | _initEvent: function() { |
| | | /** |
| | | * 监听打开导入合同弹窗事件 |
| | | * @param {Object} _param - 事件参数 |
| | | */ |
| | | vc.on('importContract', 'openImportContractModal', function(_param) { |
| | | // 清空表单数据 |
| | | $that.clearImportContractInfo(); |
| | | // 显示导入弹窗 |
| | | $('#importContractModel').modal('show'); |
| | | }); |
| | | }, |
| | | _initEvent: function () { |
| | | vc.on('importContract', 'openimportContractModal', |
| | | function (_room) { |
| | | $('#importContractModel').modal('show'); |
| | | }); |
| | | }, |
| | | methods: { |
| | | /** |
| | | * 导入合同表单验证 |
| | | * @returns {boolean} 验证是否通过 |
| | | */ |
| | | importContractValidate() { |
| | | return vc.validate.validate({ |
| | | importContractInfo: $that.importContractInfo |
| | |
| | | param: "", |
| | | errInfo: "数据异常还没有入驻小区" |
| | | }], |
| | | 'importContractInfo.excelTemplate': [{ |
| | | limit: "required", |
| | | param: "", |
| | | errInfo: "文件不能为空" |
| | | }] |
| | | }); |
| | | }, |
| | | /** |
| | | * 导入合同数据 |
| | | */ |
| | | _importData: function() { |
| | | // 表单验证 |
| | | if (!$that.importContractValidate()) { |
| | | vc.toast(vc.validate.errInfo); |
| | | return; |
| | | } |
| | | // 导入数据 |
| | | |
| | | // 验证文件类型 |
| | | if (!$that.checkFileType($that.importContractInfo.excelTemplate.name.split('.')[1])) { |
| | | vc.toast('不是有效的Excel格式'); |
| | | return; |
| | | } |
| | | |
| | | // 验证文件大小 |
| | | if (!$that.checkFileSize($that.importContractInfo.excelTemplate.size)) { |
| | | vc.toast('Excel文件大小不能超过20M'); |
| | | return; |
| | | } |
| | | |
| | | // 构建请求参数 |
| | | var param = new FormData(); |
| | | param.append("uploadFile", $that.importContractInfo.excelTemplate); // 上传的Excel文件 |
| | | param.append('communityId', $that.importContractInfo.communityId); // 小区ID |
| | | param.append('importAdapt', "importContractV2"); // 导入适配器:importContractV2(sheet:广告合同汇总表) |
| | | param.append('userId', vc.getData('/userInfo/userId')); // 操作员工编号 |
| | | |
| | | let param = new FormData(); |
| | | param.append("uploadFile", $that.importContractInfo.excelTemplate); |
| | | param.append('communityId', vc.getCurrentCommunity().communityId); |
| | | param.append('userId', vc.getData('/nav/getUserInfo').userId) |
| | | param.append('importAdapt', "importContract"); |
| | | // 显示导入中提示 |
| | | vc.toast('正在导入中,请稍候...'); |
| | | |
| | | // 发送上传请求 |
| | | vc.http.upload( |
| | | 'assetImport', |
| | | 'importData', |
| | | param, { |
| | | 'assetImport', // 模块名 |
| | | 'importData', // 方法名 |
| | | param, // 参数 |
| | | { |
| | | emulateJSON: true, |
| | | //添加请求头 |
| | | headers: { |
| | | "Content-Type": "multipart/form-data" |
| | | } |
| | | }, |
| | | function (json, res) { |
| | | //vm.menus = vm.refreshMenuActive(JSON.parse(json),0); |
| | | /** |
| | | * 成功回调 |
| | | * @param {string} json - 响应数据 |
| | | * @param {Object} res - 响应对象 |
| | | */ |
| | | function(json, res) { |
| | | let _json = JSON.parse(json); |
| | | if (_json.code == 0) { |
| | | //关闭model |
| | | vc.toast("处理成功"); |
| | | // 关闭弹窗 |
| | | $('#importContractModel').modal('hide'); |
| | | vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=importContract'); |
| | | // 清空表单数据 |
| | | $that.clearImportContractInfo(); |
| | | // 跳转到导入日志详情页 |
| | | vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=importContractV2'); |
| | | return; |
| | | } |
| | | // 显示错误信息 |
| | | vc.toast(_json.msg, 10000); |
| | | }, |
| | | function (errInfo, error) { |
| | | /** |
| | | * 失败回调 |
| | | * @param {string} errInfo - 错误信息 |
| | | * @param {Object} error - 错误对象 |
| | | */ |
| | | function(errInfo, error) { |
| | | console.log('请求失败处理'); |
| | | vc.toast(errInfo, 10000); |
| | | }); |
| | | } |
| | | ); |
| | | }, |
| | | clearAddFeeConfigInfo: function() { |
| | | var _feeTypeCds = $that.importContractInfo.feeTypeCds; |
| | | /** |
| | | * 清空导入合同信息 |
| | | */ |
| | | clearImportContractInfo: function() { |
| | | $that.importContractInfo = { |
| | | communityId: vc.getCurrentCommunity().communityId, |
| | | excelTemplate: '', |
| | | feeTypeCd: '', |
| | | feeTypeCds: [], |
| | | objType: '3333' |
| | | excelTemplate: '' |
| | | }; |
| | | $that.importContractInfo.feeTypeCds = _feeTypeCds; |
| | | }, |
| | | _changeFeeTypeCd: function (_feeTypeCd) { |
| | | }, |
| | | getExcelTemplate: function (e) { |
| | | //console.log("getExcelTemplate 开始调用") |
| | | /** |
| | | * 获取Excel模板文件 |
| | | * @param {Event} e - 文件选择事件 |
| | | */ |
| | | getExcelTemplate: function(e) { |
| | | $that.importContractInfo.excelTemplate = e.target.files[0]; |
| | | }, |
| | | checkFileType: function (fileType) { |
| | | const acceptTypes = ['xlsx']; |
| | | /** |
| | | * 检查文件类型 |
| | | * @param {string} fileType - 文件类型 |
| | | * @returns {boolean} 是否为有效的Excel文件类型 |
| | | */ |
| | | checkFileType: function(fileType) { |
| | | const acceptTypes = ['xlsx', 'xls']; |
| | | for (var i = 0; i < acceptTypes.length; i++) { |
| | | if (fileType === acceptTypes[i]) { |
| | | return true; |
| | |
| | | } |
| | | return false; |
| | | }, |
| | | checkFileSize: function (fileSize) { |
| | | //2M |
| | | /** |
| | | * 检查文件大小 |
| | | * @param {number} fileSize - 文件大小(字节) |
| | | * @returns {boolean} 文件大小是否符合要求 |
| | | */ |
| | | checkFileSize: function(fileSize) { |
| | | // 20M |
| | | const MAX_SIZE = 20 * 1024 * 1024; |
| | | if (fileSize > MAX_SIZE) { |
| | | return false; |
| | |
| | | } |
| | | } |
| | | }); |
| | | })(window.vc); |
| | | })(window.vc); |