You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

459 lines
18 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

define(['../views/pages/xlswindow/import-window',
'../views/pages/printwindow/printwindow',
'../views/pages/multiprintwindow/multiprintwindow',
'../views/pages/printloader/printloader',
'../views/pages/progressbarwindow/progressbarwindow',
'../views/pages/xlswindow/export-util',],
function (XWindow, PrintWindow, MultiPrintWindow, PrintLoader, AccLoader, exportUtil) {
var utils = {
cancel: function (biz, ispop) {
var tip = biz.beforeCancel();
if (tip === false) return;
var content = Store.messager.confirm(tip, function (r) {
if (r) {
biz.setState('cancel');
var bRet = biz.dsMaster.rejectChanges(true);
biz.setState('browser');
return bRet;
}
});
if (!ispop)
content.parent().find('.messager-button a:eq(0)').trigger('click');
},
delete: function (biz) {
var tip = biz.beforeDelete();
if (tip === false) return;
var content = Store.messager.confirm(tip, function (r) {
if (r) {
biz.dsMaster.delete(function (isOk, dataSrc) {
if (isOk) {
biz.afterDelete();
}
});
}
});
content.parent().find('.messager-button a:eq(1)').focus();
},
refresh: function (biz) {
if (biz.beforeRefresh() == false) return;
biz.dsMaster.search(function (isOk, dataSrc) {
if (isOk) {
biz.afterRefresh();
}
}, {
reset: true
});
},
edit: function (biz) {
if (biz.beforeEdit() == false) return;
//是否需要刷新明细
var needLoadDetails = !biz.getShowDetail();
if (needLoadDetails) {
biz.loadDetails(function (isOk) {
if (isOk) {
biz.setState('edit');
biz.afterEdit();
}
});
} else {
biz.setState('edit');
biz.afterEdit();
}
},
add: function (biz) {
if (biz.beforeAdd() == false) return;
biz.setShowDetail(true);
biz.dsMaster.addRow();
biz.setState('add');
// biz.loadDetails();
biz.afterAdd();
},
save: function (biz) {
if (!biz.dsMaster.commitAndRemoveEmptyRow()) return;
if (biz.beforeSave() == false) return;
utils.updateBusValue(biz);
biz.dsMaster.save(function (isOk) {
if (isOk) {
//Store.services.writeLog({
// funcCode: biz.getFuncCode(),
// loglevelType: '1',
// logPosition: 'save',
// logContent: '保存成功',
// logMessage: '保存成功'
//});
biz.setState('browser');
biz.afterSave();
}
}, true);
},
prev: function (biz) {
biz.dsMaster.moveToPrev();
},
next: function (biz) {
biz.dsMaster.moveToNext();
},
importNoShowExcel: function (cb) {
var win = new XWindow({}, function (data) {
cb(data);
});
win.open();
},
importexcel: function (biz, ds) {
//校验数据
if (ds.currentRow) {
if (ds.validate(Store.messager.err) === false) {
return;
}
}
var win = new XWindow({}, function (data) {
(new ExcelHelper(biz, ds, data)).import();
// 处理返回的excel data数据这里的数据已经是数组包含了读取的所有数据.
});
win.open();
},
exportexcel: function (biz, ds) {
exportUtil.export(biz.getMenu().funcName + '.xlsx', ds)
},
exportexcelall: function (biz, ds) {
let postData = {
beforeProc: ds.beforeSearchProc,
afterProc: ds.afterSearchProc,
searchData: {},
serverBiz: ds.serverBiz,
sync: false
};
// 明细分页search条件支持
let schemaArgs = { nodata: true };
let parentRlt = ds.getParentRelation();
if (!ds.isMaster && parentRlt) {
schemaArgs = {
masterRow: parentRlt.master.currentRow
}
}
let schemaData = ds.getSchemaData(schemaArgs)
schemaData.pageSize = 0
postData.searchData[ds.uiObjCode] = schemaData
postData.fileName = ds.uiObjName + '.xlsx'
Store.services.export(postData)
},
printset: function (biz) {
var win = new PrintWindow({
data: {
funCode: biz.getFuncCode(),
dataSrc: biz.dsMaster,
biz: biz
}
});
win.open();
},
print: function (biz, args) {
if (biz.beforePrint(args) == false) return;
if (args) {
var printIndexs = [];
for (var i = 0; i < biz.dsMaster.rows.length; i++) {
if (biz.dsMaster.rows[i].$is_sel) {
printIndexs.push(biz.dsMaster.rows[i].$id);
}
}
if (printIndexs.length == 0) {
if (biz.dsMaster.currentRow) {
printIndexs.push(biz.dsMaster.currentRow.$id);
}
}
if (biz.getShowDetail()) {
printIndexs.length = 0;
if (biz.dsMaster.currentRow) {
printIndexs.push(biz.dsMaster.currentRow.$id);
}
}
if (printIndexs.length == 0) {
Store.messager.tip(Store.MSG.PRINT_NO_DATA);
return;
}
var printid = args.serialNo;
if (!printid) {
Store.messager.tip('未指定默认打印格式,请设置后重试');
return
}
var win = new PrintLoader({
serialNo: printid,
data: biz.dsMaster,
biz: biz,
selectedRows: printIndexs,
callback: function () {
biz.afterPrint(printid);
}
});
win.open();
}
},
multiprint: function (biz, args) {
var win = new MultiPrintWindow({
data: biz.dsMaster,
biz: biz,
uiObjCode: biz.dsMaster.uiObjCode,
funcCode: biz.dsMaster.funcCode,
callback: function () {
}
});
win.open();
},
getOpEnabled: function (biz, opCode) {
var bRet = true;
var curRow = biz.dsMaster.currentRow;
var rows = biz.dsMaster.rows;
switch (opCode) {
case 'add':
bRet = biz.isBrowser();
break;
case 'edit':
bRet = biz.isBrowser() && curRow;
break;
case 'delete':
bRet = biz.isBrowser() && curRow;
break;
case 'cancel':
case 'save':
bRet = biz.isEdit();
break;
case 'list':
bRet = biz.callView('isDetail') && biz.isBrowser();
break;
case 'detail':
case 'child':
bRet = biz.callView('isList') && biz.isBrowser() && curRow;
break;
case 'prev':
bRet = !biz.isEdit() && curRow && rows.indexOf(curRow) > 0;
break;
case 'next':
bRet = !biz.isEdit() && curRow && rows.indexOf(curRow) < rows.length - 1;
break;
case 'refresh':
bRet = !biz.isEdit();
break;
case 'view':
bRet = !biz.isEdit() && (curRow || biz.callView('isDetail'));
break;
case 'print':
bRet = biz.isBrowser() && curRow;
break;
}
return bRet;
},
updateBusValue: function (biz) {
var curRow = biz.dsMaster.currentRow;
if (curRow) {
//检查是否需要生产BillNo
var billNoFieldName = biz.getBillNoFieldName();
if (billNoFieldName) {
if (curRow.hasOwnProperty(billNoFieldName)) {
var value = curRow[billNoFieldName];
if (value == "*") {
curRow.setColumnText(billNoFieldName, biz.getBillNo());
}
} else {
console.log(biz.dsMaster.uiObjName + '不存在单据列' + billNoFieldName);
}
}
//同步主从键、主从从键
var rs = biz.dsMaster.getDetailRelations();
for (var i = 0; i < rs.length; i++) {
var r = rs[i];
r.updateRelationValue(curRow);
var rrs = r.detail.getDetailRelations();
for (var j = 0; j < rrs.length; j++) {
var rr = rrs[j];
if (rr.master.currentRow) {
rr.updateRelationValue(rr.master.currentRow);
}
}
}
}
},
acc: function (biz, callback) {
if (biz.beforeAcc() == false) return;
var content = Store.messager.confirm(Store.MSG.ACC_CONFIRM, function (r) {
if (r) {
var billNoFieldName = biz.getBillNoFieldName(),
bills = biz.dsMaster.getSelectedRows(),
passNum = 0,
failNum = 0, bizType = '*';
if (biz.view && biz.view.node) {
bizType = biz.view.node.bizType;
}
//单条
if (bills.length == 0) {
var row = biz.dsMaster.currentRow;
Store.bizDao.acc(biz.dsMaster.uiObjCode, row[billNoFieldName], bizType, function (isOk, data) {
var isPass = isOk && data && data.result == '1';
if (isPass) {
Store.messager.tip(data ? data.message : Store.MSG.ACC_SUCCESS);
//更新数据
biz.dsMaster.updateRow();
} else {
Store.messager.err(data ? data.message : Store.MSG.ACC_NO_MESSAGE);
}
biz.afterAcc(isPass, data);
});
return;
}
//批量
var loader = new AccLoader({
data: bills,
iterator: function (item, success, error) {
Store.bizDao.acc(biz.dsMaster.uiObjCode, item[billNoFieldName], bizType, function (isOk, data) {
//判断成功失败
var isPass = isOk && data && data.result == '1';
if (isPass) {
passNum++;
} else {
failNum++;
console.log(data);
//if (error) {
// error();
//} else {
// console.log('iterator errorback not found');
//}
}
//更新数据
biz.dsMaster.updateRow(item);
//继续记账
if (success) {
success();
} else {
console.log('iterator successback not found');
}
});
},
completed: function () {
if (bills.length == (passNum + failNum)) {
Store.messager.tip(Store.format(Store.MSG.ACC_BATCH_TIP, passNum, failNum));
} else {
Store.messager.tip(Store.MSG.ACC_BATCH_BREAK);
}
biz.afterAcc(failNum == 0);
}
});
loader.open();
}
});
content.parent().find('.messager-button a:eq(1)').focus();
}
};
function accOneBill(biz, row, callback) {
}
function ExcelHelper(biz, ds, data) {
var curIndex = 0;
var excelCols = [];
var biz = biz;
var ds = ds;
var data = data;
this.import = function () {
var firstRow = data[0];
for (var j = 0; j < ds.columns.length; j++) {
var col = ds.columns[j];
if (col.dataType == Store.Enums.DataType.NUMBER) {
var flag = checkNumberCol(col);
if (!flag) {
Store.messager.err('导入数据中的' + col.fieldName + '列数据小数点位数与字典设置不符,不能导入,请修改字典设置或修改数据。')
return;
}
}
if (col.isEditable && firstRow.hasOwnProperty(col.dispName)) {
var excelCol = {
name: col.fieldName,
caption: col.dispName
};
excelCols.push(excelCol);
}
}
loadExcelData();
};
function checkNumberCol(col) {
for (var i = 0; i < data.length; i++) {
var numData = data[i].toString().split('.');
if (numData[1] && numData[1].length > col.dispScale) {
return false;
}
}
return true;
}
function loadExcelData() {
for (var i = curIndex; i < data.length; i++) {
curIndex++;
var row = data[i];
var dr = ds.newRow();
biz.afterNewRow(ds, dr);
dr.beginUpdate();
try {
for (var j = 0; j < excelCols.length; j++) {
dr.setColumnText(excelCols[j].name, row[excelCols[j].caption]);
if (dr.hasError()) {
goOn(dr.getColumnError(excelCols[j].name));
return;
}
}
} finally {
dr.endUpdate();
}
if (!dr.validate(goOn)) {
return;
}
ds.addRow(dr);
setTimeout(loadExcelData, 10);
return;
}
}
function goOn(msg) {
var msg = '文档导入时发生错误:<br>' + msg + '是否继续?';
if (Store.messager) {
Store.messager.confirm(msg, function (r) {
if (r) {
loadExcelData();
}
})
}
}
}
return utils;
})