/** 入驻小区 **/ (function (vc) { var DEFAULT_PAGE = 1; var DEFAULT_ROWS = 1000; vc.extends({ data: { inspectionPointInfo: { points: [], point: {}, total: 0, records: 1, moreCondition: false, inspectionName: '', pointObjTypes: [], _currentTab: 'pointTaskDetail', conditions: { inspectionId: '', machineId: '', inspectionName: '', machineCode: '', pointObjType: '', iptId: '' } }, inspectionPointTypeInfo: { types: [], type: {}, total: 0, conditions: { iptId: '', name: '' } }, importInspectionPointInfo: { communityId: vc.getCurrentCommunity().communityId, excelTemplate: '' }, fileSelected: false }, _initMethod: function () { //与字典表关联 vc.getDict('inspection_point', "point_obj_type", function (_data) { $that.inspectionPointInfo.pointObjTypes = _data; }); $that._listInspectionPoints(DEFAULT_PAGE, DEFAULT_ROWS); $that._listInspectionPointTypes(DEFAULT_PAGE, DEFAULT_ROWS); }, _initEvent: function () { vc.on('inspectionPoint', 'listInspectionPoint', function (_param) { $that._listInspectionPoints(DEFAULT_PAGE, DEFAULT_ROWS); }); vc.on('inspectionPoint', 'refreshInspectionPointTypes', function (_param) { $that._listInspectionPointTypes(DEFAULT_PAGE, DEFAULT_ROWS); vc.emit('inspectionPointTypeTree', 'refreshTree', {}); }); vc.on('inspectionPoint', 'switchInspectionPointTypeTree', function (_param) { let _type = { iptId: _param.iptId, name: _param.name }; $that._switchInspectionPointType(_type); }); vc.on('inspectionPoint', 'switchInspectionPoint', function (_param) { $that._switchInspectionPoint(_param); }); vc.on('pagination', 'page_event', function (_currentPage) { $that._listInspectionPoints(_currentPage, DEFAULT_ROWS); $that._listInspectionPointTypes(_currentPage, DEFAULT_ROWS); }); }, methods: { _listInspectionPoints: function (_page, _rows) { $that.inspectionPointInfo.conditions.page = _page; $that.inspectionPointInfo.conditions.row = _rows; $that.inspectionPointInfo.conditions.communityId = vc.getCurrentCommunity().communityId; let param = { params: $that.inspectionPointInfo.conditions }; param.params.inspectionName = param.params.inspectionName.trim(); //发送get请求 vc.http.apiGet('/inspectionPoint.listInspectionPoints', param, function (json, res) { let _json = JSON.parse(json); $that.inspectionPointInfo.total = _json.total; $that.inspectionPointInfo.records = _json.records; $that.inspectionPointInfo.points = _json.inspectionPoints; if (_json.inspectionPoints && _json.inspectionPoints.length > 0) { $that._switchInspectionPoint(_json.inspectionPoints[0]); } // vc.emit('pagination', 'init', { // total: $that.inspectionPointInfo.records, // dataCount: $that.inspectionPointInfo.total, // currentPage: _page // }); }, function (errInfo, error) { console.log('请求失败处理'); } ); }, _listInspectionPointTypes: function (_page, _rows) { var $that = this; var param = { params: { page: _page, row: _rows, communityId: vc.getCurrentCommunity().communityId } }; vc.http.apiGet('/inspectionPointType.listInspectionPointTypes', param, function (json, res) { let _json = JSON.parse(json); $that.inspectionPointTypeInfo.types = _json.data.inspectionPointTypes; $that.inspectionPointInfo.total = _json.total; if (_json.data.inspectionPointTypes && _json.data.inspectionPointTypes.length > 0) { $that._switchInspectionPointType(_json.data.inspectionPointTypes[0]); } }, function (errInfo, error) { console.log('请求失败处理'); } ); }, _switchInspectionPointType: function (_type) { var $that = this; $that.inspectionPointTypeInfo.type = _type; $that.inspectionPointInfo.conditions.iptId = _type.iptId; $that._listInspectionPoints(DEFAULT_PAGE, DEFAULT_ROWS); }, _openAddInspectionPointModal: function () { vc.emit('addInspectionPoint', 'openAddInspectionPointModal', {}); }, _openAddInspectionPointTypeModal: function () { vc.emit('addInspectionPointType', 'openAddInspectionPointTypeModal', {}); }, _openEditInspectionPointTypeModel: function () { var $that = this; if (!$that.inspectionPointTypeInfo.type || !$that.inspectionPointTypeInfo.type.iptId) { vc.toast('请选择要修改的菜单'); return; } vc.emit('editInspectionPointType', 'openEditInspectionPointTypeModal', $that.inspectionPointTypeInfo.type); }, _openDeleteInspectionPointTypeModel: function () { var $that = this; if (!$that.inspectionPointTypeInfo.type || !$that.inspectionPointTypeInfo.type.iptId) { vc.toast('请选择要删除的菜单'); return; } vc.emit('deleteInspectionPointType', 'openDeleteInspectionPointTypeModal', $that.inspectionPointTypeInfo.type); }, _openImportInspectionPointModal: function () { var $that = this; $that.clearImportInspectionPointInfo(); $('#importInspectionPointModel').modal('show'); }, _openEditInspectionPointModel: function (_inspectionPoint) { vc.emit('editInspectionPoint', 'openEditInspectionPointModal', _inspectionPoint); }, _openDeleteInspectionPointModel: function (_inspectionPoint) { vc.emit('deleteInspectionPoint', 'openDeleteInspectionPointModal', _inspectionPoint); }, //查询 _queryInspectionPointMethod: function () { $that._listInspectionPoints(DEFAULT_PAGE, DEFAULT_ROWS); }, //重置 _switchInspectionPoint: function (_point) { $that.inspectionPointInfo.point = _point; $that.changeTab($that.inspectionPointInfo._currentTab); }, changeTab: function (_tab) { $that.inspectionPointInfo._currentTab = _tab; vc.emit(_tab, 'switch', $that.inspectionPointInfo.point); }, _moreCondition: function () { if ($that.inspectionPointInfo.moreCondition) { $that.inspectionPointInfo.moreCondition = false; } else { $that.inspectionPointInfo.moreCondition = true; } }, _pointQrCode: function (_inspectionPoint) { vc.emit('inspectionPointQrCode', 'openInspectionPointQrCodeModal', _inspectionPoint); }, _importData: function() { var $that = this; if (!$that.importInspectionPointValidate()) { vc.toast(vc.validate.errInfo); return; } var param = new FormData(); param.append("uploadFile", $that.importInspectionPointInfo.excelTemplate); param.append('communityId', $that.importInspectionPointInfo.communityId); param.append('importAdapt', "importInspectionPoint"); vc.http.upload( 'assetImport', 'importData', param, { emulateJSON: true, headers: { "Content-Type": "multipart/form-data" } }, function(json, res) { let _json = JSON.parse(json); if (_json.code == 0) { $('#importInspectionPointModel').modal('hide'); $that.clearImportInspectionPointInfo(); vc.toast("导入成功", 2000); // 刷新页面数据 $that._listInspectionPoints(1, 10, '', ''); vc.emit('inspectionPointTypeTree', 'refreshTree', {}); return; } vc.toast(_json.msg, 10000); }, function(errInfo, error) { console.log('请求失败处理'); vc.toast(errInfo, 10000); }); }, importInspectionPointValidate: function() { var $that = this; return vc.validate.validate({ importInspectionPointInfo: $that.importInspectionPointInfo }, { 'importInspectionPointInfo.communityId': [{ limit: "required", param: "", errInfo: "数据异常还没有入驻小区" }], 'importInspectionPointInfo.excelTemplate': [{ limit: "required", param: "", errInfo: "文件不能为空" }] }); }, clearImportInspectionPointInfo: function() { var $that = this; $that.importInspectionPointInfo = { communityId: vc.getCurrentCommunity().communityId, excelTemplate: '' }; $that.fileSelected = false; }, getExcelTemplate: function(e) { var $that = this; $that.importInspectionPointInfo.excelTemplate = e.target.files[0]; $that.fileSelected = true; if ($that.$forceUpdate) { $that.$forceUpdate(); } var labelElement = document.querySelector('label[for="excelTemplate"]'); if (labelElement) { labelElement.textContent = e.target.files[0].name; } } } }); })(window.vc);