169 lines
7.2 KiB
JavaScript
169 lines
7.2 KiB
JavaScript
/**
|
|
入驻小区
|
|
**/
|
|
(function (vc) {
|
|
var DEFAULT_PAGE = 1;
|
|
var DEFAULT_ROWS = 10;
|
|
vc.extends({
|
|
data: {
|
|
inspectionItemManageInfo: {
|
|
inspectionItems: [],
|
|
total: 0,
|
|
records: 1,
|
|
moreCondition: false,
|
|
itemId: '',
|
|
conditions: {
|
|
itemId: '',
|
|
itemName: '',
|
|
communityId: '',
|
|
},
|
|
importInspectionItemInfo: {
|
|
selectedFile: null
|
|
},
|
|
fileSelected: false
|
|
}
|
|
},
|
|
_initMethod: function () {
|
|
$that._listInspectionItems(DEFAULT_PAGE, DEFAULT_ROWS);
|
|
},
|
|
_initEvent: function () {
|
|
vc.on('inspectionItemManage', 'listInspectionItem', function (_param) {
|
|
$that._listInspectionItems(DEFAULT_PAGE, DEFAULT_ROWS);
|
|
});
|
|
vc.on('pagination', 'page_event', function (_currentPage) {
|
|
$that._listInspectionItems(_currentPage, DEFAULT_ROWS);
|
|
});
|
|
},
|
|
methods: {
|
|
_listInspectionItems: function (_page, _rows) {
|
|
$that.inspectionItemManageInfo.conditions.page = _page;
|
|
$that.inspectionItemManageInfo.conditions.row = _rows;
|
|
$that.inspectionItemManageInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
|
|
let param = {
|
|
params: $that.inspectionItemManageInfo.conditions
|
|
};
|
|
param.params.itemId = param.params.itemId.trim();
|
|
param.params.itemName = param.params.itemName.trim();
|
|
//发送get请求
|
|
vc.http.apiGet('/inspectionItem.listInspectionItem',
|
|
param,
|
|
function (json, res) {
|
|
let _json = JSON.parse(json);
|
|
$that.inspectionItemManageInfo.total = _json.total;
|
|
$that.inspectionItemManageInfo.records = _json.records;
|
|
$that.inspectionItemManageInfo.inspectionItems = _json.data;
|
|
vc.emit('pagination', 'init', {
|
|
total: $that.inspectionItemManageInfo.records,
|
|
dataCount: $that.inspectionItemManageInfo.total,
|
|
currentPage: _page
|
|
});
|
|
},
|
|
function (errInfo, error) {
|
|
console.log('请求失败处理');
|
|
}
|
|
);
|
|
},
|
|
_openAddInspectionItemModal: function () {
|
|
vc.emit('addInspectionItem', 'openAddInspectionItemModal', {});
|
|
},
|
|
_openEditInspectionItemModel: function (_inspectionItem) {
|
|
vc.emit('editInspectionItem', 'openEditInspectionItemModal', _inspectionItem);
|
|
},
|
|
_openDeleteInspectionItemModel: function (_inspectionItem) {
|
|
vc.emit('deleteInspectionItem', 'openDeleteInspectionItemModal', _inspectionItem);
|
|
},
|
|
//查询
|
|
_queryInspectionItemMethod: function () {
|
|
$that._listInspectionItems(DEFAULT_PAGE, DEFAULT_ROWS);
|
|
},
|
|
//重置
|
|
_resetInspectionItemMethod: function () {
|
|
$that.inspectionItemManageInfo.conditions.itemId = "";
|
|
$that.inspectionItemManageInfo.conditions.itemName = "";
|
|
$that._listInspectionItems(DEFAULT_PAGE, DEFAULT_ROWS);
|
|
},
|
|
_moreCondition: function () {
|
|
if ($that.inspectionItemManageInfo.moreCondition) {
|
|
$that.inspectionItemManageInfo.moreCondition = false;
|
|
} else {
|
|
$that.inspectionItemManageInfo.moreCondition = true;
|
|
}
|
|
},
|
|
_toTitle: function (_item) {
|
|
vc.jumpToPage('/#/pages/property/inspectionItemTitleManage?itemId=' + _item.itemId)
|
|
},
|
|
// 新增导入功能
|
|
_openImportInspectionItemModal: function () {
|
|
$that.clearImportInspectionItemInfo();
|
|
$('#importInspectionItemModel').modal('show');
|
|
},
|
|
// 文件选择处理
|
|
_onFileChange: function (event) {
|
|
var files = event.target.files;
|
|
if (files.length == 0) {
|
|
return;
|
|
}
|
|
var file = files[0];
|
|
// 验证文件类型
|
|
var fileName = file.name.toLowerCase();
|
|
if (!fileName.endsWith('.xlsx') && !fileName.endsWith('.xls')) {
|
|
vc.toast("请选择Excel文件(.xlsx或.xls格式)", 2000);
|
|
return;
|
|
}
|
|
$that.inspectionItemManageInfo.importInspectionItemInfo.selectedFile = file;
|
|
$that.fileSelected = true;
|
|
var labelElement = document.querySelector('label[for="importFile"]')
|
|
if(labelElement) {
|
|
labelElement.textContent = file.name;
|
|
}
|
|
},
|
|
// 执行导入
|
|
_importInspectionItem: function () {
|
|
var file = $that.inspectionItemManageInfo.importInspectionItemInfo.selectedFile;
|
|
if (!file) {
|
|
vc.toast("请选择要导入的文件", 2000);
|
|
return;
|
|
}
|
|
|
|
var formData = new FormData();
|
|
formData.append('uploadFile', file);
|
|
formData.append('communityId', vc.getCurrentCommunity().communityId);
|
|
formData.append('importAdapt', "importInspectionItem");
|
|
|
|
vc.http.upload(
|
|
'assetImport',
|
|
'importData',
|
|
formData, {
|
|
emulateJSON: true,
|
|
headers: {
|
|
"Content-Type": "multipart/form-data"
|
|
}
|
|
},
|
|
function (json, res) {
|
|
var _json = JSON.parse(json);
|
|
if (_json.code == 0) {
|
|
$('#importInspectionItemModel').modal('hide');
|
|
$that.clearImportInspectionItemInfo();
|
|
vc.toast("导入成功", 2000);
|
|
// 刷新页面数据
|
|
$that._listInspectionItems(DEFAULT_PAGE, DEFAULT_ROWS);
|
|
return;
|
|
} else {
|
|
vc.toast(_json.msg, 2000);
|
|
}
|
|
},
|
|
function (errInfo, error) {
|
|
console.log('请求失败处理');
|
|
vc.toast("导入失败,请稍后重试", 2000);
|
|
}
|
|
);
|
|
},
|
|
// 清除导入信息
|
|
clearImportInspectionItemInfo: function () {
|
|
$that.inspectionItemManageInfo.importInspectionItemInfo.selectedFile = null;
|
|
$that.fileSelected = false;
|
|
$('#importFile').val('');
|
|
}
|
|
}
|
|
});
|
|
})(window.vc); |