/**
|
入驻小区
|
**/
|
(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);
|