'use strict';
/**
* 变更令详细页js
*
* @author EllisRan.
* @date 2018/11/22
* @version
*/
const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + ' ledger-Select';
const ckChangeSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + 'change-Select';
const is_numeric = (value) => {
if (typeof(value) === 'object') {
return false;
} else {
return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
}
};
function sortByCode(a, b) {
let code1 = a.code.split('-');
let code2 = b.code.split('-');
let code1length = code1.length;
let code2length = code2.length;
for (let i = 0; i < code1length; i ++) {
if (i+1 <= code2length) {
if (code1[i] != code2[i]) {
if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
return parseInt(code1[i]) - parseInt(code2[i]);
} else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
return 1;
} else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
return -1;
} else {
const str1length = code1[i].length;
const str2length = code2[i].length;
for (let j = 0; j < str1length; j++) {
if (j+1 <= str2length) {
if (code1[i].charAt(j) != code2[i].charAt(j)) {
return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
} else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
if (str1length == str2length) {
return 0;
} else {
return str1length - str2length;
}
}
} else {
if (j+1 >= str1length) {
return 1;
} else {
return -1;
}
}
}
}
} else if (i+1 == code1length && code1[i] == code2[i]) {
if (code1length == code2length) {
return 0;
} else {
return code1length - code2length;
}
}
} else {
if (i+1 >= code1length) {
return 1;
} else {
return -1;
}
}
}
}
$.event.special.valuechange = {
teardown: function (namespaces) {
$(this).unbind('.valuechange');
},
handler: function (e) {
$.event.special.valuechange.triggerChanged($(this));
},
add: function (obj) {
$(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
},
triggerChanged: function (element) {
var current = element[0].contentEditable === 'true' ? element.html() : element.val()
, previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
if (current !== previous) {
element.trigger('valuechange', [element.data('previous')]);
element.data('previous', current);
}
}
};
function getPasteHint (str, row = '') {
let returnObj = str;
if (row) {
returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
}
return returnObj;
}
$(document).ready(() => {
//初始化所有附件列表
getAllList();
// 计算最新的变更总额和change的total_price是否一致,不一致则更新
// if (changeStatus !== auditConst.status.checked) {
calcChangePrice();
// }
//tab change
$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
const tab = $(this).data('tab');
if (tab === 'bgfujian') {
$('#fujian_btn').show();
$('#copy_btn').hide();
} else {
$('#fujian_btn').hide();
$('#copy_btn').show();
}
});
$('#add-bj').on('click', 'input[type="checkbox"]', function () {
const isCheck = $(this).prop('checked');
if (isCheck) {
$('#add-bj input[type="checkbox"]').each(function () {
$(this).prop('checked', false)
});
$(this).prop('checked', true)
}
});
$('#bg-copy').click(function() {
const cid = $('#add-bj input:checked').data('id');
postData(window.location.pathname + '/copy', cid, function () {
window.location.reload();
})
});
// 上传附件
$('#upload-file-btn').click(function () {
const files = $('#upload-file')[0].files;
const formData = new FormData();
formData.append('cid', $('#changeId').val());
formData.append('tid', $('#tenderId').val());
for (const file of files) {
if (file === undefined) {
toastr.error('未选择上传文件!');
return false;
}
const filesize = file.size;
if (filesize > 50 * 1024 * 1024) {
toastr.error('文件大小过大!');
return false;
}
const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
if (whiteList.indexOf(fileext) === -1) {
toastr.error('只能上传指定格式的附件!');
return false;
}
formData.append('size', filesize);
formData.append('file[]', file);
}
// if (!(change_uid === accountId || (auditors2 && auditors2.findIndex(item => item.uid === parseInt(accountId)) !== -1) || touristPermission)) {
if (!filePermission) {
return toastr.error('暂无权限上传!');
}
postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
attData = data.concat(attData);
// 重新生成List
getAllList();
$('#addfujian').modal('hide');
// let html = '';
// let index = $('#attList tr').length + 1;
// for (const fileInfo of data) {
// html += '
' +
// ` | ` +
// '' + index + ' | ' +
// `${fileInfo.filename}${fileInfo.fileext} | `+
// '' + fileInfo.in_time + ' ' + fileInfo.filesize + ' | ' +
// ``+
// ( auditStatus === 4 ?
// fileInfo.extra_upload ? `` : ''
// : ` `)+
// ` | `+
// // ' | ' +
// '
';
// ++index;
// }
// $('#attList').append(html);
}, function () {
});
$('#upload-file').val('');
});
// 删除附件
$('body').on('click', '.delete-file', function () {
let attid = $(this).data('attid');
let self = $(this);
const data = {id: attid};
postData(window.location.pathname + '/file/delete', data, function (result) {
// self.parents('tr').remove();
// // 重新排序
// let newsort = 1;
// $('#attList tr').each(function(){
// $(this).children('td').eq(1).text(newsort);
// newsort++;
// });
// 删除到attData中
const att_index = attData.findIndex(function (item) {
return item.id === parseInt(attid);
});
attData.splice(att_index, 1);
// 重新生成List
if ($('#attList tr').length === 1) {
getAllList(parseInt($('#currentPage').text()) - 1);
} else {
getAllList(parseInt($('#currentPage').text()));
}
});
});
// /change/download/file/
$('#attList').on('click', '.file-atn', function() {
const id = $(this).attr('f-id');
postData(`/change/download/file/${id}`, {}, (data) => {
const { filepath } = data;
$('#file-upload').attr('href', filepath);
$('#file-upload')[0].click();
})
});
$('#attList').on('click', '.check-file', function() {
const checkedList = $('#attList').find('input:checked');
const childs = $('#attList').children().length;
const checkBox = $('#check-all-file');
if (checkedList.length === childs) {
checkBox.prop("checked", true);
} else {
checkBox.prop("checked", false);
}
});
$('#check-all-file').click(function() {
const isCheck = $(this).is(':checked');
$('#attList').children().each(function() {
$(this).find('input:checkbox').prop("checked", isCheck);
})
});
$('#bach-download').click(function() {
const fileIds = [];
$( '#attList .check-file:checked').each(function() {
const fileId = $(this).attr('file-id');
fileId && fileIds.push(fileId);
});
if (fileIds.length) {
// const tid = $('#tenderId').val();
// const cid = $('#changeId').val();
// $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
// $('#downloadZip')[0].click();
if (fileIds.length > 20) {
return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
}
const tid = $('#tenderId').val();
const cid = $('#changeId').val();
toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
$(this).attr('disabled', "true");
const btn = $(this);
const fileArr = [];
for (const id of fileIds) {
const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
fileArr.push({
url: fileInfo.orginpath, //文件的oss存储路径 (必填)
name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
foldPath: '' // (可选, 文件在压缩包中的存储路径)
});
}
const packageName = `${tenderName}-工程变更-${changeName}-附件.zip`;
try {
zipOss.downloadFromAliOss(fileArr, packageName, btn);
} catch (e) {
btn.removeAttr('disabled');
toastr.clear();
toastr.error('批量下载失败');
}
// postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
// toastr.clear();
// toastr.success('压缩文件成功');
// btn.removeAttr('disabled');
// const href = window.URL.createObjectURL(result);
// $('#zipDown').attr('href', href);
// $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
// $("#zipDown")[0].click();
// }, () => {
// btn.removeAttr('disabled');
// toastr.clear();
// toastr.error('批量下载失败');
// });
}
});
// 差值对比信息获取
let czSpread = null;
const czSpreadSetting = {
cols: [
{title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
{title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
{title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
{title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
{title: '变更方案|数量', colSpan: '2|1', rowSpan: '1|1', field: 'pamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.pamount'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'pa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.pa_tp'},
{title: '变更令|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
{title: '差值对比|数量', colSpan: '2|1', rowSpan: '1|1', field: 'czamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.czamount'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cz_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.cz_tp'},
],
emptyRows: 0,
headRows: 2,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
readOnly: true,
localCache: {
key: 'changes-cz',
colWidth: true,
}
};
const czCol = {
getValue: {
unit_price: function(data) {
return ZhCalc.round(data.unit_price, unitPriceUnit);
},
pa_tp: function (data) {
return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.pamount, findDecimal(data.unit))), totalPriceUnit);
},
ca_tp: function (data) {
return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
},
pamount: function (data) {
return ZhCalc.round(data.pamount, findDecimal(data.unit));
},
camount: function (data) {
return ZhCalc.round(data.camount, findDecimal(data.unit));
},
czamount: function (data) {
return ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit)));
},
cz_tp: function (data) {
return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit))), findDecimal(data.unit))), totalPriceUnit);
},
}
};
const czSpreadObj = {
makeBackColor: function () {
const rowCount = czSpread.getActiveSheet().getRowCount();
for (let i = 0; i < rowCount; i++) {
if (czSpread.getActiveSheet().zh_data[i].color) czSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#f5c6cb');
}
},
makeSjsFooter: function () {
// 增加汇总行并设为锁定禁止编辑状态
czSpread.getActiveSheet().addRows(czSpread.getActiveSheet().getRowCount(), 1);
czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
czSpread.getActiveSheet().setStyle(czSpread.getActiveSheet().getRowCount() - 1, -1, style1);
czSpreadObj.countSum();
},
countSum: function () {
const rowCount = czSpread.getActiveSheet().getRowCount();
let pSum = 0,
cSum = 0,
czSum = 0;
for (let i = 0; i < rowCount - 1; i++) {
pSum = ZhCalc.add(pSum, czSpread.getActiveSheet().getValue(i, 5));
cSum = ZhCalc.add(cSum, czSpread.getActiveSheet().getValue(i, 7));
czSum = ZhCalc.add(czSum, czSpread.getActiveSheet().getValue(i, 9));
}
czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 5, pSum !== 0 ? pSum : null);
czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 9, czSum !== 0 ? czSum : null);
},
};
$('#bgfadb').on('shown.bs.modal', function () {
if (!czSpread) {
czSpread = SpreadJsObj.createNewSpread($('#cz-spread')[0]);
SpreadJsObj.initSpreadSettingEvents(czSpreadSetting, czCol);
SpreadJsObj.initSheet(czSpread.getActiveSheet(), czSpreadSetting);
}
const cList = [];
const newChangeList = _.cloneDeep(changeList);
for (const cl of newChangeList) {
const cIndex = _.findIndex(cList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
if (cIndex !== -1) {
cList[cIndex].spamount = ZhCalc.add(cList[cIndex].spamount, cl.spamount);
} else {
cList.push(cl);
}
}
// 生成差值对比数据列表
const czList = [];
const newPlanList = _.cloneDeep(planList);
for (const c of cList) {
const planInfo = _.find(newPlanList, { code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price });
const pamount = planInfo ? planInfo.spamount : null;
let color = true;
if (planInfo) {
_.remove(newPlanList, (item) => item === planInfo);
if ((pamount ? pamount : 0) === (c.spamount ? c.spamount : 0)) {
color = false;
}
}
czList.push({ code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price, camount: c.spamount, pamount, color });
}
if (newPlanList.length > 0) {
for (const np of newPlanList) {
czList.push({ code: np.code, name: np.name, unit: np.unit, unit_price: np.unit_price, camount: null, pamount: np.spamount, color: true });
}
}
if (czList.length > 0) {
// 按清单编号排序
czList.sort(sortByCode);
}
console.log(czList);
// sjs设置
SpreadJsObj.loadSheetData(czSpread.getActiveSheet(), SpreadJsObj.DataType.Data, czList);
czSpreadObj.makeBackColor();
czSpreadObj.makeSjsFooter();
});
// 清单汇总信息获取
let hzSpread = null;
const hzSpreadSetting = {
cols: [
{title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
{title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
{title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
{title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
{title: '申报变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
{title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'amount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.amount', visible: readOnly && !shenpiPower},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'a_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.a_tp', visible: readOnly && !shenpiPower},
{title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'spamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.spamount', visible: readOnly && shenpiPower},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'spa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.spa_tp', visible: readOnly && shenpiPower},
{title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', hAlign: 2, width: 60, type: 'Number', getValue: '', visible: !readOnly},
{title: '|金额', colSpan: '|1', rowSpan: '|1', hAlign: 2, width: 80, type: 'Number', getValue: '', visible: !readOnly},
],
emptyRows: 0,
headRows: 2,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
readOnly: true,
localCache: {
key: 'changes-hz',
colWidth: true,
}
};
const hzCol = {
getValue: {
unit_price: function(data) {
return ZhCalc.round(data.unit_price, unitPriceUnit);
},
camount: function (data) {
return ZhCalc.round(data.camount, findDecimal(data.unit));
},
ca_tp: function (data) {
return ZhCalc.round(data.ca_tp, totalPriceUnit);
},
amount: function (data) {
return ZhCalc.round(data.amount, findDecimal(data.unit));
},
a_tp: function (data) {
return ZhCalc.round(data.a_tp, totalPriceUnit);
},
spamount: function (data) {
return ZhCalc.round(data.spamount, findDecimal(data.unit));
},
spa_tp: function (data) {
return ZhCalc.round(data.spa_tp, totalPriceUnit);
},
}
};
const hzSpreadObj = {
makeBackColor: function () {
const rowCount = hzSpread.getActiveSheet().getRowCount();
for (let i = 0; i < rowCount; i++) {
if (readOnly && shenpiPower && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].spamount) {
hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
} else if (readOnly && !shenpiPower && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].amount) {
hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
} else if (!readOnly && !(hzSpread.getActiveSheet().zh_data[i].camount === '' || hzSpread.getActiveSheet().zh_data[i].camount === 0 || hzSpread.getActiveSheet().zh_data[i].camount === null)) {
hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
}
}
},
makeSjsFooter: function () {
// 增加汇总行并设为锁定禁止编辑状态
hzSpread.getActiveSheet().addRows(hzSpread.getActiveSheet().getRowCount(), 1);
hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
hzSpread.getActiveSheet().setStyle(hzSpread.getActiveSheet().getRowCount() - 1, -1, style1);
hzSpreadObj.countSum();
},
countSum: function () {
const rowCount = hzSpread.getActiveSheet().getRowCount();
let cSum = 0,
sSum = 0,
spSum = 0;
for (let i = 0; i < rowCount - 1; i++) {
cSum = ZhCalc.add(cSum, hzSpread.getActiveSheet().getValue(i, 5));
sSum = ZhCalc.add(sSum, hzSpread.getActiveSheet().getValue(i, 7));
spSum = ZhCalc.add(spSum, hzSpread.getActiveSheet().getValue(i, 9));
}
hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 5, cSum !== 0 ? cSum : null);
hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 7, sSum !== 0 ? sSum : null);
hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 9, spSum !== 0 ? spSum : null);
},
};
$('#qdgather').on('shown.bs.modal', function () {
if (!hzSpread) {
hzSpread = SpreadJsObj.createNewSpread($('#hz-spread')[0]);
SpreadJsObj.initSpreadSettingEvents(hzSpreadSetting, hzCol);
SpreadJsObj.initSheet(hzSpread.getActiveSheet(), hzSpreadSetting);
}
const hzList = [];
const newChangeList = _.cloneDeep(changeSpreadSheet.zh_data);
for (const cl of newChangeList) {
const hzIndex = _.findIndex(hzList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
const count4Amount = cl.audit_amount ? cl.audit_amount.split(',').length : 0;
cl.spa_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.spamount, findDecimal(cl.unit))), totalPriceUnit);
// 根据count4Amoun得出audit_amount_X值
cl.amount = count4Amount ? cl['audit_amount_' + count4Amount + ''] : 0;
cl.a_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.amount, findDecimal(cl.unit))), totalPriceUnit);
if (hzIndex !== -1) {
hzList[hzIndex].camount = ZhCalc.add(hzList[hzIndex].camount, cl.camount);
hzList[hzIndex].ca_tp = ZhCalc.add(hzList[hzIndex].ca_tp, cl.ca_tp);
hzList[hzIndex].spamount = ZhCalc.add(hzList[hzIndex].spamount, cl.spamount);
hzList[hzIndex].spa_tp = ZhCalc.add(hzList[hzIndex].spa_tp, cl.spa_tp);
hzList[hzIndex].amount = ZhCalc.add(hzList[hzIndex].amount, cl.amount);
hzList[hzIndex].a_tp = ZhCalc.add(hzList[hzIndex].a_tp, cl.a_tp);
} else {
hzList.push(cl);
}
}
if (hzList.length > 0) {
// 按清单编号排序
hzList.sort(sortByCode);
}
console.log(hzList);
// // sjs设置
SpreadJsObj.loadSheetData(hzSpread.getActiveSheet(), SpreadJsObj.DataType.Data, hzList);
hzSpreadObj.makeBackColor();
hzSpreadObj.makeSjsFooter();
});
// 切换页数
$('.page-select').on('click', function () {
const totalPageNum = parseInt($('#totalPage').text());
const lastPageNum = parseInt($('#currentPage').text());
const status = $(this).attr('content');
if (status === 'pre' && lastPageNum > 1) {
getAllList(lastPageNum-1);
$('#showAttachment').hide();
$('#syfujian .check-all-file').prop('checked', false)
} else if (status === 'next' && lastPageNum < totalPageNum) {
getAllList(lastPageNum+1);
$('#showAttachment').hide();
$('#syfujian .check-all-file').prop('checked', false)
}
});
// 数字只判断几个值(unit_price, oamount)
const numField = ['unit_price', 'oamount2'];
const changeSpreadSetting = {
cols: [
{title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
{title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
{title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
{title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
{title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
{title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
{title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isSettle2'},
{title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
{title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
{title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
// {title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},
// {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'},
// {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
],
emptyRows: 0,
headRows: 2,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
rowHeader:[
{
rowHeaderType: 'circle',
setting: {
size: 5,
indent: 16,
getColor: function (index, data) {
if (!data) return;
if (data.ccid && data.ccid === 1) {
return '#dc3545';
}
if (data.id && data.lid != 0 && !data.children) {
return '#ffc107';
}
if(data.lid != 0) return;
return '#007bff';
}
},
},
],
localCache: {
key: 'changes-spread',
colWidth: true,
}
};
if (readOnly) {
changeSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
for (const aid of aidList) {
// const userinfo = _.find(auditList2, { 'uid': aid });
const audit = _.find(auditors2, function(item){
return _.findIndex(item, { audit_order: aid }) !== -1;
});
const newColcount = {
title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
colSpan: '2|1', rowSpan: '1|1',
field: 'audit_amount_' + aid,
hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
};
const newColTp = {
title: '|金额',
colSpan: '|1', rowSpan: '|1',
field: 'sa_tp_' + aid,
hAlign: 2, width: 80, type: 'Number',
};
changeSpreadSetting.cols.push(newColcount);
changeSpreadSetting.cols.push(newColTp);
}
}
changeSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'changed_amount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'});
changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
// if (!readOnly) {
// changeSpreadSetting.cols.push({title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'});
// }
changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;
}
const changeCol = {
getValue: {
unit_price: function(data) {
return ZhCalc.round(data.unit_price, unitPriceUnit);
},
oa_tp: function (data) {
return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit);
},
ca_tp: function (data) {
return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
},
oamount2: function (data) {
return ZhCalc.round(data.oamount2, findDecimal(data.unit));
},
camount: function (data) {
return ZhCalc.round(data.camount, findDecimal(data.unit));
},
changed_amount: function (data) {
return ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
},
changed_tp: function (data) {
return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit));
},
// del_list: function (data) {
// return !_.find(changeUsedData, { cbid: data.id }) && !checkIsSettle(data) ? '移除' : '';
// }
},
readOnly: {
isValuation: function (data) {
return !(!readOnly && ((data.id && _.findIndex(changeUsedData, { cbid: data.id }) !== -1) || (data.children && data.children.length === 1 && _.findIndex(changeUsedData, { cbid: data.children[0].id }) !== -1)));
},
isEdit: function (data) {
return !(!readOnly && data.lid == 0 && data.id && !checkIsSettle(data));
},
isSettle: function (data) {
return !((!readOnly || shenpiPower) && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
},
isSettle2: function (data) {
return !(!readOnly && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
}
},
};
const changeSpreadObj = {
makeSjsFooter: function () {
// 增加汇总行并设为锁定禁止编辑状态
changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
changeSpreadObj.countSum();
},
setAuditValue: function () {
if (readOnly) {
for (const c of changeList) {
for (const j of aidList) {
c['audit_amount_' + j] = ZhCalc.round(c['audit_amount_' + j], findDecimal(c.unit));
c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
}
}
}
},
loadExprToInput: function () {
const sel = changeSpreadSheet.getSelections()[0];
if (!sel) return;
const col = changeSpreadSheet.zh_setting.cols[sel.col];
const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (col && col.field === 'camount' && data && (!data.gcl_id || (data.children && data.children.length === 1))) {
if (readOnly) {
$('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
} else {
$('#camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
}
} else {
$('#camount-expr').attr('readonly', true).val('');
}
},
topRowChanged: function (e, info) {
SpreadJsObj.saveTopAndSelect(info.sheet, ckChangeSpread);
},
selectionChanged: function (e, info) {
if (info.newSelections) {
if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (info.oldSelections && info.oldSelections[0].row !== changeSpreadSheet.getRowCount() - 1) {
info.sheet.getRange(info.oldSelections[0].row, -1, 1, -1).backColor('#fff');
}
if (!data) {
SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, []);
return;
}
console.log(info);
changeSpreadObj.refreshXmjData();
if (!readOnly) changeSpreadObj.refreshActn();
}
}
changeSpreadObj.loadExprToInput();
},
showHideAudit: function (show = false) {
if (shenpiPower) {
show = true;
}
if (readOnly) {
const count = changeSpreadSetting.cols.length;
for (let i = startLimit + 5; i < count - 2; i++) {
changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
}
changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
}
},
calcOneSum: function (node) {
if (node.children && node.children.length > 0) {
if (readOnly) {
for (const aid of aidList) {
let audit_amount = 0;
for (const c of node.children) {
audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(c['audit_amount_' + aid], findDecimal(node.unit)));
}
if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
node['audit_amount_' + aid] = audit_amount;
}
node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
}
}
let is_valuation = 1;
let ccid = 0;
let oamount2 = 0;
let camount = 0;
let samount = 0;
let spamount = 0;
for (const c of node.children) {
oamount2 = ZhCalc.add(oamount2, ZhCalc.round(c.oamount2, findDecimal(node.unit)));
camount = ZhCalc.add(camount, ZhCalc.round(c.camount, findDecimal(node.unit)));
samount = ZhCalc.add(samount, ZhCalc.round(c.samount, findDecimal(node.unit)));
spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(node.unit)));
if (c.is_valuation === 0) is_valuation = 0;
if (_.findIndex(changeLedgerList, { id: c.gcl_id }) !== -1 || _.findIndex(changePosList, { id: c.mx_id }) !== -1) {
ccid = 1;
}
c.order = node.order;
}
if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
node.oamount2 = oamount2;
node.camount = camount;
node.samount = samount;
node.spamount = spamount;
node.change_amount = ZhCalc.add(oamount2, camount);
}
node.is_valuation = is_valuation;
node.ccid = ccid;
this.calcNodeTp(node);
} else {
if (readOnly) {
for (const aid of aidList) {
node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
}
}
this.calcNodeTp(node);
}
return node;
},
calcNodeTp: function (node) {
node.change_amount = ZhCalc.add(node.oamount2, node.camount);
node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
},
refreshXmjData: function() {
SpreadJsObj.resetTopAndSelect(xmjSheet);
xmjSpreadObj.loadCurXmjData();
SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
// posSearch.search($('#pos-keyword').val());
},
makeNewChangeList: function(newOrder = changeOrder) {
// 先加载台账数据
if (!newOrder) {
const newChangeList2 = [];
for (const gcl of changeListData) {
if (!newOrder) {
if (gcl.leafXmjs !== undefined && gcl.leafXmjs !== null) {
const cl = _.filter(changeList, function (item) {
return _.findIndex(gcl.leafXmjs, { gcl_id: item.gcl_id }) !== -1;
});
if (cl.length > 0) {
for (const l of gcl.leafXmjs) {
const c = _.find(cl, { gcl_id: l.gcl_id, mx_id: l.mx_id || '' });
if (c) newChangeList2.push(c);
}
}
} else {
// 签约清单
const c = _.find(changeList, { lid: gcl.id });
if (c) newChangeList2.push(c);
}
}
}
// 按台账去重新排序changeList,空白清单居后
const sycList = _.difference(changeList, newChangeList2);
changeList = newChangeList2.concat(sycList);
}
const newChangeList = [];
for (const cl of changeList) {
const newCl = _.cloneDeep(cl);
if (cl.gcl_id && _.findIndex(newChangeList, { gcl_id: cl.gcl_id }) === -1) {
// delete newCl.id;
// newCl.bwmx = '';
// newCl.detail = '';
// newCl.delimit = null;
newCl.children = [];
newCl.children.push(cl);
if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
newCl.ccid = 1;
}
newChangeList.push(newCl);
} else if (!cl.gcl_id) {
newChangeList.push(newCl);
} else {
const newCl2 = _.find(newChangeList, { gcl_id: cl.gcl_id });
if (newCl2) {
if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
newCl2.ccid = 1;
}
delete newCl2.id;
newCl2.bwmx = '';
newCl2.detail = '';
newCl2.delimit = null;
newCl2.children.push(newCl);
}
}
}
const updateOrderList = [];
// order如果不同,则修改并提交
let i = 0;
// 重算金额和数量汇总
for (const node of newChangeList) {
if (node.children && node.children.length > 0) {
changeSpreadObj.calcOneSum(node);
node.order = i + 1;
const cls = node.gcl_id ? _.filter(changeList, { gcl_id: node.gcl_id }) : [];
for (const c of cls) {
if (node.order !== c.order) {
c.order = node.order;
updateOrderList.push({ id: c.id, order: node.order });
}
}
} else {
if (node.order !== i + 1) {
node.order = i + 1;
updateOrderList.push({ id: node.id, order: node.order });
}
changeSpreadObj.calcOneSum(node);
if (readOnly) {
for (const aid of aidList) {
node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
}
}
}
i++;
}
return [newChangeList, updateOrderList];
},
countSum: function () {
const rowCount = changeSpreadSheet.getRowCount();
let oa_tp = 0,
ca_tp = 0,
sa_tp = 0,
changed_tp = 0;
const aidLength = readOnly ? aidList.length : 0;
for (const data of changeSpreadSheet.zh_data) {
oa_tp = ZhCalc.add(oa_tp, data.oa_tp);
ca_tp = ZhCalc.add(ca_tp, data.ca_tp);
sa_tp = ZhCalc.add(sa_tp, data.sa_tp);
changed_tp = ZhCalc.add(changed_tp, data.changed_tp);
}
changeSpreadSheet.setValue(rowCount - 1, startLimit, oa_tp !== 0 ? oa_tp : null);
changeSpreadSheet.setValue(rowCount - 1, startLimit + 2, ca_tp !== 0 ? ca_tp : null);
if (readOnly) {
changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), sa_tp !== 0 ? sa_tp : null);
changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4 + aidLength * 2 + 2), changed_tp !== 0 ? changed_tp : null);
} else {
changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), changed_tp !== 0 ? changed_tp : null);
}
if (readOnly) {
// 用户的数据合计
for (const j in aidList) {
let audit_sum = 0;
for (const data of changeSpreadSheet.zh_data) {
audit_sum = ZhCalc.add(audit_sum, data['sa_tp_' + aidList[j]]);
}
changeSpreadSheet.setValue(rowCount - 1, startLimit + 6 + j * 2, audit_sum !== 0 ? audit_sum : null);
}
}
},
reloadRow: function (sheet, row, rowCount = 0, clearAll = false) {
if (rowCount) {
SpreadJsObj.reLoadRowData(sheet, row, rowCount);
} else {
SpreadJsObj.reLoadRowData(sheet, row);
}
if (clearAll) {
for (const i in sheet.zh_data) {
const data = sheet.zh_data[i];
if (data) {
sheet.getRange(i, -1, 1, -1).backColor('#fff');
}
}
}
sheet.getRange(row, -1, 1, -1).backColor('#fffacd');
},
reloadSheet: function (newChangeList) {
changeSpreadObj.setAuditValue();
SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, newChangeList);
SpreadJsObj.loadTopAndSelect(changeSpreadSheet, ckChangeSpread);
changeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
changeSpreadObj.makeSjsFooter();
xmjSpreadObj.loadCurXmjData();
changeSpreadObj.loadExprToInput();
if (!readOnly) changeSpreadObj.refreshActn();
}
};
// sjsSettingObj.setGridSelectStyle(changeSpreadSetting);
SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
let changeListData;
let gclGatherData;
postData(preUrl + '/defaultBills', {}, function (result) {
ledgerList = result.bills;
posList = result.pos;
gclGatherModel.loadLedgerData(result.bills);
gclGatherModel.loadPosData(result.pos);
gclGatherData = gclGatherModel.gatherGclData();
gclGatherData = _.filter(gclGatherData, function (item) {
return item.leafXmjs && item.leafXmjs.length !== 0;
});
for (const ggd in gclGatherData) {
if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
gclGatherData.splice(ggd, 1);
}
gclGatherData[ggd].code = gclGatherData[ggd].b_code;
let hadcid = 0;
for (const xmj of gclGatherData[ggd].leafXmjs) {
const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
if (changeLedger || changePos) {
xmj.cid = 1;
xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
hadcid = 1;
}
}
if (hadcid !== 0) gclGatherData[ggd].cid = 1;
}
console.log(gclGatherData);
// 数组去重
const dealBillList = result.dealBills;
for (const db of gclGatherData) {
const exist_index = dealBillList.findIndex(function (item) {
return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
});
if (exist_index !== -1) {
dealBillList.splice(exist_index, 1);
}
}
changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
if (!readOnly || shenpiPower) {
checkAndChange(changeListData);
}
showMode(changeMode);
});
changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
changeSpread.bind(spreadNS.Events.topRowChanged, changeSpreadObj.topRowChanged);
// 项目节信息获取
const xmjSpreadSetting = {
cols: [
{title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
{title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80, readOnly: true},
// {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
{title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100, readOnly: true},
{title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100, readOnly: true},
{title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100, readOnly: true},
{title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100, readOnly: true},
{title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100, readOnly: true},
{title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
{title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
{title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
{title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', type: 'Number', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
// {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
],
emptyRows: 0,
headRows: 2,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
// readOnly: true,
rowHeader:[
{
rowHeaderType: 'circle',
setting: {
size: 5,
indent: 16,
getColor: function (index, data) {
if (!data) return;
if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
return '#dc3545';
}
}
},
},
],
localCache: {
key: 'changes-xmj',
colWidth: true,
}
};
if (readOnly) {
xmjSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
for (const aid of aidList) {
const audit = _.find(auditors2, function(item){
return _.findIndex(item, { audit_order: aid }) !== -1;
});
const newColcount = {
title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
colSpan: '1|1', rowSpan: '|1',
field: 'audit_amount_' + aid,
hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
};
xmjSpreadSetting.cols.push(newColcount);
}
}
xmjSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
const xmjCol = {
getValue: {
oamount2: function (data) {
return ZhCalc.round(data.oamount2, findDecimal(data.unit));
},
camount: function (data) {
return ZhCalc.round(data.camount, findDecimal(data.unit));
},
samount: function (data) {
return ZhCalc.round(data.samount, findDecimal(data.unit));
},
changed_amount: function (data) {
return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
},
},
readOnly: {
isEdit: function (data) {
return readOnly;
},
isValuation: function (data) {
return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
},
isSettle: function (data) {
return !((!readOnly || shenpiPower) && !checkIsSettle(data));
},
isSettle2: function (data) {
return !(!readOnly && !checkIsSettle(data));
}
},
}
sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
const xmjSheet = xmjSpread.getActiveSheet();
const xmjSpreadObj = {
loadExprToInput: function () {
const sel = xmjSheet.getSelections()[0];
if (!sel) return;
const col = xmjSheet.zh_setting.cols[sel.col];
const data = SpreadJsObj.getSelectObject(xmjSheet);
if (col && col.field === 'camount' && data) {
if (readOnly) {
$('#xmj-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
} else {
$('#xmj-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
}
} else {
$('#xmj-camount-expr').attr('readonly', true).val('');
}
},
/**
* 加载计量单元 根据当前台账选择节点
*/
loadCurXmjData: function () {
const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
changeSpreadSheet.getRange(changeSpreadSheet.getSelections()[0].row, -1, 1, -1).backColor('#fffacd');
const xmj = [];
if (data && data.children && data.children.length > 0) {
for (const child of data.children) {
if (child.bwmx === child.xmj_jldy) {
child.bwmx = '';
}
xmj.push(child);
}
}
SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, xmj);
xmjSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
SpreadJsObj.resetTopAndSelect(xmjSheet);
xmjSpreadObj.loadExprToInput();
},
selectionChanged: function (e, info) {
xmjSpreadObj.loadExprToInput();
},
showHideAudit: function (show = false) {
if (shenpiPower) {
show = true;
}
if (readOnly) {
const xmjStartLimit = 9;
const count = xmjSpreadSetting.cols.length;
for (let i = xmjStartLimit + 2; i < count - 1; i++) {
xmjSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
}
xmjSheet.setColumnVisible(xmjStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
}
},
};
xmjSpread.bind(spreadNS.Events.SelectionChanged, xmjSpreadObj.selectionChanged);
if (!readOnly) {
$('.dropdown-menu input[name="paixu"]').on('click', function () {
const newChangeOrder = parseInt($(this).val());
if (newChangeOrder !== changeOrder) {
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList(newChangeOrder);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'order_by', updateData: newChangeOrder, updateOrderList }, function (result) {
if (newChangeOrder === 0) {
$('#bpaixu').text('清单排序:清单编号');
$('#upAndMoveBtn').attr('style', 'display: none !important');
$('.order_text').text('添加');
changeOrder = newChangeOrder;
} else if (newChangeOrder === 1) {
$('#bpaixu').text('清单排序:添加顺序');
$('#upAndMoveBtn').show();
$('.order_text').text('插入');
changeOrder = newChangeOrder;
}
changeList = result.changeList;
changeUsedData = result.usedList;
const [newChangeList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
});
}
});
$('#set-site-btn').click(async function () {
if (changeOrder && !changeMode) {
const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (!select && changeSpreadSheet.zh_data.length > 0) {
toastr.error('请选择清单再插入');
return;
}
postData(window.location.pathname + '/save', { type:'order_site', listid: select && select.id ? select.id : (select && select.children && select.children.length > 0 ? select.children[0].id : null) }, function (result) {
window.location.href = window.location.pathname + '/revise';
});
} else {
window.location.href = window.location.pathname + '/revise';
}
});
changeSpreadObj.refreshActn = function (rowCount = 1) {
const setObjEnable = function (obj, enable) {
if (enable) {
obj.removeClass('disabled');
} else {
obj.addClass('disabled');
}
};
// const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
// 还需判断是否已被调差清单调用
const selection = changeSpreadSheet.getSelections();
const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
const row = sel ? sel.row : -1;
const first = changeSpreadSheet.zh_data[row];
let last = first;
if (sel.rowCount > 1 && first) {
for (let r = 1; r < sel.rowCount; r++) {
const rNode = changeSpreadSheet.zh_data[sel.row + r];
if (!rNode) break;
last = rNode;
}
}
const preNode = changeSpreadSheet.zh_data[row - 1];
setObjEnable($('#up-move'), !readOnly && first && preNode && changeSpreadSheet.zh_data.indexOf(last) > 0 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
setObjEnable($('#down-move'), !readOnly && first && changeSpreadSheet.zh_data.indexOf(last) < changeSpreadSheet.zh_data.length - 1 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
// setObjEnable($('#open-list-modal'), !readOnly && select && changeList.indexOf(select) !== -1);
// setObjEnable($('#add-white-btn'), !readOnly && select && changeList.indexOf(select) !== -1);
};
changeSpreadObj.add = function () {
let select = null;
if (changeOrder) {
select = SpreadJsObj.getSelectObject(changeSpreadSheet);
}
postData(window.location.pathname + '/save', {type: 'add', postData: select ? select.order : null}, function (result) {
if (result) {
if (changeOrder === 1 && select) {
// 批量更新changeList的order值
_.forEach(changeList, function (item) {
item.order = item.order > select.order ? item.order + 1 : item.order;
});
_.forEach(changeSpreadSheet.zh_data, function (item) {
item.order = item.order > select.order ? item.order + 1 : item.order;
});
changeList.splice(select.order, 0, result);
changeSpreadSheet.addRows(select.order, 1);
changeSpreadSheet.zh_data.splice(select.order, 0, _.cloneDeep(result));
changeSpreadSheet.getRange(select.order - 1, -1, 1, -1).backColor('#fff');
changeSpreadSheet.setSelection(select.order, 1, 1, 1);
changeSpreadObj.reloadRow(changeSpreadSheet, select.order);
} else {
changeList.push(result);
changeSpreadSheet.zh_data.push(_.cloneDeep(result));
changeSpreadSheet.addRows(changeSpreadSheet.zh_data.length - 1, 1);
changeSpreadSheet.setSelection(changeSpreadSheet.zh_data.length - 1, 1, 1, 1);
changeSpreadObj.reloadRow(changeSpreadSheet, changeSpreadSheet.zh_data.length - 1, 0, true);
}
changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
changeSpreadObj.refreshXmjData();
changeSpreadObj.refreshActn();
}
});
};
changeSpreadObj.batchAdd = function(num) {
let select = null;
if (changeOrder) {
select = SpreadJsObj.getSelectObject(changeSpreadSheet);
}
postData(window.location.pathname + '/save', {type: 'batchadd', num, postData: select ? select.order : null}, function (result) {
if (result) {
changeList = result;
SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}
});
};
// 计量单元修改
changeSpreadObj.del = function () {
const selection = changeSpreadSheet.getSelections();
const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
const row = sel && sel.row !== undefined ? sel.row : -1;
const count = sel.rowCount;
if (readOnly || row === -1 || row + count > changeSpreadSheet.zh_data.length) {
return false;
}
const delList = [];
let lastSelect = null;
for (let r = 0; r < count; r++) {
const select = changeSpreadSheet.zh_data[row + r];
if (!select || !select.id) {
toastr.error('变更清单不存在或者该清单存在项目节');
return;
}
if(!select || _.find(changeUsedData, { cbid: select.id })) {
toastr.error('已调用的变更清单不能删除');
return false;
}
if (checkIsSettle(select)) {
toastr.error('已结算的变更清单不能删除');
return false;
}
if (r === count - 1 && changeOrder) {
lastSelect = select;
}
delList.push(select.id);
}
if (delList.length) {
postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
changeSpreadSheet.deleteRows(row, count);
changeSpreadSheet.zh_data.splice(row, count);
changeSpreadObj.countSum();
changeSpreadSheet.setSelection(0, 0, 1, 1);
changeSpreadObj.refreshXmjData();
changeSpreadObj.refreshActn();
});
}
};
changeSpreadObj.editStarting = function (e, info) {
const select = SpreadJsObj.getSelectObject(info.sheet);
if (select && select.id) {
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'camount') {
if (select.camount_expr && select.camount_expr !== '') {
info.sheet.getCell(info.row, info.col).text(select.camount_expr);
}
}
}
};
changeSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
if (!select || !select.id) {
toastr.error('该变更清单无法编辑');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
return;
}
let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
let orgValue;
if (col.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
} else {
orgValue = select[col.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
if(col.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: select.id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
cInfo.spamount = select.spamount;
cInfo.camount_expr = exprQuantity.expr;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
if (col.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
}
if (col.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('计量上限默认值只能输入0-100之间的整数');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: select.id });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
if (validText < minLimit) {
toastr.error('计量上限值至少大于等于 ' + minLimit);
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
console.log(cInfo);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
if (select.children && select.children.length === 1) {
const child = select.children[0];
child[col.field] = validText;
}
changeSpreadObj.calcOneSum(select);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
changeSpreadObj.refreshXmjData();
changeSpreadObj.countSum();
changeSpreadObj.refreshActn();
if (info.row === info.sheet.zh_data.length - 1) {
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if(col.field === 'camount') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
changeSpreadObj.reloadRow(info.sheet, info.row);
});
};
changeSpreadObj.clipboardPasted = function (e, info) {
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_data || [];
const data = [];
// const rowData = [];
let needCopyIgnore = !$('#customCheck1').is(':checked');
let needColAdd = false;
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
if (!sortData[curRow].id) {
bPaste = false;
continue;
}
const cLData = { id: sortData[curRow].id };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
const newCurCol = curCol + 1;
needColAdd = true;
colSetting = info.sheet.zh_setting.cols[newCurCol];
}
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue;
if (colSetting.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
: (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
} else {
orgValue = sortData[curRow][colSetting.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if(colSetting.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastMessageUniq(getPasteHint(msg, hintRow));
bPaste = false;
continue;
}
if (isNaN(exprQuantity.quantity)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
cLData.camount_expr = exprQuantity.expr;
sortData[curRow].camount_expr = exprQuantity.expr;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
if (colSetting.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
}
if (colSetting.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
bPaste = false;
continue;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
if (validText < minLimit) {
toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
bPaste = false;
continue;
}
}
}
}
let unitdecimal = validText;
cLData[colSetting.field] = validText;
sortData[curRow][colSetting.field] = validText;
cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
}
if (bPaste) {
data.push(cLData);
// rowData.push(curRow);
} else {
changeSpreadObj.reloadRow(info.sheet, curRow);
}
}
if (data.length === 0) {
changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
changeList = result;
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}, function () {
changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
changeSpreadObj.buttonClicked = function(e, info) {
if (info.sheet.zh_setting) {
const select = SpreadJsObj.getSelectObject(info.sheet);
if (!select || !select.id) {
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
if (info.sheet.isEditing()) {
info.sheet.endEdit(true);
}
if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
return;
}
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
cInfo.is_valuation = select.is_valuation;
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
changeSpreadObj.reloadRow(info.sheet, info.row);
if (select.children && select.children.length === 1) {
const child = select.children[0];
child[col.field] = select.is_valuation;
changeSpreadObj.refreshXmjData();
}
}, function () {
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
cInfo.is_valuation = select.is_valuation;
changeSpreadObj.reloadRow(info.sheet, info.row);
});
}
}
};
changeSpreadObj.valueChanged = function(e, info) {
// 防止ctrl+z撤销数据
changeSpreadObj.reloadRow(info.sheet, info.row);
};
changeSpreadObj.setAllValuation = function (is_valuation) {
if (changeList.length === 0) {
toastr.warning('暂无清单无法设置清单计价');
return;
}
const needChangeList = _.filter(changeList, { is_valuation: is_valuation ? 0 : 1 });
if (needChangeList.length === 0) {
toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
return;
}
const realNeedChangeList = [];
for (const nc of needChangeList) {
if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
realNeedChangeList.push(nc.id);
}
}
if (realNeedChangeList.length === 0) {
toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
return;
}
postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
changeList = result;
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
});
};
changeSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_data[iRow];
if (!node || !node.id) continue;
const cInfo = _.find(changeList, { id: node.id });
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'camount' || col.field === 'oamount2') {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field === 'camount') {
node.camount_expr = '';
node.spamount = null;
cInfo.camount_expr = '';
cInfo.spamount = null;
}
delete cInfo.waitingLoading;
bDel = true;
}
}
if (bDel) datas.push(cInfo);
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
changeList = result;
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}, function () {
changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
changeSpreadObj.upMove = function () {
const data = {
type: 'changeOrder',
postData: [],
};
const selection = changeSpreadSheet.getSelections();
const row = selection[0].row, count = selection[0].rowCount;
const first = changeSpreadSheet.zh_data[row];
const firstRow = row;
if (!first) {
changeSpreadObj.refreshActn();
return false;
}
const pre = changeSpreadSheet.zh_data[row - 1];
const preUpdates = [];
if (pre && pre.id) {
preUpdates.push({ id: pre.id });
} else if (pre && pre.children && pre.children.length > 0) {
for (const item of pre.children) {
preUpdates.push({ id: item.id });
}
}
for (let iRow = 0; iRow < count; iRow++) {
const posData = changeSpreadSheet.zh_data[iRow + row];
if (posData) {
for (const item of preUpdates) {
item.order = posData.order;
}
if (posData.id) {
data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
} else if (posData && posData.children && posData.children.length > 0) {
for (const item of posData.children) {
data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
}
}
}
}
data.postData.push(...preUpdates);
console.log(data);
if (data.postData.length > 0) {
postData(window.location.pathname + '/save', data, function () {
_.forEach(data.postData, function (item) {
const cl = _.find(changeList, { id: item.id });
cl.order = item.order;
});
changeList.sort(function (a, b) {
return a.order - b.order
});
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
const sel = selection[0];
if (sel) {
changeSpreadSheet.setSelection(row - 1, sel.col, sel.rowCount, sel.colCount);
changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
}
changeSpreadObj.reloadSheet(newChangeList);
});
}
};
changeSpreadObj.downMove = function () {
const data = {
type: 'changeOrder',
postData: [],
};
const selection = changeSpreadSheet.getSelections();
const row = selection[0].row, count = selection[0].rowCount;
const first = changeSpreadSheet.zh_data[row];
if (!first) {
changeSpreadObj.refreshActn();
return false;
}
const next = changeSpreadSheet.zh_data[row + count];
const nextUpdates = [];
if (next && next.id) {
nextUpdates.push({ id: next.id });
} else if (next && next.children && next.children.length > 0) {
for (const item of next.children) {
nextUpdates.push({ id: item.id });
}
}
for (let iRow = count - 1; iRow >= 0; iRow--) {
const posData = changeSpreadSheet.zh_data[iRow + row];
if (posData) {
for (const item of nextUpdates) {
item.order = posData.order;
}
if (posData.id) {
data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
} else if (posData && posData.children && posData.children.length > 0) {
for (const item of posData.children) {
data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
}
}
}
}
data.postData.push(...nextUpdates);
console.log(data);
if (data.postData.length > 0) {
postData(window.location.pathname + '/save', data, function () {
_.forEach(data.postData, function (item) {
const cl = _.find(changeList, { id: item.id });
cl.order = item.order;
});
changeList.sort(function (a, b) {
return a.order - b.order
});
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
const sel = selection[0];
if (sel) {
changeSpreadSheet.setSelection(row + 1, sel.col, sel.rowCount, sel.colCount);
changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
}
changeSpreadObj.reloadSheet(newChangeList);
});
}
};
// 表达式判断
$('#camount-expr').change(function () {
if (this.readOnly) return;
let validText = $(this).val();
const sel = changeSpreadSheet.getSelections()[0];
const row = sel ? sel.row : -1;
const col = changeSpreadSheet.zh_setting.cols[sel.col];
if (row === -1 || !(col && col.field === 'camount')) return;
const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (!select || !select.id) return;
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) return;
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
const orgExprValue = _.clone(select.camount_expr);
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
return;
}
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
select.camount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
cInfo.spamount = select.spamount;
cInfo.camount_expr = select.camount_expr;
cInfo.camount = validText;
// console.log(select);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
changeSpreadObj.reloadRow(changeSpreadSheet, row);
changeSpreadObj.calcOneSum(select);
changeSpreadObj.countSum();
changeSpreadObj.refreshActn();
if (SpreadJsObj.getSelectObject(changeSpreadSheet) === select) {
if (select.children && select.children.length === 1) {
changeSpreadObj.refreshXmjData();
}
}
changeSpreadObj.loadExprToInput(changeSpreadSheet);
}, function () {
select.camount = orgValue;
select.camount_expr = orgExprValue;
select.spamount = orgValue;
cInfo.camount = orgValue;
cInfo.camount_expr = orgExprValue;
cInfo.spamount = orgValue;
changeSpreadObj.reloadRow(changeSpreadSheet, row);
});
});
$('#add-white-btn').click(changeSpreadObj.add);
$('#up-move').click(changeSpreadObj.upMove);
$('#down-move').click(changeSpreadObj.downMove);
changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
changeSpread.bind(spreadNS.Events.EditStarting, changeSpreadObj.editStarting);
changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
// 计量单元修改
xmjSpreadObj.del = function () {
const selection = xmjSheet.getSelections();
const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
const row = sel && sel.row !== undefined ? sel.row : -1;
const count = sel.rowCount;
if (readOnly || row === -1 || row + count > xmjSheet.zh_data.length) {
return false;
}
const delList = [];
let lastSelect = null;
for (let r = 0; r < count; r++) {
const select = xmjSheet.zh_data[row + r];
if(!select || _.find(changeUsedData, { cbid: select.id })) {
toastr.error('已调用的变更清单不能删除');
return false;
}
if (checkIsSettle(select)) {
toastr.error('已结算的变更清单不能删除');
return false;
}
if (r === count - 1 && xmjSheet.zh_data.length === count && changeOrder) {
lastSelect = select;
}
delList.push(select.id);
}
if (delList.length) {
postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null, delLength: 1}, function (result) {
xmjSheet.deleteRows(row, count);
xmjSheet.zh_data.splice(row, count);
// 同步删除changeList值
_.forEach(delList, function (id) {
_.remove(changeList, { id: id });
});
const billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, billsNode);
let allDel = false;
// 判断是移除还是更新数量和金额
if (xmjSheet.zh_data.length === 0) {
changeSpreadSheet.deleteRows(billIndex, 1);
changeSpreadSheet.zh_data.splice(billIndex, 1);
allDel = true;
} else {
billsNode.children = xmjSheet.zh_data;
if (billsNode.children.length === 1) {
billsNode.id = billsNode.children[0].id;
billsNode.bwmx = billsNode.children[0].bwmx || billsNode.children[0].xmj_jldy;
billsNode.detail = billsNode.children[0].detail;
billsNode.delimit = billsNode.children[0].delimit;
}
changeSpreadObj.calcOneSum(billsNode);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
}
changeSpreadObj.countSum();
if (allDel) {
changeSpreadSheet.setSelection(0, 0, 1, 1);
changeSpreadObj.refreshXmjData();
changeSpreadObj.refreshActn();
}
});
}
};
xmjSpreadObj.editStarting = function (e, info) {
xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
const col = info.sheet.zh_setting.cols[info.col];
const select = SpreadJsObj.getSelectObject(info.sheet);
if (col.field === 'camount') {
if (select.camount_expr && select.camount_expr !== '') {
info.sheet.getCell(info.row, info.col).text(select.camount_expr);
}
}
};
xmjSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
console.log(info.sheet.zh_data);
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
return;
}
let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
let orgValue;
if (col.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
} else {
orgValue = select[col.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const node = xmjSpreadObj.billsNode;
if (!node) {
toastr.error('数据错误,请选择清单节点后再试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if(col.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: select.id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
cInfo.spamount = select.spamount;
cInfo.camount_expr = exprQuantity.expr;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (col.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
}
if (col.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('计量上限默认值只能输入0-100之间的整数');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: select.id });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
if (validText < minLimit) {
toastr.error('计量上限值至少大于等于 ' + minLimit);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
console.log(cInfo);
delete cInfo.waitingLoading;
const children = info.sheet.zh_data;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = children;
if (node.children && node.children.length === 1) {
node[col.field] = validText;
if (col.field === 'camount') {
node.spamount = select.spamount;
node.camount_expr = select.camount_expr;
}
}
xmjSpreadObj.loadExprToInput();
changeSpreadObj.calcOneSum(node);
console.log(node);
if (SpreadJsObj.getSelectObject(changeSpreadSheet) !== node) {
SpreadJsObj.reLoadRowData(changeSpreadSheet, billIndex);
} else {
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
}
changeSpreadObj.countSum();
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if(col.field === 'camount') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
};
xmjSpreadObj.clipboardPasted = function (e, info) {
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_data || [];
if (range.row + range.rowCount > sortData.length) {
toastMessageUniq(hint.cellError);
// SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
xmjSpreadObj.loadCurXmjData();
return;
}
if (sortData.length > 0 && range.col + range.colCount > 12) {
toastMessageUniq(hint.cellError);
xmjSpreadObj.loadCurXmjData();
return;
}
if (!info.sheet.zh_setting) {
xmjSpreadObj.loadCurXmjData();
return;
}
const data = [];
// const rowData = [];
let needCopyIgnore = !$('#customCheck1').is(':checked');
let needColAdd = false;
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
// const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
const cLData = { id: sortData[curRow].id };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
const newCurCol = curCol + 1;
needColAdd = true;
colSetting = info.sheet.zh_setting.cols[newCurCol];
}
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue;
if (colSetting.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
: (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
} else {
orgValue = sortData[curRow][colSetting.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if(colSetting.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastMessageUniq(getPasteHint(msg, hintRow));
bPaste = false;
continue;
}
if (isNaN(exprQuantity.quantity)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
cLData.camount_expr = exprQuantity.expr;
sortData[curRow].camount_expr = exprQuantity.expr;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
if (colSetting.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
}
if (colSetting.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('项目节第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
bPaste = false;
continue;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
if (validText < minLimit) {
toastr.error('项目节第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
bPaste = false;
continue;
}
}
}
}
let unitdecimal = validText;
cLData[colSetting.field] = validText;
sortData[curRow][colSetting.field] = validText;
cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
}
if (bPaste) {
data.push(cLData);
// rowData.push(curRow);
} else {
SpreadJsObj.reLoadRowData(info.sheet, curRow);
}
}
if (data.length === 0) {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
changeList = result;
const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = info.sheet.zh_data;
if (node.children && node.children.length === 1) {
for (const col in data[0]) {
node[col] = data[0][col];
}
}
changeSpreadObj.calcOneSum(node);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
changeSpreadObj.countSum();
xmjSpreadObj.loadCurXmjData();
}, function () {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
xmjSpreadObj.buttonClicked = function(e, info) {
if (info.sheet.zh_setting) {
const select = SpreadJsObj.getSelectObject(info.sheet);
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
if (info.sheet.isEditing()) {
info.sheet.endEdit(true);
}
if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
return;
}
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
cInfo.is_valuation = select.is_valuation;
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = info.sheet.zh_data;
changeSpreadObj.calcOneSum(node);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
}, function () {
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
cInfo.is_valuation = select.is_valuation;
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
}
}
};
xmjSpreadObj.valueChanged = function(e, info) {
// 防止ctrl+z撤销数据
SpreadJsObj.reLoadRowData(info.sheet, info.row);
};
xmjSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_data[iRow];
const cInfo = _.find(changeList, { id: node.id });
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'camount' || col.field === 'oamount2') {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field === 'camount') {
node.camount_expr = '';
node.spamount = null;
cInfo.camount_expr = '';
cInfo.spamount = null;
}
delete cInfo.waitingLoading;
bDel = true;
}
}
if (bDel) datas.push(cInfo);
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
changeList = result;
const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = xmjSheet.zh_data;
changeSpreadObj.calcOneSum(node);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
changeSpreadObj.countSum();
xmjSpreadObj.loadCurXmjData();
}, function () {
SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
xmjSpreadObj.setAllValuation = function (is_valuation) {
const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (!select) {
toastr.error('未选中清单');
return;
}
if (!select.children || select.children.length === 0) {
toastr.warning('暂无清单无法设置清单计价');
return;
}
const needChangeList = _.filter(select.children, { is_valuation: is_valuation ? 0 : 1 });
if (needChangeList.length === 0) {
toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
return;
}
const realNeedChangeList = [];
for (const nc of needChangeList) {
if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
realNeedChangeList.push(nc.id);
}
}
if (realNeedChangeList.length === 0) {
toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
return;
}
postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
changeList = result;
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
});
};
// 表达式判断
$('#xmj-camount-expr').change(function () {
if (this.readOnly) return;
let validText = $(this).val();
const sel = xmjSheet.getSelections()[0];
const row = sel ? sel.row : -1;
const col = xmjSheet.zh_setting.cols[sel.col];
if (row === -1 || !(col && col.field === 'camount')) return;
const select = SpreadJsObj.getSelectObject(xmjSheet);
if (!select) return;
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) return;
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
const orgExprValue = _.clone(select.camount_expr);
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
return;
}
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
select.camount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
cInfo.spamount = select.spamount;
cInfo.camount_expr = select.camount_expr;
cInfo.camount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
// console.log(select);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
SpreadJsObj.reLoadRowData(xmjSheet, row);
const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = xmjSheet.zh_data;
changeSpreadObj.calcOneSum(node);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
changeSpreadObj.countSum();
xmjSpreadObj.loadExprToInput(xmjSheet);
}, function () {
select.camount = orgValue;
select.camount_expr = orgExprValue;
select.spamount = orgValue;
cInfo.camount = orgValue;
cInfo.camount_expr = orgExprValue;
cInfo.spamount = orgValue;
SpreadJsObj.reLoadRowData(posSheet, row);
});
});
xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
xmjSpread.bind(spreadNS.Events.ValueChanged, xmjSpreadObj.valueChanged);
xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked);
SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
let batchInsertObj;
$.contextMenu.types.batchInsert = function (item, opt, root) {
const self = this;
if ($.isFunction(item.icon)) {
item._icon = item.icon.call(this, this, $t, key, item);
} else {
if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
// to enable font awesome
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
} else {
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
}
}
this.addClass(item._icon);
const $obj = $('' + item.name + '行
')
.appendTo(this);
const $input = $obj.find('input');
const event = () => {
if (self.hasClass('context-menu-disabled')) return;
item.batchInsert($input[0], root);
};
$obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
$input.click((e) => {e.stopPropagation();})
.keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
.on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
};
// 右键菜单
$.contextMenu({
selector: '#change-spread',
build: function ($trigger, e) {
const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
// console.log(e, target);
// const range = SpreadJsObj.getTargetSelection(changeSpreadSheet, target);
// console.log(range);
let ts = getLocalCache(ckChangeSpread);
if (ts !== '') {
ts = JSON.parse(ts);
if (ts === undefined || ts === null) return;
if (ts.sel) {
changeSpreadSheet.getRange(ts.sel.row, -1, 1, -1).backColor('#fff');
}
}
changeSpreadObj.refreshXmjData();
changeSpreadObj.refreshActn();
return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
},
items: {
'createList': {
name: '添加台账清单',
icon: 'fa-sign-in',
visible: function () {
return changeOrder === 0;
},
callback: function (key, opt) {
// $('#addlist').modal('show');
$('#set-site-btn').click();
},
},
'createAdd': {
name: '添加空白清单',
icon: 'fa-sign-in',
visible: function () {
return changeOrder === 0 && openChangeWhiteList;
},
callback: function (key, opt) {
changeSpreadObj.add();
},
},
'batchInsert': {
name: '批量添加空白清单',
type: 'batchInsert',
value: '2',
icon: 'fa-sign-in',
visible: function () {
return changeOrder === 0 && openChangeWhiteList;
},
batchInsert: function (obj, root) {
if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
obj.value = obj.max;
toastr.warning('批量添加不可多于' + obj.max);
} else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
obj.value = obj.min;
toastr.warning('批量添加不可少于' + obj.min);
} else {
// treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
changeSpreadObj.batchAdd(obj.value);
root.$menu.trigger('contextmenu:hide');
}
},
},
'createList1': {
name: '插入台账清单',
icon: 'fa-sign-in',
visible: function () {
return changeOrder === 1;
},
// disabled: function (key, opt) {
// const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
// const sel = changeSpreadSheet.getSelections()[0];
// changeSpreadObj.resetXmjSpread(select);
// // console.log(select, sel);
// if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
// return false;
// } else {
// return true;
// }
// },
callback: function (key, opt) {
// $('#addlist').modal('show');
$('#set-site-btn').click();
},
},
'createAdd1': {
name: '插入空白清单',
icon: 'fa-sign-in',
visible: function () {
return changeOrder === 1 && openChangeWhiteList;
},
// disabled: function (key, opt) {
// const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
// const sel = changeSpreadSheet.getSelections()[0];
// changeSpreadObj.resetXmjSpread(select);
// // console.log(select, sel);
// if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
// return false;
// } else {
// return true;
// }
// },
callback: function (key, opt) {
changeSpreadObj.add();
},
},
'batchInsert1': {
name: '批量插入空白清单',
type: 'batchInsert',
value: '2',
icon: 'fa-sign-in',
visible: function () {
return changeOrder === 1 && openChangeWhiteList;
},
// disabled: function (key, opt) {
// const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
// const sel = changeSpreadSheet.getSelections()[0];
// changeSpreadObj.resetXmjSpread(select);
// // console.log(select, sel);
// if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
// return false;
// } else {
// return true;
// }
// },
batchInsert: function (obj, root) {
if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
obj.value = obj.max;
toastr.warning('批量插入不可多于' + obj.max);
} else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
obj.value = obj.min;
toastr.warning('批量插入不可少于' + obj.min);
} else {
// treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
changeSpreadObj.batchAdd(obj.value);
root.$menu.trigger('contextmenu:hide');
}
},
},
'delete': {
name: '删除',
icon: 'fa-remove',
callback: function (key, opt) {
changeSpreadObj.del();
},
disabled: function (key, opt) {
const selection = changeSpreadSheet.getSelections();
const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
const row = sel ? sel.row : -1;
if (readOnly || row === -1 || sel.row + sel.rowCount > changeSpreadSheet.zh_data.length) {
return true;
}
const first = changeSpreadSheet.zh_data[row];
let valid = true;
if (sel.rowCount > 1 && first) {
for (let r = 1; r < sel.rowCount; r++) {
const rNode = changeSpreadSheet.zh_data[sel.row + r];
if (!rNode || !rNode.id) {
valid = false;
break;
}
if (_.find(changeUsedData, { cbid: rNode.id }) || checkIsSettle(rNode)) {
valid = false;
break;
}
}
}
return !(first && first.id && !_.find(changeUsedData, { cbid: first.id }) && !checkIsSettle(first) && valid);
}
},
sprEdit: '----',
'allNotValuation': {
name: '设置全部清单不计价',
icon: 'fa-magic',
callback: function (key, opt) {
changeSpreadObj.setAllValuation(0);
},
},
'allValuation': {
name: '设置全部清单计价',
icon: 'fa-magic',
callback: function (key, opt) {
changeSpreadObj.setAllValuation(1);
},
},
}
});
// 右键菜单
$.contextMenu({
selector: '#xmj-spread',
build: function ($trigger, e) {
const target = SpreadJsObj.safeRightClickSelection($trigger, e, xmjSpread);
return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
},
items: {
'delete': {
name: '删除',
icon: 'fa-remove',
callback: function (key, opt) {
xmjSpreadObj.del();
},
disabled: function (key, opt) {
const selection = xmjSheet.getSelections();
const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
const row = sel && sel.row !== undefined ? sel.row : -1;
if (readOnly || row === -1 || sel.row + sel.rowCount > xmjSheet.zh_data.length) {
return true;
}
let isUsed = false;
for (let r = 0; r < sel.rowCount; r++) {
const select = xmjSheet.zh_data[row + r];
if(!select || _.find(changeUsedData, { cbid: select.id })) {
isUsed = true;
}
if (checkIsSettle(select)) {
isUsed = true;
}
}
return isUsed;
}
},
sprEdit: '----',
'allNotValuation': {
name: '设置全部不计价',
icon: 'fa-magic',
callback: function (key, opt) {
xmjSpreadObj.setAllValuation(0);
},
disabled: function (key, opt) {
const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (select.children && select.children.length > 0) {
return false;
} else {
return true;
}
}
},
'allValuation': {
name: '设置全部计价',
icon: 'fa-magic',
callback: function (key, opt) {
xmjSpreadObj.setAllValuation(1);
},
disabled: function (key, opt) {
const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (select.children && select.children.length > 0) {
return false;
} else {
return true;
}
}
},
}
});
}
const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
const ledgerSheet = ledgerSpread.getActiveSheet();
const ledgerSpreadSetting = {
cols: [
{title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', getValue: 'getValue.is_valuation', readOnly: 'readOnly.isValuation'},
{title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree' },
{title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
{title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
{title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
{title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: 'readOnly.isEdit2'},
{title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
{title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', visible: openChangeState},
{title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
{title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
{title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
],
emptyRows: 0,
headRows: 2,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
// readOnly: true,
rowHeader:[
{
rowHeaderType: 'circle',
setting: {
size: 5,
indent: 16,
getColor: function (index, data) {
if (!data) return;
if ((!data.clid && data.id && (_.findIndex(changeLedgerList, { id: data.id }) !== -1 || _.findIndex(changePosList, { lid: data.id }) !== -1))
|| (data.clid && data.gcl_id && _.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1)) {
return '#dc3545';
}
if (data.lid == 0) {
return '#007bff';
}
if (data.clid && data.gcl_id) {
return '#28a745';
}
if (data.clid && !data.gcl_id && data.lid != 0) {
return '#ffc107';
}
if(data.lid != 0) return;
return '#007bff';
}
},
},
],
// localCache: {
// key: 'changes-ledger-spread',
// colWidth: true,
// }
};
if (readOnly) {
ledgerSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
ledgerSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
for (const aid of aidList) {
// const userinfo = _.find(auditList2, { 'uid': aid });
const audit = _.find(auditors2, function(item){
return _.findIndex(item, { audit_order: aid }) !== -1;
});
const newColcount = {
title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
colSpan: '2|1', rowSpan: '1|1',
field: 'audit_amount_' + aid,
hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
};
const newColTp = {
title: '|金额',
colSpan: '|1', rowSpan: '|1',
field: 'sa_tp_' + aid,
hAlign: 2, width: 80, type: 'Number',
};
ledgerSpreadSetting.cols.push(newColcount);
ledgerSpreadSetting.cols.push(newColTp);
}
}
ledgerSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'changed_amount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'});
ledgerSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
const ledgerCol = {
getValue: {
is_valuation: function (data) {
return data.is_valuation === 1;
},
unit_price: function(data) {
return ZhCalc.round(data.unit_price, unitPriceUnit);
},
oa_tp: function (data) {
return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit) : data.oa_tp;
},
ca_tp: function (data) {
return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit) : data.ca_tp;
},
oamount2: function (data) {
return ZhCalc.round(data.oamount2, findDecimal(data.unit));
},
camount: function (data) {
return ZhCalc.round(data.camount, findDecimal(data.unit));
},
samount: function (data) {
return ZhCalc.round(data.samount, findDecimal(data.unit));
},
sa_tp: function (data) {
return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit) : data.sa_tp;
},
changed_amount: function (data) {
return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
},
changed_tp: function (data) {
return data.clid ? ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit)) : data.changed_tp;
},
},
readOnly: {
isEdit: function (data) {
return !(!readOnly && data.clid);
},
isEdit2: function (data) {
return !(!readOnly && data.lid == 0 && data.clid);
},
isValuation: function (data) {
return !(!readOnly && data.clid && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
},
isSettle: function (data) {
return !((!readOnly || shenpiPower) && data.clid && !checkIsSettle(data));
},
isSettle2: function (data) {
return !(!readOnly && data.clid && !checkIsSettle(data));
}
},
};
sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
SpreadJsObj.initSheet(ledgerSheet, ledgerSpreadSetting);
// 初始化 节点树结构
const treeSetting = {
id: 'ledger_id',
pid: 'ledger_pid',
order: 'order',
level: 'level',
rootId: -1,
keys: ['id', 'tender_id', 'ledger_id'],
calcFields: ['oa_tp', 'ca_tp', 'sa_tp', 'changed_tp', 'total_price'],
autoExpand: 3,
markExpandKey: 'change-bills-expand',
markExpandSubKey: window.location.pathname.split('/')[2],
};
if (readOnly) {
for (const aid of aidList) {
treeSetting.calcFields.push('sa_tp_' + aid);
}
}
treeSetting.calcFun = function (node) {
if (node && node.b_code) {
const posData = pos.getLedgerPos(node.id) || [];
if (!node.clid && posData.length > 0) {
let is_valuation = 1;
let oamount2 = 0;
let camount = 0;
let samount = 0;
let spamount = 0;
if (readOnly) {
for (const aid of aidList) {
let audit_amount = 0;
for (const np of posData) {
audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(np['audit_amount_' + aid], findDecimal(node.unit)));
}
if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
node['audit_amount_' + aid] = audit_amount;
node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
}
}
}
for (const np of posData) {
oamount2 = ZhCalc.add(oamount2, ZhCalc.round(np.oamount2, findDecimal(node.unit)));
camount = ZhCalc.add(camount, ZhCalc.round(np.camount, findDecimal(node.unit)));
samount = ZhCalc.add(samount, ZhCalc.round(np.samount, findDecimal(node.unit)));
spamount = ZhCalc.add(spamount, ZhCalc.round(np.spamount, findDecimal(node.unit)));
if (np.is_valuation === 0) is_valuation = 0;
}
if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
node.oamount2 = oamount2;
node.camount = camount;
node.samount = samount;
node.spamount = spamount;
node.change_amount = ZhCalc.add(oamount2, camount);
node.oa_tp = ZhCalc.round(ZhCalc.mul(oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.ca_tp = ZhCalc.round(ZhCalc.mul(camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.sa_tp = ZhCalc.round(ZhCalc.mul(samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
const spa_tp = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
}
node.is_valuation = is_valuation;
} else if (node.clid) {
// node.oamount2 = ZhCalc.round(node.oamount2, findDecimal(node.unit));
// node.camount = ZhCalc.round(node.camount, findDecimal(node.unit));
// node.change_amount = ZhCalc.add(node.oamount2, node.camount);
node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
if (readOnly) {
for (const aid of aidList) {
node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
}
}
}
}
};
const ledgerTree = createNewPathTree('revise', treeSetting);
const ledgerTreeSpreadObj = {
loadExprToInput: function () {
const sel = ledgerSheet.getSelections()[0];
if (!sel) return;
const col = ledgerSheet.zh_setting.cols[sel.col];
const data = SpreadJsObj.getSelectObject(ledgerSheet);
if (col && col.field === 'camount' && data && data.clid) {
if (!readOnly) {
$('#ledger-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
} else {
$('#ledger-camount-expr').attr('readonly', true).val(data.camount_expr ? data.camount_expr : data.camount);
}
} else {
$('#ledger-camount-expr').attr('readonly', true).val('');
}
},
showHideAudit: function (show = false) {
if (shenpiPower) {
show = true;
}
if (readOnly) {
const count = ledgerSpreadSetting.cols.length;
for (let i = startLimit + 5; i < count - 2; i++) {
ledgerSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
}
ledgerSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
ledgerSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
}
},
/**
*
* @param sheet
* @param data
*/
refreshTree: function (sheet, data) {
SpreadJsObj.massOperationSheet(sheet, function () {
const tree = sheet.zh_tree;
// 处理删除
if (data.delete) {
data.delete.sort(function (a, b) {
return b.deleteIndex - a.deleteIndex;
});
for (const d of data.delete) {
sheet.deleteRows(d.deleteIndex, 1);
}
}
// 处理新增
if (data.create) {
const newNodes = data.create;
if (newNodes) {
newNodes.sort(function (a, b) {
return a.index - b.index;
});
for (const node of newNodes) {
sheet.addRows(node.index, 1);
SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
}
}
}
// 处理更新
if (data.update) {
const rows = [];
for (const u of data.update) {
rows.push(tree.nodes.indexOf(u));
}
SpreadJsObj.reLoadRowsData(sheet, rows);
}
// 处理展开
if (data.expand) {
const expanded = [];
for (const e of data.expand) {
if (expanded.indexOf(e) === -1) {
const posterity = tree.getPosterity(e);
for (const p of posterity) {
sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
expanded.push(p);
}
}
}
}
});
},
topRowChanged: function (e, info) {
SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
},
selectionChanged: function (e, info) {
if (info.newSelections) {
if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
// ledgerTreeSpreadObj.refreshOperationValid(info.sheet);
ledgerTreeSpreadObj.refreshPosData();
}
}
ledgerTreeSpreadObj.loadExprToInput(info.sheet);
},
refreshPosData: function() {
SpreadJsObj.resetTopAndSelect(posSheet);
posSpreadObj.loadCurPosData();
SpreadJsObj.saveTopAndSelect(ledgerSheet, ckBillsSpread);
// posSearch.search($('#pos-keyword').val());
},
getDefaultSelectInfo: function (sheet) {
const tree = sheet.zh_tree;
if (!tree) return;
const sel = sheet.getSelections()[0];
const node = sheet.zh_tree.nodes[sel.row];
if (!node) return;
let count = 1;
if (sel.rowCount > 1) {
for (let r = 1; r < sel.rowCount; r++) {
const rNode = sheet.zh_tree.nodes[sel.row + r];
if (rNode.level > node.level) continue;
if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
toastr.warning('请选择同一节点下的节点,进行该操作');
return;
}
count += 1;
}
}
return [tree, node, count];
},
_checkExprValid(expr) {
if (!expr) return [true, null];
const param = [];
let num = '', base = '';
for (let i = 0, iLen = expr.length; i < iLen; i++) {
if (/^[\d\.%]+/.test(expr[i])) {
if (base !== '') {
param.push({type: 'base', value: base});
base = '';
}
num = num + expr[i];
} else if (expr[i] === '(') {
if (num !== '') {
param.push({type: 'num', value: num});
num = '';
}
if (base !== '') {
param.push({type: 'base', value: base});
base = '';
}
param.push({type: 'left', value: '('});
} else if (expr[i] === ')') {
if (num !== '') {
param.push({type: 'num', value: num});
num = '';
}
if (base !== '') {
param.push({type: 'base', value: base});
base = '';
}
param.push({type: 'right', value: ')'});
} else if (/^[\+\-*\/]/.test(expr[i])) {
if (num !== '') {
param.push({type: 'num', value: num});
num = '';
}
if (base !== '') {
param.push({type: 'base', value: base});
base = '';
}
param.push({type: 'calc', value: expr[i]});
} else {
return [false, '输入的表达式含有非法字符: ' + expr[i]];
}
}
if (num !== '') {
param.push({type: 'num', value: num});
num = '';
}
if (base !== '') {
param.push({type: 'base', value: base});
base = '';
}
if (param.length === 0) return true;
if (param.length > 1) {
if (param[0].value === '-' && param[1].type === 'num') {
param[1].value = '-' + param[1].value;
param.shift();
}
}
const iLen = param.length;
let iLeftCount = 0, iRightCount = 0;
for (const [i, p] of param.entries()) {
if (p.type === 'calc') {
if (i === 0 || i === iLen - 1)
return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
}
if (p.type === 'num') {
num = p.value.replace('%', '');
if (p.value.length - num.length > 1)
return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
num = _.toNumber(num);
if (num === undefined || num === null || _.isNaN(num))
return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
if (i > 0) {
if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
} else if (param[i - 1].value === '/' && num === 0) {
return [false, '输入的表达式非法:请勿除0'];
}
}
}
if (p.type === 'base') {
if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
}
if (p.type === 'left') {
iLeftCount += 1;
if (i !== 0 && param[i-1].type !== 'calc')
return [false, '输入的表达式非法:(前应有运算符'];
}
if (p.type === 'right') {
iRightCount += 1;
if (i !== iLen - 1 && param[i+1].type !== 'calc')
return [false, '输入的表达式非法:)后应有运算符'];
if (iRightCount > iLeftCount)
return [false, '输入的表达式非法:")"前无对应的"("'];
}
}
if (iLeftCount > iRightCount)
return [false, '输入的表达式非法:"("后无对应的")"'];
return [true, ''];
},
_checkExpr: function (text, data) {
if (text) {
const num = _.toNumber(text);
if (num) {
data.quantity = num;
data.expr = '';
} else {
const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
const [valid, msg] = this._checkExprValid(expr);
if (!valid) return [valid, msg];
data.expr = expr;
data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
// const ce = new CalcEvalMin();
// data.quantity = ce.eval(expr);
// console.log(data.quantity);
}
} else {
data.quantity = 0;
data.expr = '';
}
return [true, ''];
},
}
ledgerSpread.bind(spreadNS.Events.SelectionChanged, ledgerTreeSpreadObj.selectionChanged);
ledgerSpread.bind(spreadNS.Events.topRowChanged, ledgerTreeSpreadObj.topRowChanged);
// 初始化 计量单元
const pos = new PosData({ id: 'id', ledgerId: 'lid' });
const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
const posSheet = posSpread.getActiveSheet();
const posSpreadSetting = {
cols: [
{title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
{title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true},
{title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
{title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
{title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
{title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
],
emptyRows: 0,
headRows: 2,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
rowHeader:[
{
rowHeaderType: 'circle',
setting: {
size: 5,
indent: 16,
getColor: function (index, data) {
if (!data) return;
if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
return '#dc3545';
}
if(data.lid != 0) return;
return '#007bff';
}
},
},
],
};
if (readOnly) {
posSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
for (const aid of aidList) {
// const userinfo = _.find(auditList2, { 'uid': aid });
const audit = _.find(auditors2, function(item){
return _.findIndex(item, { audit_order: aid }) !== -1;
});
const newColcount = {
title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
colSpan: '1|1', rowSpan: '|1',
field: 'audit_amount_' + aid,
hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
};
posSpreadSetting.cols.push(newColcount);
}
}
posSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
const posCol = {
getValue: {
oamount2: function (data) {
return ZhCalc.round(data.oamount2, findDecimal(data.unit));
},
camount: function (data) {
return ZhCalc.round(data.camount, findDecimal(data.unit));
},
samount: function (data) {
return ZhCalc.round(data.samount, findDecimal(data.unit));
},
changed_amount: function (data) {
return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
},
},
readOnly: {
isEdit: function (data) {
return readOnly;
},
isValuation: function (data) {
return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
},
isSettle: function (data) {
return !((!readOnly || shenpiPower) && !checkIsSettle(data));
},
isSettle2: function (data) {
return !(!readOnly && !checkIsSettle(data));
}
},
}
sjsSettingObj.setGridSelectStyle(posSpreadSetting);
SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
SpreadJsObj.initSheet(posSheet, posSpreadSetting);
// 计量单元 相关方法&绑定spreadjs事件
const posSpreadObj = {
loadExprToInput: function () {
const sel = posSheet.getSelections()[0];
if (!sel) return;
const col = posSheet.zh_setting.cols[sel.col];
const data = SpreadJsObj.getSelectObject(posSheet);
if (col && col.field === 'camount' && data) {
if (readOnly) {
$('#pos-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
} else {
$('#pos-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
}
} else {
$('#pos-camount-expr').attr('readonly', true).val('');
}
},
/**
* 加载计量单元 根据当前台账选择节点
*/
loadCurPosData: function () {
const node = SpreadJsObj.getSelectObject(ledgerSheet);
if (node) {
const posData = pos.getLedgerPos(node.id) || [];
console.log(posData);
SpreadJsObj.loadSheetData(posSheet, 'data', posData);
} else {
SpreadJsObj.loadSheetData(posSheet, 'data', []);
}
posSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
SpreadJsObj.resetTopAndSelect(posSheet);
posSpreadObj.loadExprToInput();
},
selectionChanged: function (e, info) {
posSpreadObj.loadExprToInput();
},
showHideAudit: function (show = false) {
if (shenpiPower) {
show = true;
}
if (readOnly) {
const posStartLimit = 4;
const count = posSpreadSetting.cols.length;
for (let i = posStartLimit + 2; i < count - 1; i++) {
posSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
}
posSheet.setColumnVisible(posStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
}
},
}
posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
if (!readOnly) {
// 台账修改
ledgerTreeSpreadObj.del = function () {
const self = this;
const [tree, node, count] = this.getDefaultSelectInfo(ledgerSheet);
if (!tree || !node || !count) return;
const delList = [];
let lastSelect = null;
let hadTaiZhang = false;
const selects = [];
const parent = tree.getParent(node);
const children = parent ? parent.children : tree.children;
const index = children.indexOf(node);
for (let r = 0; r < count; r++) {
const select = children[r+index];
if (!select || _.find(changeUsedData, { cbid: select.clid })) {
toastr.error('已调用的变更清单不能删除');
return false;
}
if (checkIsSettle(select)) {
toastr.error('已结算的变更清单不能删除');
return false;
}
if (r === count - 1 && changeOrder) {
lastSelect = select;
}
if (select.lid != 0) {
hadTaiZhang = true;
}
delList.push(select.clid);
selects.push(select);
}
if (delList.length) {
postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
const loadResult = {
delete: selects,
}
// 判断父节点是否也要移除
if (children.length === count) {
loadResult.delete.push(parent);
const parentNodes = _.reverse(ledgerTree.getAllParents(parent));
for (const node of parentNodes) {
if (node.children && node.children.length === 1) {
loadResult.delete.push(node);
} else {
break;
}
}
}
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
ledgerSheet.setSelection(0, 0, 1, 1);
ledgerTreeSpreadObj.refreshPosData();
});
}
};
ledgerTreeSpreadObj.editStarting = function (e, info) {
const select = SpreadJsObj.getSelectObject(ledgerSheet);
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'camount') {
if (select.camount_expr && select.camount_expr !== '') {
info.sheet.getCell(info.row, info.col).text(select.camount_expr);
}
}
};
ledgerTreeSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
return;
}
const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
const select = sortData[info.row];
if (!select || !select.clid) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
let orgValue;
if (col.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
} else {
orgValue = select[col.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if(col.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: select.clid });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
cInfo.spamount = select.spamount;
cInfo.camount_expr = exprQuantity.expr;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (col.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
}
if (col.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('计量上限默认值只能输入0-100之间的整数');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: select.clid });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
if (validText < minLimit) {
toastr.error('计量上限值至少大于等于 ' + minLimit);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
}
}
}
if (col.field === 'unit') {
select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
select.oamount2 = ZhCalc.round(select.oamount2, findDecimal(validText)) || 0;
cInfo.camount = select.camount;
cInfo.oamount2 = select.oamount2;
}
if (col.field === 'b_code') {
cInfo.code = validText;
} else {
cInfo[col.field] = validText;
}
select[col.field] = validText;
console.log(cInfo);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
const loadResult = {
update: [select],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
ledgerTreeSpreadObj.loadExprToInput();
}, function () {
select[col.field] = orgValue;
if (col.field === 'b_code') {
cInfo.code = orgValue;
} else {
cInfo[col.field] = orgValue;
}
if(col.field === 'camount') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
};
ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
const tree = info.sheet.zh_tree;
if (!tree) { return; }
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_tree.nodes;
const selects = [];
const data = [];
let needCopyIgnore = !$('#customCheck1').is(':checked');
let needColAdd = false;
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
const node = sortData[curRow];
if (!node) {
continue;
}
const cLData = { id: sortData[curRow].clid };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if ((needColAdd && curCol > 6) || (needCopyIgnore && curCol === 6)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
const newCurCol = curCol + 1;
needColAdd = true;
colSetting = info.sheet.zh_setting.cols[newCurCol];
}
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue;
if (colSetting.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
: (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
} else {
orgValue = sortData[curRow][colSetting.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if(colSetting.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastMessageUniq(getPasteHint(msg, hintRow));
bPaste = false;
continue;
}
if (isNaN(exprQuantity.quantity)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
cLData.camount_expr = exprQuantity.expr;
sortData[curRow].camount_expr = exprQuantity.expr;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
if (colSetting.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
}
if (colSetting.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
bPaste = false;
continue;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
if (validText < minLimit) {
toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
bPaste = false;
continue;
}
}
}
}
let unitdecimal = validText;
if (colSetting.field === 'unit') {
//粘贴内容要为下拉列表里所有的单位,不然为空
if (changeUnits.indexOf(validText) === -1) {
unitdecimal = '';
}
cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
cLData.oamount2 = ZhCalc.round(sortData[curRow].oamount2, findDecimal(unitdecimal)) || 0;
}
if (colSetting.field === 'b_code') {
cLData.code = validText;
} else {
cLData[colSetting.field] = validText;
}
sortData[curRow][colSetting.field] = validText;
cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
sortData[curRow].spamount = cLData.spamount;
}
if (bPaste) {
data.push(cLData);
selects.push(sortData[curRow]);
} else {
SpreadJsObj.reLoadRowData(info.sheet, curRow);
}
}
if (data.length === 0) {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data, selects);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
changeList = result;
const loadResult = {
update: selects,
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
ledgerTreeSpreadObj.loadExprToInput();
}, function () {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
ledgerTreeSpreadObj.buttonClicked = function(e, info) {
if (info.sheet.zh_setting) {
const select = SpreadJsObj.getSelectObject(info.sheet);
if (!select || !select.clid) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
if (info.sheet.isEditing()) {
info.sheet.endEdit(true);
}
if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
return;
}
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
cInfo.is_valuation = select.is_valuation;
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
const loadResult = {
update: [select],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
}, function () {
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
cInfo.is_valuation = select.is_valuation;
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
}
}
};
ledgerTreeSpreadObj.valueChanged = function(e, info) {
// 防止ctrl+z撤销数据
SpreadJsObj.reLoadRowData(info.sheet, info.row);
};
ledgerTreeSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
const selects = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_tree.nodes[iRow];
const cInfo = _.find(changeList, { id: node.clid });
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'camount' || col.field === 'oamount2') {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field === 'camount') {
node.camount_expr = '';
node.spamount = null;
cInfo.camount_expr = '';
cInfo.spamount = null;
}
delete cInfo.waitingLoading;
bDel = true;
}
}
if (bDel) {
datas.push(cInfo);
selects.push(node);
}
}
console.log(datas, selects);
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
changeList = result;
const loadResult = {
update: selects,
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
ledgerTreeSpreadObj.loadExprToInput();
}, function () {
SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
// 表达式判断
$('#ledger-camount-expr').change(function () {
if (this.readOnly) return;
let validText = $(this).val();
const sel = ledgerSheet.getSelections()[0];
const row = sel ? sel.row : -1;
const col = ledgerSheet.zh_setting.cols[sel.col];
if (row === -1 || !(col && col.field === 'camount')) return;
const select = SpreadJsObj.getSelectObject(ledgerSheet);
if (!select || !select.clid) return;
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) return;
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
const orgExprValue = _.clone(select.camount_expr);
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
return;
}
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
select.camount = validText;
cInfo.spamount = select.spamount;
cInfo.camount_expr = select.camount_expr;
cInfo.camount = validText;
// console.log(select);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
const loadResult = {
update: [select],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
}, function () {
select.camount = orgValue;
select.camount_expr = orgExprValue;
select.spamount = orgValue;
cInfo.camount = orgValue;
cInfo.camount_expr = orgExprValue;
cInfo.spamount = orgValue;
SpreadJsObj.reLoadRowData(posSheet, row);
});
});
ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
ledgerSpread.bind(spreadNS.Events.EditStarting, ledgerTreeSpreadObj.editStarting);
ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
ledgerSpread.bind(spreadNS.Events.ValueChanged, ledgerTreeSpreadObj.valueChanged);
ledgerSpread.bind(spreadNS.Events.ButtonClicked, ledgerTreeSpreadObj.buttonClicked);
SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
// 计量单元修改
posSpreadObj.del = function () {
const selection = posSheet.getSelections();
const sel = selection ? selection[0] : posSheet.getSelections()[0];
const row = sel && sel.row !== undefined ? sel.row : -1;
const count = sel.rowCount;
if (readOnly || row === -1 || row + count > posSheet.zh_data.length) {
return false;
}
const delList = [];
let lastSelect = null;
let hadTaiZhang = false;
const selects = [];
for (let r = 0; r < count; r++) {
const select = posSheet.zh_data[row + r];
if(!select || _.find(changeUsedData, { cbid: select.clid })) {
toastr.error('已调用的变更清单不能删除');
return false;
}
if (checkIsSettle(select)) {
toastr.error('已结算的变更清单不能删除');
return false;
}
if (r === count - 1 && changeOrder) {
lastSelect = select;
}
if (select.lid != 0) {
hadTaiZhang = true;
}
delList.push(select.clid);
selects.push(select.id);
}
if (delList.length) {
postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
pos.removeDatas(selects);
posSheet.deleteRows(row, count);
const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {};
// 判断是移除还是更新数量和金额
if (posSheet.zh_data.length === 0) {
// 判断父节点是否也要移除
const parentNodes = _.reverse(ledgerTree.getAllParents(billsNode));
loadResult.delete = [billsNode];
for (const node of parentNodes) {
if (node.children && node.children.length === 1) {
loadResult.delete.push(node);
} else {
break;
}
}
} else {
loadResult.update = [billsNode];
}
if (loadResult.update || loadResult.delete) {
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
if (loadResult.delete) {
ledgerSheet.setSelection(0, 0, 1, 1);
ledgerTreeSpreadObj.refreshPosData();
}
}
});
}
};
posSpreadObj.editStarting = function (e, info) {
posSpreadObj.billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
const col = info.sheet.zh_setting.cols[info.col];
const select = SpreadJsObj.getSelectObject(info.sheet);
if (col.field === 'camount') {
if (select.camount_expr && select.camount_expr !== '') {
info.sheet.getCell(info.row, info.col).text(select.camount_expr);
}
}
};
posSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
return;
}
let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
let orgValue;
if (col.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
} else {
orgValue = select[col.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const node = posSpreadObj.billsNode;
if (!node) {
toastr.error('数据错误,请选择台账节点后再试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if(col.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: select.clid });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
cInfo.spamount = select.spamount;
cInfo.camount_expr = exprQuantity.expr;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (col.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
}
if (col.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('计量上限默认值只能输入0-100之间的整数');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: select.clid });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
if (validText < minLimit) {
toastr.error('计量上限值至少大于等于 ' + minLimit);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
console.log(cInfo);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
const loadResult = {
update: [node],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
posSpreadObj.loadExprToInput();
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if(col.field === 'camount') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
};
posSpreadObj.clipboardPasted = function (e, info) {
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_data || [];
if (range.row + range.rowCount > sortData.length) {
toastMessageUniq(hint.cellError);
// SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
posSpreadObj.loadCurPosData();
return;
}
if (sortData.length > 0 && range.col + range.colCount > 6) {
toastMessageUniq(hint.cellError);
posSpreadObj.loadCurPosData();
return;
}
if (!info.sheet.zh_setting) {
posSpreadObj.loadCurPosData();
return;
}
const data = [];
// const rowData = [];
let needCopyIgnore = !$('#customCheck1').is(':checked');
let needColAdd = false;
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
// const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
const cLData = { id: sortData[curRow].clid };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
const newCurCol = curCol + 1;
needColAdd = true;
colSetting = info.sheet.zh_setting.cols[newCurCol];
}
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue;
if (colSetting.field === 'camount') {
orgValue = validText && validText !== ''
? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
: (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
} else {
orgValue = sortData[curRow][colSetting.field];
}
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if(colSetting.field === 'camount') {
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastMessageUniq(getPasteHint(msg, hintRow));
bPaste = false;
continue;
}
if (isNaN(exprQuantity.quantity)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
cLData.camount_expr = exprQuantity.expr;
sortData[curRow].camount_expr = exprQuantity.expr;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
if (colSetting.field === 'unit_price') {
validText = ZhCalc.round(validText, unitPriceUnit);
} else {
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
}
if (colSetting.field === 'delimit') {
const reg = /^(\d{1,2}|100)$/;
if (!(_.isNumber(validText) && reg.test(validText))) {
toastr.error('计量单元第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
bPaste = false;
continue;
}
// 需要判断是否已调用,已调用的则不能低于原有值大小
const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
if (usedInfo && usedInfo.qty) {
const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
if (validText < minLimit) {
toastr.error('计量单元第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
bPaste = false;
continue;
}
}
}
}
let unitdecimal = validText;
cLData[colSetting.field] = validText;
sortData[curRow][colSetting.field] = validText;
cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
}
if (bPaste) {
data.push(cLData);
// rowData.push(curRow);
} else {
SpreadJsObj.reLoadRowData(info.sheet, curRow);
}
}
if (data.length === 0) {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
changeList = result;
const node = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {
update: [node],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
posSpreadObj.loadCurPosData();
}, function () {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
posSpreadObj.buttonClicked = function(e, info) {
if (info.sheet.zh_setting) {
const select = SpreadJsObj.getSelectObject(info.sheet);
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
if (col.field === 'is_valuation') {
if (info.sheet.isEditing()) {
info.sheet.endEdit(true);
}
if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
return;
}
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
cInfo.is_valuation = select.is_valuation;
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
const node = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {
update: [node],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
}, function () {
select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
cInfo.is_valuation = select.is_valuation;
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
}
}
};
posSpreadObj.valueChanged = function(e, info) {
// 防止ctrl+z撤销数据
SpreadJsObj.reLoadRowData(info.sheet, info.row);
};
posSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_data[iRow];
const cInfo = _.find(changeList, { id: node.clid });
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'camount' || col.field === 'oamount2') {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field === 'camount') {
node.camount_expr = '';
node.spamount = null;
cInfo.camount_expr = '';
cInfo.spamount = null;
}
delete cInfo.waitingLoading;
bDel = true;
}
}
if (bDel) datas.push(cInfo);
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
changeList = result;
const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {
update: [billsNode],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
posSpreadObj.loadCurPosData();
}, function () {
SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
// 表达式判断
$('#pos-camount-expr').change(function () {
if (this.readOnly) return;
let validText = $(this).val();
const sel = posSheet.getSelections()[0];
const row = sel ? sel.row : -1;
const col = posSheet.zh_setting.cols[sel.col];
if (row === -1 || !(col && col.field === 'camount')) return;
const select = SpreadJsObj.getSelectObject(posSheet);
if (!select) return;
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) return;
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
let orgValue = validText && validText !== ''
? (_.toNumber(validText) ? select.camount : select.camount_expr)
: (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
const orgExprValue = _.clone(select.camount_expr);
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
return;
}
const exprQuantity = {
expr: '',
quantity: 0,
};
const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
if (!valid) {
toastr.error(msg);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
if (isNaN(exprQuantity.quantity)) {
toastr.error('不能输入其它非数字类型字符');
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
validText = parseFloat(exprQuantity.quantity);
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
$(this).val(select.camount_expr ? select.camount_expr : select.camount);
return;
}
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.camount_expr = exprQuantity.expr;
select.camount = validText;
cInfo.spamount = select.spamount;
cInfo.camount_expr = select.camount_expr;
cInfo.camount = validText;
// console.log(select);
delete cInfo.waitingLoading;
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
SpreadJsObj.reLoadRowData(posSheet, row);
const node = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {
update: [node],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
}, function () {
select.camount = orgValue;
select.camount_expr = orgExprValue;
select.spamount = orgValue;
cInfo.camount = orgValue;
cInfo.camount_expr = orgExprValue;
cInfo.spamount = orgValue;
SpreadJsObj.reLoadRowData(posSheet, row);
});
});
posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
posSpread.bind(spreadNS.Events.ValueChanged, posSpreadObj.valueChanged);
posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
// 右键菜单
$.contextMenu({
selector: '#ledger-spread',
build: function ($trigger, e) {
const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
},
items: {
'delete': {
name: '删除',
icon: 'fa-remove',
callback: function (key, opt) {
ledgerTreeSpreadObj.del();
},
disabled: function (key, opt) {
const selection = ledgerSheet.getSelections();
const sel = selection ? selection[0] : ledgerSheet.getSelections()[0];
const row = sel ? sel.row : -1;
const tree = ledgerSheet.zh_tree;
if (!tree) return true;
const first = ledgerSheet.zh_tree.nodes[row];
let last = first, sameParent = true, listValid = true;
if (sel.rowCount > 1 && first) {
for (let r = 1; r < sel.rowCount; r++) {
const rNode = tree.nodes[sel.row + r];
if (!rNode) {
sameParent = false;
break;
}
if (!rNode.clid) {
listValid = false;
break;
}
if (_.find(changeUsedData, { cbid: rNode.clid }) || checkIsSettle(rNode)) {
listValid = false;
break;
}
if (rNode.level > first.level) continue;
if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
sameParent = false;
break;
}
last = rNode;
}
}
const valid = !ledgerSheet.zh_setting.readOnly;
return !(valid && first && first.clid && !_.find(changeUsedData, { cbid: first.clid }) && !checkIsSettle(first) && sameParent && listValid);
}
},
// sprEdit: '----',
// 'allNotValuation': {
// name: '设置全部清单不计价',
// icon: 'fa-magic',
// callback: function (key, opt) {
// changeSpreadObj.setAllValuation(0);
// },
// },
// 'allValuation': {
// name: '设置全部清单计价',
// icon: 'fa-magic',
// callback: function (key, opt) {
// changeSpreadObj.setAllValuation(1);
// },
// },
}
});
// 右键菜单
$.contextMenu({
selector: '#pos-spread',
build: function ($trigger, e) {
const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
},
items: {
'delete': {
name: '删除',
icon: 'fa-remove',
callback: function (key, opt) {
posSpreadObj.del();
},
disabled: function (key, opt) {
const selection = posSheet.getSelections();
const sel = selection ? selection[0] : posSheet.getSelections()[0];
const row = sel && sel.row !== undefined ? sel.row : -1;
if (readOnly || row === -1 || sel.row + sel.rowCount > posSheet.zh_data.length) {
return true;
}
let isUsed = false;
for (let r = 0; r < sel.rowCount; r++) {
const select = posSheet.zh_data[row + r];
if(!select || _.find(changeUsedData, { cbid: select.clid })) {
isUsed = true;
}
if (checkIsSettle(select)) {
isUsed = true;
}
}
return isUsed;
}
},
// sprEdit: '----',
// 'allNotValuation': {
// name: '设置全部清单不计价',
// icon: 'fa-magic',
// callback: function (key, opt) {
// changeSpreadObj.setAllValuation(0);
// },
// },
// 'allValuation': {
// name: '设置全部清单计价',
// icon: 'fa-magic',
// callback: function (key, opt) {
// changeSpreadObj.setAllValuation(1);
// },
// },
}
});
}
if (shenpiPower) {
changeSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
if (!select || !select.id) {
toastr.error('该变更清单无法编辑');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
const orgValue = select[col.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (!node) {
toastr.error('数据错误,请选择清单节点后再试');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
if (col.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {cbid: select.id});
if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
} else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
changeSpreadObj.reloadRow(info.sheet, info.row);
return;
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
if (col.field !== 'oamount2') {
cInfo.spamount = validText;
select.spamount = validText;
}
const data = {
id: select.id,
};
if (col.field === 'oamount2') {
data[col.field] = select[col.field];
} else {
data.spamount = select.spamount;
}
console.log(data, col.field);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
changeSpreadObj.calcOneSum(select);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
changeSpreadObj.refreshXmjData();
changeSpreadObj.countSum();
if (info.row === info.sheet.zh_data.length - 1) {
// console.log(info);
// changeSpreadSheet.setSelection(info.row, info.col, 1, 1);
// changeSpreadObj.reloadRow(changeSpreadSheet, info.row, 0, true);
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if (col.field !== 'oamount2') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
changeSpreadObj.reloadRow(info.sheet, info.row);
});
};
changeSpreadObj.clipboardPasted = function (e, info) {
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_data || [];
const data = [];
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
if (!sortData[curRow] || !sortData[curRow].id) {
bPaste = false;
}
const cLData = { id: sortData[curRow].id };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
const orgValue = sortData[curRow][colSetting.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
if (colSetting.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
}
}
sortData[curRow][colSetting.field] = validText;
if (colSetting.field === 'oamount2') {
cLData[colSetting.field] = validText;
} else {
cLData.spamount = validText;
sortData[curRow].spamount = validText;
}
}
if (bPaste) {
data.push(cLData);
// rowData.push(curRow);
} else {
changeSpreadObj.reloadRow(info.sheet, curRow);
}
}
if (data.length === 0) {
changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
changeList = result;
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}, function () {
changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
changeSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_data[iRow];
const cInfo = _.find(changeList, { id: node.id });
const data = { id: node.id };
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field !== 'oamount2') {
data.spamount = null;
cInfo.spamount = null;
node.spamount = null;
} else {
data[col.field] = null;
}
bDel = true;
}
}
if (bDel) datas.push(data);
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
changeList = result;
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}, function () {
changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
xmjSpreadObj.editStarting = function (e, info) {
xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
};
xmjSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
const cInfo = _.find(changeList, { id: select.id });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
const orgValue = select[col.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const node = xmjSpreadObj.billsNode;
if (!node) {
toastr.error('数据错误,请选择清单节点后再试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
if (col.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {cbid: select.id});
if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
} else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
if (col.field !== 'oamount2') {
cInfo.spamount = validText;
select.spamount = validText;
}
const data = {
id: select.id,
};
if (col.field === 'oamount2') {
data[col.field] = select[col.field];
} else {
data.spamount = select.spamount;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = info.sheet.zh_data;
changeSpreadObj.calcOneSum(node);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
changeSpreadObj.countSum();
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if (col.field !== 'oamount2') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
};
xmjSpreadObj.clipboardPasted = function (e, info) {
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (!node) {
toastr.error('数据错误,请选择清单节点后再试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_data || [];
const data = [];
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
const cLData = { id: sortData[curRow].id };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
const orgValue = sortData[curRow][colSetting.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
if (colSetting.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
}
}
sortData[curRow][colSetting.field] = validText;
if (colSetting.field === 'oamount2') {
cLData[colSetting.field] = validText;
} else {
cLData.spamount = validText;
sortData[curRow].spamount = validText;
}
}
if (bPaste) {
data.push(cLData);
// rowData.push(curRow);
} else {
SpreadJsObj.reLoadRowData(info.sheet, curRow);
}
}
if (data.length === 0) {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
changeList = result;
const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
node.children = info.sheet.zh_data;
changeSpreadObj.calcOneSum(node);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
changeSpreadObj.countSum();
xmjSpreadObj.loadCurXmjData();
}, function () {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
xmjSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
const changeNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
if (!changeNode) {
toastr.error('数据错误,请选择清单节点后再试');
SpreadJsObj.reLoadRowData(sheet, info.row);
return;
}
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_data[iRow];
const cInfo = _.find(changeList, { id: node.id });
const data = { id: node.id };
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field !== 'oamount2') {
data.spamount = null;
cInfo.spamount = null;
node.spamount = null;
} else {
data[col.field] = null;
}
bDel = true;
}
}
if (bDel) datas.push(data);
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
changeList = result;
const billIndex = _.indexOf(changeSpreadSheet.zh_data, changeNode);
changeNode.children = sheet.zh_data;
changeSpreadObj.calcOneSum(changeNode);
console.log(changeNode);
changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
changeSpreadObj.countSum();
xmjSpreadObj.loadCurXmjData();
}, function () {
SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
ledgerTreeSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
const select = sortData[info.row];
if (!select || !select.clid) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
const orgValue = select[col.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
if (col.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
} else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
if (col.field !== 'oamount2') {
cInfo.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
}
const data = {
id: cInfo.id,
};
if (col.field === 'oamount2') {
data[col.field] = select[col.field];
} else {
data.spamount = select.spamount;
}
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
const loadResult = {
update: [select],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if(col.field !== 'oamount2') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
};
ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
const tree = info.sheet.zh_tree;
if (!tree) { return; }
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_tree.nodes;
const selects = [];
const data = [];
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
const node = sortData[curRow];
if (!node) {
continue;
}
const cLData = { id: sortData[curRow].clid };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
const orgValue = sortData[curRow][colSetting.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
if (colSetting.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, curRow);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, curRow);
bPaste = false;
continue;
}
}
}
sortData[curRow][colSetting.field] = validText;
if (colSetting.field === 'oamount2') {
cLData[colSetting.field] = validText;
} else {
cLData.spamount = validText;
sortData[curRow].spamount = cLData.spamount;
}
}
if (bPaste) {
data.push(cLData);
selects.push(sortData[curRow]);
} else {
SpreadJsObj.reLoadRowData(info.sheet, curRow);
}
}
if (data.length === 0) {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data, selects);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
changeList = result;
const loadResult = {
update: selects,
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
ledgerTreeSpreadObj.loadExprToInput();
}, function () {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
ledgerTreeSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
const selects = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_tree.nodes[iRow];
const cInfo = _.find(changeList, { id: node.clid });
const data = { id: node.clid };
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field !== 'oamount2') {
data.spamount = null;
cInfo.spamount = null;
node.spamount = null;
} else {
data[col.field] = null;
}
bDel = true;
}
}
if (bDel) {
datas.push(data);
selects.push(node);
}
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
changeList = result;
const loadResult = {
update: selects,
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
ledgerTreeSpreadObj.loadExprToInput();
}, function () {
SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
posSpreadObj.editEnded = function (e, info) {
if (!info.sheet.zh_setting) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
const cInfo = _.find(changeList, { id: select.clid });
if (!cInfo) {
toastr.error('数据错误,请刷新页面重试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const col = info.sheet.zh_setting.cols[info.col];
let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
const orgValue = select[col.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
const node = SpreadJsObj.getSelectObject(ledgerSheet);
if (!node) {
toastr.error('数据错误,请选择台账节点后再试');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
if (col.type === 'Number') {
if (isNaN(validText)) {
toastr.error('不能输入其它非数字类型字符');
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
if (col.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {cbid: select.clid});
if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
} else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
SpreadJsObj.reLoadRowData(info.sheet, info.row);
return;
}
}
}
cInfo[col.field] = validText;
select[col.field] = validText;
if (col.field !== 'oamount2') {
cInfo.spamount = validText;
select.spamount = validText;
}
const data = {
id: select.clid,
};
if (col.field === 'oamount2') {
data[col.field] = select[col.field];
} else {
data.spamount = select.spamount;
}
// 更新至服务器
postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
SpreadJsObj.reLoadRowData(info.sheet, info.row);
const loadResult = {
update: [node],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
}, function () {
select[col.field] = orgValue;
cInfo[col.field] = orgValue;
if (col.field !== 'oamount2') {
select.spamount = orgValue;
cInfo.spamount = orgValue;
}
SpreadJsObj.reLoadRowData(info.sheet, info.row);
});
};
posSpreadObj.clipboardPasted = function (e, info) {
if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
}
const hint = {
cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
};
const range = info.cellRange;
const sortData = info.sheet.zh_data || [];
const data = [];
for (let iRow = 0; iRow < range.rowCount; iRow++) {
let bPaste = true;
const curRow = range.row + iRow;
const cLData = { id: sortData[curRow].clid };
const hintRow = range.rowCount >= 1 ? curRow : '';
let sameCol = 0;
for (let iCol = 0; iCol < range.colCount; iCol++) {
const curCol = range.col + iCol;
let colSetting = info.sheet.zh_setting.cols[curCol];
if (!colSetting) continue;
let validText = info.sheet.getText(curRow, curCol);
validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
const orgValue = sortData[curRow][colSetting.field];
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
sameCol++;
if (range.colCount === sameCol) {
bPaste = false;
}
continue;
}
if (colSetting.type === 'Number') {
if (isNaN(validText)) {
toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
bPaste = false;
continue;
}
validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
if (colSetting.field !== 'oamount2') {
// 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
} else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
bPaste = false;
continue;
}
}
}
sortData[curRow][colSetting.field] = validText;
if (colSetting.field === 'oamount2') {
cLData[colSetting.field] = validText;
} else {
cLData.spamount = validText;
sortData[curRow].spamount = validText;
}
}
if (bPaste) {
data.push(cLData);
// rowData.push(curRow);
} else {
SpreadJsObj.reLoadRowData(info.sheet, curRow);
}
}
if (data.length === 0) {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
}
console.log(data);
// 更新至服务器
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
changeList = result;
const node = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {
update: [node],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
posSpreadObj.loadCurPosData();
}, function () {
SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
return;
});
};
posSpreadObj.deletePress = function (sheet) {
if (!sheet.zh_setting) return;
// 暂时仅支持移除数量
const sel = sheet.getSelections()[0], datas = [];
for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
let bDel = false;
const node = sheet.zh_data[iRow];
const cInfo = _.find(changeList, { id: node.clid });
const data = { id: node.clid };
for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
const col = sheet.zh_setting.cols[iCol];
if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
node[col.field] = null;
cInfo[col.field] = null;
if (col.field !== 'oamount2') {
data.spamount = null;
cInfo.spamount = null;
node.spamount = null;
} else {
data[col.field] = null;
}
bDel = true;
}
}
if (bDel) datas.push(data);
}
if (datas.length > 0) {
postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
changeList = result;
const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
const loadResult = {
update: [billsNode],
};
const refreshData = ledgerTree.loadPostData(loadResult);
ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
posSpreadObj.loadCurPosData();
}, function () {
SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
return;
});
}
return;
};
posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
}
// 切换清单模式
$('.change-mode').on('click', async function () {
if ($(this).hasClass('active')) {
return;
}
$('.change-mode').removeClass('active');
$(this).addClass('active');
const type = parseInt($(this).data('type'));
postData(window.location.pathname + '/save', { type:'change_mode', updateData: type }, function (result) {
changeList = result;
changeMode = type;
showMode(type);
});
});
let firstLoad = true;
function showMode(type) {
if (type === 0) {
$('.judge-hide').show();
$('.judge-show').attr("style","display:none !important");
if (changeOrder === 0) {
$('#upAndMoveBtn').attr("style","display:none !important");
}
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
if (updateOrderList.length > 0) {
postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
});
}
changeSpreadObj.reloadSheet(newChangeList);
changeSpread.refresh();
xmjSpread.refresh();
} else {
$('.judge-hide').attr("style","display:none !important");
$('.judge-show').show();
if (firstLoad) {
const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
if (updateOrderList.length > 0) {
postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
});
}
firstLoad = false;
}
const {changeLedgers, changePoss} = makeLedgerAndPosData();
ledgerTree.loadDatas(changeLedgers);
pos.loadDatas(changePoss);
treeCalc.calculateAll(ledgerTree);
console.log(ledgerTree);
SpreadJsObj.loadSheetData(ledgerSheet, SpreadJsObj.DataType.Tree, ledgerTree);
ledgerTree.expandByCustom(() => { return true; });
SpreadJsObj.refreshTreeRowVisible(ledgerSheet);
SpreadJsObj.loadTopAndSelect(ledgerSheet, ckBillsSpread);
ledgerTreeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
posSpreadObj.loadCurPosData();
SpreadJsObj.resetTopAndSelect(posSheet);
ledgerTreeSpreadObj.loadExprToInput();
ledgerSpread.refresh();
posSpread.refresh();
}
}
// 显示层次
(function (select, sheet) {
$(select).click(function () {
if (!sheet.zh_tree) return;
const tag = $(this).attr('tag');
const tree = sheet.zh_tree;
setTimeout(() => {
showWaitingView();
switch (tag) {
case "1":
case "2":
case "3":
case "4":
case "5":
tree.expandByLevel(parseInt(tag));
SpreadJsObj.refreshTreeRowVisible(sheet);
break;
case "last":
tree.expandByCustom(() => { return true; });
SpreadJsObj.refreshTreeRowVisible(sheet);
break;
case "leafXmj":
tree.expandToLeafXmj();
SpreadJsObj.refreshTreeRowVisible(sheet);
break;
}
closeWaitingView();
}, 100);
});
})('a[name=showLevel]', ledgerSheet);
function makeLedgerAndPosData() {
const changeLedgers = _.filter(ledgerList, function (item) {
return _.findIndex(changeList, { gcl_id: item.id}) !== -1;
});
// 找出所有父节点
if (changeLedgers.length > 0) {
const parentLedgers = [];
for (const node of changeLedgers) {
const cl = _.find(changeList, { gcl_id: node.id, mx_id: '' });
if (cl) {
const cloneCl = _.cloneDeep(cl);
delete cloneCl.id;
delete cloneCl.name;
delete cloneCl.code;
node.clid = cl.id;
// cloneCl 合并到node中
Object.assign(node, cloneCl);
}
if (node.full_path && node.full_path !== '') {
const parentIds = node.full_path.split('-');
parentIds.length = parentIds.length - 1;
for (const id of parentIds) {
const lid = parseInt(id);
if (lid !== node.ledger_id && _.findIndex(parentLedgers, { ledger_id: lid }) === -1) {
parentLedgers.push(_.find(ledgerList, { ledger_id: lid }));
}
}
}
}
changeLedgers.push(...parentLedgers);
}
// 找出空白清单和签约清单
const otherChangeList = _.filter(changeList, function (item) {
return item.gcl_id === '' || item.gcl_id === null || item.gcl_id == 0;
});
if (otherChangeList.length > 0) {
// 判断changeLedgers中是否已经存在第一部分
let firstChangeLedger = _.find(changeLedgers, { order: 1, level: 1 });
let firstOrder = 1;
if (firstChangeLedger) {
const firstChilds = _.filter(changeLedgers, { ledger_pid: firstChangeLedger.ledger_id });
firstOrder = _.maxBy(firstChilds, 'order').order + 1;
}
let maxLedgerId = changeLedgers.length > 0 ? _.maxBy(changeLedgers, 'ledger_id').ledger_id + 1 : 2;
if (!firstChangeLedger) {
const firstLedger = _.find(ledgerList, { order: 1, level: 1 });
if (firstLedger) {
changeLedgers.push(firstLedger);
firstChangeLedger = firstLedger;
} else {
firstChangeLedger = { id: 'new-tree-ledger-1', ledger_id: 1, ledger_pid: -1, name: '第一部分 建筑安装工程费', unit: '公路公里', unit_price: 0, b_code: null, code: '1', order: 1, level: 1, full_path: '1', is_leaf: 0 };
changeLedgers.push(firstChangeLedger);
}
}
for (const cl of otherChangeList) {
const cloneCl = _.cloneDeep(cl);
cloneCl.b_code = cloneCl.code;
cloneCl.code = null;
cloneCl.clid = cl.id;
cloneCl.level = 2;
cloneCl.order = firstOrder;
cloneCl.is_leaf = 1;
cloneCl.ledger_pid = firstChangeLedger.ledger_id;
cloneCl.ledger_id = maxLedgerId;
cloneCl.full_path = firstChangeLedger.full_path + '-' + maxLedgerId;
changeLedgers.push(cloneCl);
maxLedgerId++;
firstOrder++;
}
}
const changePoss = _.filter(posList, function (item) {
return _.findIndex(changeList, { mx_id: item.id }) !== -1;
});
for (const cp of changePoss) {
const cl = _.find(changeList, { mx_id: cp.id });
if (cl) {
const cloneCl = _.cloneDeep(cl);
delete cloneCl.id;
delete cloneCl.lid;
delete cloneCl.name;
cp.clid = cl.id;
// cloneCl 合并到cp中
Object.assign(cp, cloneCl);
}
}
return { changeLedgers, changePoss };
}
// 审批流程展示与隐藏
$('#show-table-detail').on('click', function (e) {
if($(e.target).is('label')){
return;
}
ledgerTreeSpreadObj.showHideAudit($(this).is(':checked'));
posSpreadObj.showHideAudit($(this).is(':checked'));
changeSpreadObj.showHideAudit($(this).is(':checked'));
xmjSpreadObj.showHideAudit($(this).is(':checked'));
});
const cca = getLocalCache('change-checkbox-account-' + accountId);
if (cca !== null && cca !== undefined) {
$('#customCheck1').prop('checked', cca !== 'false');
}
changeSpreadSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
xmjSheet.setColumnVisible(7,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
ledgerSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
posSheet.setColumnVisible(2,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
// 变更详情展示和隐藏
$('.change-detail-checkbox').on('click', function (e) {
if($(e.target).is('label')){
return;
}
// // 设置用户项目本地记录展示和隐藏情况
setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
changeSpreadSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
xmjSheet.setColumnVisible(7,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
ledgerSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
posSheet.setColumnVisible(2,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
});
$.subMenu({
menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
key: 'menu.1.0.0',
miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
callback: function (info) {
if (info.mini) {
$('.panel-title').addClass('fluid');
$('#sub-menu').removeClass('panel-sidebar');
} else {
$('.panel-title').removeClass('fluid');
$('#sub-menu').addClass('panel-sidebar');
}
autoFlashHeight();
changeSpread.refresh();
xmjSpread.refresh();
ledgerSpread.refresh();
posSpread.refresh();
}
});
$.divResizer({
select: '#right-spr',
callback: function () {
changeSpread.refresh();
xmjSpread.refresh();
ledgerSpread.refresh();
posSpread.refresh();
const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
setLocalCache('change_information_width', width);
$('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
}
});
$('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
changeSpread.refresh();
xmjSpread.refresh();
ledgerSpread.refresh();
posSpread.refresh();
// 根据浏览器记录展开收起
if (getLocalCache('change_information_width')) {
$('#left-view').css('width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
$('#right-view').css('width', getLocalCache('change_information_width') + '%');
$('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
changeSpread.refresh();
xmjSpread.refresh();
ledgerSpread.refresh();
posSpread.refresh();
} else {
$('#left-header').css('min-width', '33.33%');
}
$.divResizer({
select: '#change-pos-resize',
callback: function () {
$('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
changeSpread.refresh();
ledgerSpread.refresh();
let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
$(".sp-wrap").height(bcontent-30);
posSpread.refresh();
xmjSpread.refresh();
}
});
if (!readOnly || shenpiPower) {
// 自动编号
$('.reduction-code').click(function () {
const code = $(this).attr('data-code');
$('input[name="code"]').val(code);
changeInfo.code = $('input[name="code"]').val();
judgeChange();
});
// 记录变更信息操作
$('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
changeInfo[$(this).attr('name')] = $(this).val();
judgeChange();
});
$('body').on('valuechange', '#change_form textarea', function (e, previous) {
changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '
');
judgeChange();
});
$('body').on('change', '#change_form select', function (e, previous) {
changeInfo[$(this).attr('name')] = $(this).val();
judgeChange();
});
$('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
changeInfo[$(this).attr('name')] = $(this).val();
judgeChange();
});
$('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
const typecheck = [];
$.each($('#change_form input[name="type[]"]:checked'), function () {
typecheck.push($(this).val());
});
changeInfo.type = typecheck.join(',');
judgeChange();
});
// 保存修改ajax提交(不刷新页面)
$('.save_change_btn').on('click', function () {
// 保存修改modal
if ($('input[name="code"]').val() === '') {
toastr.error('申请编号不能为空!');
return;
}
if ($('input[name="name"]').val() === '') {
toastr.error('变更工程名称不能为空!');
return;
}
// 换行更改并提交
changeInfo.content = changeInfo.content.replace(/
/g, '\r\n');
changeInfo.basis = changeInfo.basis.replace(/
/g, '\r\n');
changeInfo.expr = changeInfo.expr.replace(/
/g, '\r\n');
changeInfo.memo = changeInfo.memo.replace(/
/g, '\r\n');
changeInfo.company = $('#change_form select[name="company"]').val();
// 后改为br
// 更新至服务器
postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
$('.reduction-code').attr('data-code', $('input[name="code"]').val());
toastr.success(result ? result.msg : '');
$('#show-save-btn').hide();
$('#sp-btn').show();
$('.title-main').removeClass('bg-warning');
changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '
');
changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '
');
changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '
');
changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '
');
back_changeInfo = Object.assign({}, changeInfo);
if (result.changeList) {
deLimit = result.deLimit;
changeList = result.changeList;
SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
const [newChangeList] = changeSpreadObj.makeNewChangeList();
changeSpreadObj.reloadSheet(newChangeList);
}
});
return false;
});
$('#cancel_change').on('click', function () {
$('#show-save-btn').hide();
$('#sp-btn').show();
$('.title-main').removeClass('bg-warning');
if (!isObjEqual(changeInfo, back_changeInfo)) {
changeFormRemake();
}
toastr.success('已还原到上次保存状态');
});
function changeFormRemake() {
changeInfo = Object.assign({}, back_changeInfo);
$('#change_form input[name="code"]').val(changeInfo.code);
$('#change_form input[name="name"]').val(changeInfo.name);
$('#change_form input[name="peg"]').val(changeInfo.peg);
$('#change_form input[name="org_name"]').val(changeInfo.org_name);
$('#change_form input[name="org_code"]').val(changeInfo.org_code);
$('#change_form input[name="new_name"]').val(changeInfo.new_name);
$('#change_form input[name="new_code"]').val(changeInfo.new_code);
$('#change_form textarea[name="content"]').val(changeInfo.content.replace(/
/g, '\r\n'));
$('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/
/g, '\r\n'));
$('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/
/g, '\r\n'));
$('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/
/g, '\r\n'));
$('#change_form select[name="type"]').val(changeInfo.type);
$('#change_form select[name="class"]').val(changeInfo.class);
$('#change_form select[name="quality"]').val(changeInfo.quality);
$('#change_form select[name="company"]').val(changeInfo.company);
$('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
$('#change_form input[name="state"][value="'+ changeInfo.state +'"]').prop('checked', true);
$('#change_form input[name="type[]"]').prop('checked', false);
$('#change_form input[name="w_code"]').val(changeInfo.w_code);
const typecheck = changeInfo.type.split(',');
for (const type of typecheck) {
$('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
}
}
if (!readOnly) {
$('.checkChangeFrom').on('click', function () {
let returnFlag = false;
// 表单判断
if ($('input[name="code"]').val() === '') {
toastr.error('申请编号不能为空!');
returnFlag = true;
}
if ($('input[name="name"]').val() === '') {
toastr.error('变更工程名称不能为空!');
returnFlag = true;
}
if ($('textarea[name="content"]').val() === '') {
toastr.error('工程变更理由及内容不能为空!');
returnFlag = true;
}
if (changeList.length === 0) {
toastr.error('请添加变更清单!');
returnFlag = true;
} else {
const whiteList = _.filter(changeList, item => item.lid == 0 && (item.name === '' || item.name === null));
if (whiteList.length > 0) {
toastr.error('存在空白清单未完整填写数据(名称不可为空)');
returnFlag = true;
}
// for (const [i,cl] of changeSpreadSheet.zh_data.entries()) {
// if (cl.name === '') {
// toastr.error('清单第' + (i+1) + '行未完整填写数据(名称不可为空)');
// returnFlag = true;
// }
// }
}
if(!checkAuditorFrom ()) {
returnFlag = true;
}
// 判断非空白变更清单是否有重复值(gcl_id及mx_id),如果存在完全相同则需要提示并删除,上报失败,这功能主要是因为清单数据过多服务器处理不过来偶然出现
const doubleList = findDuplicates(_.filter(changeList, item => item.lid != 0));
console.log(doubleList);
if (doubleList.length > 0) {
for (const double of doubleList) {
const msgIndex = [];
for (const one of double) {
const index = _.findIndex(changeSpreadSheet.zh_data[double[0].order - 1].children, { id: one.id });
if (index !== -1) msgIndex.push(index+1);
}
if (msgIndex.length > 0) {
toastr.error('第 ' + double[0].order + ' 行' + double[0].code + '清单项目节第 ' + msgIndex.splice(',') + '行重复,请只保留一条数据');
}
}
returnFlag = true;
}
if (returnFlag) {
return false;
}
postData(window.location.pathname + '/audit/start', {}, function (result) {
window.location.reload();
})
});
// 检查上报情况
function checkAuditorFrom () {
if ($('#auditList li').length === 0) {
if(shenpi_status === shenpiConst.sp_status.gdspl) {
toastr.error('请联系管理员添加审批人');
} else {
toastr.error('请先选择审批人,再上报数据');
}
return false;
}
return true;
}
// 找出数组中相同的清单
function findDuplicates(arr, keys = ['lid', 'gcl_id', 'mx_id']) {
const groupedData = _.groupBy(arr, item => JSON.stringify(_.pick(item, keys)));
const duplicates = _.filter(groupedData, group => group.length > 1);
return _.values(duplicates);
}
}
}
if (shenpiPower) {
// 审批提交与判断
$('.approval-btn').on('click', function () {
// 判断审批状态
let returnflag = true;
const pData = {
change_id: $('#changeId').val(),
w_code: $.trim($('#w_code').val()),
}
if ($(this).hasClass('btn-success')) {
const sdesc = $('#success-approval').find('textarea').val();
if (sdesc === '') {
toastr.error('审批意见不能为空!');
returnflag = false;
}
if ($('input[name="p_code"]').val() === '') {
toastr.error('变更令号(批复编号)不能为空!');
returnflag = false;
} else if ($('input[name="p_code"]').val() !== undefined) {
$('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
const postData2 = {
p_code: $('input[name="p_code"]').val(),
};
postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData2, function (result) {
}, function (data) {
returnflag = false;
});
pData.p_code = $('input[name="p_code"]').val();
}
if(returnflag) {
$('input[name="w_code"]').val($.trim($('#w_code').val()));
$('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' '));
if ($('#warning-text').length) $('#warning-text').remove();
// $('#success-approval').submit();
pData.status = auditConst.status.checked;
pData.sdesc = sdesc.replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
}
} else {
const sdesc = $('#fail-approval').find('textarea').val();
if (sdesc === '') {
toastr.error('审批意见不能为空!');
returnflag = false;
}
const type = $('#fail-approval').find('input[name="status"]:checked').val();
if (type === undefined) {
// toastr.error('请选择退回类型!');
if (!$('#warning-text').length) {
$('#change-back-content').append('请选择退回流程
');
}
returnflag = false;
}
if(returnflag) {
$('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' '));
$('input[name="w_code"]').val($.trim($('#w_code').val()));
// $('#fail-approval').submit();
pData.status = type;
pData.sdesc = sdesc.replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
}
}
if (pData.status) {
console.log(pData);
postData('/tender/' + $('#tenderId').val() + '/change/approval', pData, function (result) {
window.location.reload();
});
}
});
const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
if (showWaiting) showWaitingView();
$.ajax({
type:"POST",
url: url,
data: {'data': JSON.stringify(data)},
dataType: 'json',
cache: false,
async: false,
timeout: 60000,
beforeSend: function(xhr) {
let csrfToken = Cookies.get('csrfToken_j');
xhr.setRequestHeader('x-csrf-token', csrfToken);
},
success: function(result){
if (result.err === 0) {
if (successCallback) {
successCallback(result.data);
}
} else {
toastr.error(result.msg);
if (errorCallBack) {
errorCallBack(result.msg);
}
}
if (showWaiting) closeWaitingView();
},
error: function(jqXHR, textStatus, errorThrown){
toastr.error('error: ' + textStatus + " " + errorThrown);
if (errorCallBack) {
errorCallBack();
}
if (showWaiting) closeWaitingView();
}
});
};
}
// 重新审批获取手机验证码
// 获取验证码
let isPosting = false;
$(".get-code").on('click', function() {
if (isPosting) {
return false;
}
const btn = $(this);
$.ajax({
url: '/profile/code?_csrf_j=' + csrf,
type: 'post',
data: { mobile: authMobile, type: 'shenpi' },
dataTye: 'json',
error: function() {
isPosting = false;
},
beforeSend: function() {
isPosting = true;
},
success: function(response) {
isPosting = false;
if (response.err === 0) {
codeSuccess(btn);
$("input[name='code']").removeAttr('readonly');
$("#re-shenpi-btn").removeAttr('disabled');
$("#re-shenpi-btn2").removeAttr('disabled');
} else {
toast(response.msg, 'error');
}
}
});
});
if (readOnly && !shenpiPower) {
// 记录变更信息操作
$('body').on('valuechange', '#w_code', function (e, previous) {
const new_w_code = $(this).val();
if (new_w_code !== w_code) {
$('#show-save-btn').show();
$('#sp-btn').hide();
$('.title-main').addClass('bg-warning');
} else {
$('#show-save-btn').hide();
$('#sp-btn').show();
$('.title-main').removeClass('bg-warning');
}
});
// 保存修改ajax提交(不刷新页面)
$('.save_change_btn').on('click', function () {
const new_w_code = $('#w_code').val();
// 后改为br
// 更新至服务器
postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {
toastr.success(result ? result.msg : '');
$('#show-save-btn').hide();
$('#sp-btn').show();
$('.title-main').removeClass('bg-warning');
w_code = new_w_code;
});
return false;
});
$('#cancel_change').on('click', function () {
$('#show-save-btn').hide();
$('#sp-btn').show();
$('.title-main').removeClass('bg-warning');
$('#w_code').val(w_code);
// toastr.success('已还原到上次保存状态');
});
}
});
/**
* 获取成功后的操作
*
* @param {Object} btn - 点击的按钮
* @return {void}
*/
function codeSuccess(btn) {
let counter = 60;
btn.addClass('disabled').text('重新获取 ' + counter + 'S');
btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
const bindBtn = $("#bind-btn");
bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
const countDown = setInterval(function() {
const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
// 倒数结束后
if (countString === '') {
clearInterval(countDown);
btn.removeClass('disabled');
}
const text = '重新获取' + countString;
btn.text(text);
counter -= 1;
}, 1000);
}
function calcChangePrice() {
let positive_tp = 0;
let negative_tp = 0;
let valuation_tp = 0;
let unvaluation_tp = 0;
let new_tp = 0;
// 先汇总再统计金额
const gclChangeList = _.uniq(_.map(changeList, 'gcl_id'));
for (const g of gclChangeList) {
if (g) {
const list = _.filter(changeList, { gcl_id: g });
let spamount = 0;
let valuation_amount = 0;
let unvaluation_amount = 0;
let unitPrice = 0;
for (const c of list) {
if (c.spamount) {
spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
unitPrice = c.unit_price;
if (c.is_valuation) {
valuation_amount = ZhCalc.add(valuation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
} else {
unvaluation_amount = ZhCalc.add(unvaluation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
}
const posOrNePrice = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
if (posOrNePrice >= 0) {
positive_tp = ZhCalc.add(positive_tp, posOrNePrice);
} else {
negative_tp = ZhCalc.add(negative_tp, posOrNePrice);
}
}
}
const price = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit);
const valuation_price = ZhCalc.round(ZhCalc.mul(valuation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
const unvaluation_price = ZhCalc.round(ZhCalc.mul(unvaluation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
valuation_tp = ZhCalc.add(valuation_tp, valuation_price);
unvaluation_tp = ZhCalc.add(unvaluation_tp, unvaluation_price);
new_tp = ZhCalc.add(new_tp, price);
// if (price >= 0) {
// positive_tp = ZhCalc.add(positive_tp, price);
// } else {
// negative_tp = ZhCalc.add(negative_tp, price);
// }
} else {
const list = _.filter(changeList, { gcl_id: g });
for (const c of list) {
if (c.spamount) {
const price = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
new_tp = ZhCalc.add(new_tp, price);
if (price >= 0) {
positive_tp = ZhCalc.add(positive_tp, price);
} else {
negative_tp = ZhCalc.add(negative_tp, price);
}
if (c.is_valuation) {
valuation_tp = ZhCalc.add(valuation_tp, price);
} else {
unvaluation_tp = ZhCalc.add(unvaluation_tp, price);
}
}
}
}
}
const updateTpList = {};
let updateFlag = false;
if (changeTp !== new_tp) {
updateTpList.total_price = new_tp;
updateFlag = true;
}
if (positive_tp !== changePp) {
updateTpList.positive_tp = positive_tp;
updateFlag = true;
}
if (negative_tp !== changeNp) {
updateTpList.negative_tp = negative_tp;
updateFlag = true;
}
if (valuation_tp !== changeVp) {
updateTpList.valuation_tp = valuation_tp;
updateFlag = true;
}
if (unvaluation_tp !== changeUp) {
updateTpList.unvaluation_tp = unvaluation_tp;
updateFlag = true;
}
if (updateFlag) {
console.log(updateTpList);
postData(window.location.pathname + '/save', { type:'update_tp', updateData: updateTpList }, function () {
changePp = positive_tp;
changeNp = negative_tp;
changeVp = valuation_tp;
changeUp = unvaluation_tp;
changeTp = new_tp;
});
}
}
function checkAndChange(changeListData) {
// 根据已添加的清单显示
if (changeList.length > 0 && changeList[0]) {
const removeList = [];
const updateList = [];
const updateGclIdList = [];
for (const [index,clinfo] of changeList.entries()) {
if (clinfo.lid != 0) {
let listinfo = changeListData.find(function (item) {
return (item.leafXmjs && item.leafXmjs.length > 0 && _.find(item.leafXmjs, {gcl_id: clinfo.lid })) || (item.id && item.id == clinfo.lid);
});
if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
// 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
const newlistinfo = changeListData.find(function (item) {
return (item.leafXmjs && item.leafXmjs.length > 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id })) || (item.id && item.id == clinfo.gcl_id);
});
if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
listinfo = newlistinfo;
updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
// 更新lid
changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
}
}
if (listinfo === undefined) {
// 针对旧数据获取清单信息
listinfo = changeListData[clinfo.lid - 1];
if (listinfo === undefined) {
toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
if (changeStatus !== auditConst.status.revise) {
removeList.push(clinfo);
} else {
updateList.push(makeWhiteList(clinfo));
}
continue;
}
}
const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
// 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
const updateInfo = {};
if (info.code !== clinfo.xmj_code) {
updateInfo.xmj_code = info.code;
changeList[index].xmj_code = info.code;
}
if (info.jldy !== clinfo.xmj_jldy) {
updateInfo.xmj_jldy = info.jldy;
changeList[index].xmj_jldy = info.jldy;
}
if (info.dwgc !== clinfo.xmj_dwgc) {
updateInfo.xmj_dwgc = info.dwgc;
changeList[index].xmj_dwgc = info.dwgc;
}
if (info.fbgc !== clinfo.xmj_fbgc) {
updateInfo.xmj_fbgc = info.fbgc;
changeList[index].xmj_fbgc = info.fbgc;
}
if (info.fxgc !== clinfo.xmj_fxgc) {
updateInfo.xmj_fxgc = info.fxgc;
changeList[index].xmj_fxgc = info.fxgc;
}
if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
updateGclIdList.push(clinfo.gcl_id);
// updateInfo.gcl_id = info.id;
updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
}
}
}
}
if(updateList.length > 0) {
console.log(updateList);
postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
}, function () {
});
}
if(removeList.length > 0) {
console.log(removeList);
_.pullAll(changeList, removeList);
postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
}, function () {
});
}
}
}
function makePushBwmx(clinfo, listinfo, removeList, updateList) {
let info = '';
const checkKey = ['name', 'code', 'unit', 'unit_price'];
const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
if (listinfo.leafXmjs !== undefined) {
const leafInfo = listinfo.leafXmjs.find(function (item) {
// const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id)) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
if (flag && item.code === clinfo.xmj_code) {
return flag && item.code === clinfo.xmj_code;
}
return flag;
});
if (leafInfo) {
const oneUpdate = { id: clinfo.id };
let needUpdate = false;
// 判断要不要更新名称,单位,原数量,单价
checkKey.forEach(function (key) {
if ((key === 'name' || key === 'unit') && listinfo[key] === null) {
listinfo[key] = '';
}
if (listinfo[key] !== clinfo[key]) {
oneUpdate[key] = listinfo[key];
clinfo[key] = listinfo[key];
if (key === 'unit') {
const changeKey = ['oamount', 'oamount2', 'camount'];
changeKey.forEach(function (key) {
const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
if (value !== clinfo[key]) {
oneUpdate[key] = value;
clinfo[key] = value;
}
});
}
// else if (key === 'unit_price') {
// // 可能要更新总金额了
// oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
// clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
// }
needUpdate = true;
}
});
checkLeafKey.forEach(function (key) {
// 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
if (key === 'oamount') {
if (leafInfo.quantity !== clinfo[key]) {
oneUpdate[key] = leafInfo.quantity;
clinfo[key] = leafInfo.quantity;
needUpdate = true;
}
} else if (key === 'bwmx') {
if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
oneUpdate[key] = leafInfo[key];
clinfo[key] = leafInfo[key];
needUpdate = true;
} else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
oneUpdate[key] = leafInfo.jldy;
clinfo[key] = leafInfo.jldy;
needUpdate = true;
}
} else {
if (leafInfo[key] !== clinfo['xmj_' + key]) {
oneUpdate['xmj_' + key] = leafInfo[key];
clinfo['xmj_' + key] = leafInfo[key];
needUpdate = true;
}
}
});
if (needUpdate) {
updateList.push(oneUpdate);
}
info = leafInfo;
} else {
toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
if (changeStatus !== auditConst.status.revise) {
removeList.push(clinfo);
} else {
updateList.push(makeWhiteList(clinfo));
}
return false;
}
}
return info;
}
function makeWhiteList(clinfo) {
clinfo.lid = 0;
clinfo.xmj_code = null;
clinfo.xmj_jldy = null;
clinfo.xmj_dwgc = null;
clinfo.xmj_fbgc = null;
clinfo.xmj_fxgc = null;
clinfo.gcl_id = '';
clinfo.mx_id = '';
return clinfo;
}
function isObjEqual(o1,o2){
var props1 = Object.getOwnPropertyNames(o1);
var props2 = Object.getOwnPropertyNames(o2);
if (props1.length != props2.length) {
return false;
}
for (var i = 0,max = props1.length; i < max; i++) {
var propName = props1[i];
if (o1[propName] !== o2[propName]) {
return false;
}
}
return true;
}
function findDecimal(unit) {
let value = precision.other.value;
const changeUnits = precision;
for (const d in changeUnits) {
if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
value = changeUnits[d].value;
break;
}
}
return value;
}
// 生成附件列表
function getAllList(currPageNum = 1) {
// 每页最多几个附件
const pageCount = 20;
// 附件总数
const total = attData.length;
// 总页数
const pageNum = Math.ceil(total/pageCount);
$('#totalPage').text(pageNum);
$('#currentPage').text(total === 0 ? 0 : currPageNum);
// 当前页附件内容
const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
currPageFileData = currPageAttData;
let html = '';
// '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
for(const [index,att] of currPageAttData.entries()) {
html += `
|
${((currPageNum-1)*pageCount)+index+1} |
${att.filename}${att.fileext} |
${moment(att.in_time * 1000).format('YYYY-MM-DD')} ${bytesToSize(att.filesize)} |
`
html += (att.uid === accountId && ((changeStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true) || deleteFilePermission)) ?
`` : '';
html += ` | `;
}
$('#attList').html(html);
$('#attList').on('click', 'tr', function() {
$('#attList tr').removeClass('bg-light');
$(this).addClass('bg-light');
})
}
function bytesToSize(bytes) {
if (parseInt(bytes) === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
// return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}
// 判断是否是已结算清单
function checkIsSettle(data) {
const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
if (info && info.settle_status && info.settle_status === settleStatus.finish) {
return true;
}
return false;
}