|
@@ -8,194 +8,98 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
+function loadUpdateMaterials(newMaterial, fields) {
|
|
|
+ const newMaterials = newMaterial instanceof Array ? newMaterial : [newMaterial];
|
|
|
+ for (const nm of newMaterials) {
|
|
|
+ const om = _.find(materialBillsData, {id: nm.id});
|
|
|
+ for (const prop in nm) {
|
|
|
+ if (!fields || fields.indexOf(prop) >= 0) {
|
|
|
+ om[prop] = nm[prop];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
$(document).ready(() => {
|
|
|
autoFlashHeight();
|
|
|
const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
|
|
|
+ console.log(materialType);
|
|
|
+ const materialSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.t_type', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
|
|
|
+ {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.code'},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.name'},
|
|
|
+ {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.unit'},
|
|
|
+ {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 230, formatter: '@', readOnly: 'readOnly.spec'},
|
|
|
+ {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 0, width: 60, readOnly: 'readOnly.m_type', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
|
|
|
+ {title: '本期应耗数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.quantity'},
|
|
|
+ {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.basic_price'},
|
|
|
+ {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.basic_times'},
|
|
|
+ {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
|
|
|
+ {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.msg_times'},
|
|
|
+ {title: '|价差', colSpan: '1', rowSpan: '1|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '本期材料调差|风险幅度(%)', colSpan: '3|1', rowSpan: '1|1', field: 'm_risk', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.m_risk'},
|
|
|
+ {title: '|有效价差', colSpan: '|1', rowSpan: '|1', field: 'm_spread', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '|调整金额', colSpan: '|1', rowSpan: '1|1', field: 'm_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '截止上期调差金额', colSpan: '1', rowSpan: '2', field: 'pre_tp', hAlign: 2, width: 120, type: 'Number', readOnly: true},
|
|
|
+ {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.remark'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 2,
|
|
|
+ headRowHeight: [32, 32],
|
|
|
+ defaultRowHeight: 30,
|
|
|
+ headerFont: '10pt 微软雅黑',
|
|
|
+ readOnly: readOnly,
|
|
|
+ font: '10pt 微软雅黑',
|
|
|
+ };
|
|
|
|
|
|
- SpreadJsObj.initSheet(materialSpread.getActiveSheet(), billsSpreadSetting);
|
|
|
-
|
|
|
- const paySpreadObj = {
|
|
|
- _checkExprValid(expr, invalidParam) {
|
|
|
- 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 (/^[a-z]/.test(expr[i])) {
|
|
|
- if (num !== '') {
|
|
|
- param.push({type: 'num', value: num});
|
|
|
- base = '';
|
|
|
- }
|
|
|
- base = base + expr[i];
|
|
|
- } else if (expr[i] === '(') {
|
|
|
- if (num !== '') {
|
|
|
- param.push({type: 'num', value: num});
|
|
|
- base = '';
|
|
|
- }
|
|
|
- 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});
|
|
|
- base = '';
|
|
|
- }
|
|
|
- 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});
|
|
|
- base = '';
|
|
|
- }
|
|
|
- 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});
|
|
|
- base = '';
|
|
|
- }
|
|
|
- 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].value = '-' + param[1];
|
|
|
- }
|
|
|
- param.unshift();
|
|
|
- }
|
|
|
- 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') {
|
|
|
- return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
|
|
|
- } else if (param[i - 1].value === '/' && num === 0) {
|
|
|
- return [false, '输入的表达式非法:请勿除0'];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (p.type === 'base') {
|
|
|
- const baseParam = _.find(calcBase, {code: p.value});
|
|
|
- if (!baseParam)
|
|
|
- return [false, '输入的表达式非法:不存在计算基数' + p.value];
|
|
|
- if (invalidParam && invalidParam.indexOf(p.value) >= 0)
|
|
|
- return [false, '不可使用计算基数' + p.value];
|
|
|
- if (i > 0 && param[i - 1].type === 'calc')
|
|
|
- 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, ''];
|
|
|
- },
|
|
|
- _checkSExpr: function (payNode, text, data) {
|
|
|
- if (!payNode) return [false, '数据错误'];
|
|
|
-
|
|
|
- const num = text ? _.toNumber(text) : null;
|
|
|
- let expr = text ? (num ? null : text) : null;
|
|
|
- expr = expr ? expr.replace('=', '').toLowerCase(): null;
|
|
|
- const [valid, msg] = this._checkExprValid(expr, ['bqwc', 'ybbqwc']);
|
|
|
- if (!valid) return [valid, msg];
|
|
|
-
|
|
|
- if (payBase.isStarted(payNode)) {
|
|
|
- return [false, '已经开始计量,请勿修改起扣金额'];
|
|
|
- } else {
|
|
|
- if (stage.order > 1) {
|
|
|
- const value = expr ? payCalc.calculateExpr(expr) : num;
|
|
|
- if (wcPay.pre_tp && value < wcPay.pre_tp)
|
|
|
- return [false, '已进行到第' + stage.order + '期,起扣金额请勿少于本期完成截止上期计量金额' + wcPay.pre_tp];
|
|
|
- data.sprice = num;
|
|
|
- data.sexpr = expr;
|
|
|
- return [true, ''];
|
|
|
- } else {
|
|
|
- data.sprice = num;
|
|
|
- data.sexpr = expr;
|
|
|
- return [true, ''];
|
|
|
- }
|
|
|
- }
|
|
|
+ const materialCol = {
|
|
|
+ readOnly: {
|
|
|
+ t_type: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ code: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ name: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ unit: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ spec: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ m_type: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ quantity: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ basic_price: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ basic_times: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ msg_tp: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ msg_times: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ m_risk: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ remark: function (data) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
},
|
|
|
- _checkRExpr: function (payNode, text, data) {
|
|
|
- if (!payNode) return [false, '数据错误'];
|
|
|
-
|
|
|
- const num = text ? _.toNumber(text) : null;
|
|
|
- let expr = text ? (num ? null : text) : null;
|
|
|
- expr = expr ? expr.replace('=', '').toLowerCase(): null;
|
|
|
- const [valid, msg] = this._checkExprValid(expr, ['bqwc', 'ybbqwc']);
|
|
|
- if (!valid) return [valid, msg];
|
|
|
+ };
|
|
|
+ SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
|
|
|
+ SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
|
|
|
+ SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
|
|
|
|
|
|
- if (payBase.isStarted(payNode)) {
|
|
|
- if (payNode.pre_finish) return [false, '已达扣款限额,请勿修改'];
|
|
|
- const value = expr ? payCalc.calculateExpr(expr) : num;
|
|
|
- if (payNode.pre_tp && value < payNode.pre_tp) return [false, '截止上期已计量' + payNode.pre_tp + ',扣款限额请勿少于改值'];
|
|
|
- data.rprice = num;
|
|
|
- data.rexpr = expr;
|
|
|
- return [true, ''];
|
|
|
- } else {
|
|
|
- data.rprice = num;
|
|
|
- data.rexpr = expr;
|
|
|
- return [true, ''];
|
|
|
- }
|
|
|
- },
|
|
|
- _checkExpr: function (text, data) {
|
|
|
- if (text) {
|
|
|
- const num = _.toNumber(text);
|
|
|
- if (num) {
|
|
|
- data.tp = num;
|
|
|
- data.expr = null;
|
|
|
- } else {
|
|
|
- const expr = text.replace('=', '').toLowerCase();
|
|
|
- const [valid, msg] = this._checkExprValid(expr);
|
|
|
- if (!valid) return [valid, msg];
|
|
|
- data.expr = expr;
|
|
|
- data.tp = null;
|
|
|
- }
|
|
|
- } else {
|
|
|
- data.tp = null;
|
|
|
- data.expr = null;
|
|
|
- }
|
|
|
- return [true, ''];
|
|
|
- },
|
|
|
+ const materialSpreadObj = {
|
|
|
refreshActn: function () {
|
|
|
const setObjEnable = function (obj, enable) {
|
|
|
if (enable) {
|
|
@@ -204,303 +108,124 @@ $(document).ready(() => {
|
|
|
obj.addClass('disabled');
|
|
|
}
|
|
|
};
|
|
|
- const sheet = paySpread.getActiveSheet();
|
|
|
+ const sheet = materialSpread.getActiveSheet();
|
|
|
const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
- setObjEnable($('#add'), !readOnly);
|
|
|
- const delValid = payBase.isOld(select)
|
|
|
- ? !payBase.isStarted(select) && payBase.isYB()
|
|
|
- : payBase.isYB() || payBase.isOwner(select);
|
|
|
- setObjEnable($('#del'), !readOnly && select && delValid);
|
|
|
- setObjEnable($('#up-move'), !readOnly && select && !payBase.isSpecial(select) && dealPay.indexOf(select) > 3);
|
|
|
- setObjEnable($('#down-move'), !readOnly && select && !payBase.isSpecial(select) && dealPay.indexOf(select) < dealPay.length - 1);
|
|
|
+ setObjEnable($('#del'), !readOnly && select);
|
|
|
},
|
|
|
add: function () {
|
|
|
- const sheet = billsSpread.getActiveSheet();
|
|
|
+ const sheet = materialSpread.getActiveSheet();
|
|
|
postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
|
|
|
if (result) {
|
|
|
- dealPay.push(result);
|
|
|
- sheet.addRows(dealPay.length - 1, 1);
|
|
|
- SpreadJsObj.reLoadRowData(sheet, dealPay.length - 1);
|
|
|
- sheet.setSelection(dealPay.length - 1, 0, 1, 1);
|
|
|
- paySpreadObj.refreshActn();
|
|
|
+ materialBillsData.push(result);
|
|
|
+ sheet.addRows(materialBillsData.length - 1, 1);
|
|
|
+ SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
|
|
|
+ sheet.setSelection(materialBillsData.length - 1, 0, 1, 1);
|
|
|
+ materialSpreadObj.refreshActn();
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
del: function () {
|
|
|
- const sheet = billsSpread.getActiveSheet();
|
|
|
+ const sheet = materialSpread.getActiveSheet();
|
|
|
const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
- if (payBase.isNonZero(select.tp)) {
|
|
|
- toast('该支付(扣款)项存在数据,如需删除请先清除本期金额!');
|
|
|
- return;
|
|
|
- } else if (payBase.isOld(select)) {
|
|
|
- if (payBase.isStarted(select)) {
|
|
|
- toast('该合同支付项往期已进行计算,不允许删除');
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- postData(window.location.pathname + '/save', {type: 'del', id: select.pid}, function (result) {
|
|
|
- const index = dealPay.indexOf(select);
|
|
|
- dealPay.splice(index, 1);
|
|
|
+ console.log(select);
|
|
|
+ postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
|
|
|
+ const index = materialBillsData.indexOf(select);
|
|
|
+ materialBillsData.splice(index, 1);
|
|
|
sheet.deleteRows(index, 1);
|
|
|
- loadUpdateDealPays(result);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
+ SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
|
|
|
const sel = sheet.getSelections();
|
|
|
sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
|
|
|
- paySpreadObj.refreshActn();
|
|
|
+ materialSpreadObj.refreshActn();
|
|
|
});
|
|
|
},
|
|
|
selectionChanged: function (e, info) {
|
|
|
- paySpreadObj.refreshActn();
|
|
|
+ materialSpreadObj.refreshActn();
|
|
|
const sel = info.sheet.getSelections()[0];
|
|
|
const col = info.sheet.zh_setting.cols[sel.col];
|
|
|
const data = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
- if (col.field === 'tp') {
|
|
|
- $('#expr').val(data.expr).attr('field', 'expr').attr('org', data.expr)
|
|
|
- .attr('readOnly', readOnly|| payBase.isSpecial(data));
|
|
|
- } else if (col.field === 'sprice') {
|
|
|
- $('#expr').val(data.sexpr).attr('field', 'sexpr').attr('org', data.sexpr)
|
|
|
- .attr('readOnly', readOnly|| payCol.readOnly.sprice(data));
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- $('#expr').val(data.rexpr).attr('field', 'rexpr').attr('org', data.rexpr)
|
|
|
- .attr('readOnly', readOnly|| payCol.readOnly.rprice(data));
|
|
|
- } else {
|
|
|
- $('#expr').val('').attr('readOnly', true);
|
|
|
- }
|
|
|
+ materialSpreadObj.setReadOnly(true);
|
|
|
},
|
|
|
editEnded: function (e, info) {
|
|
|
if (info.sheet.zh_setting) {
|
|
|
const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
const col = info.sheet.zh_setting.cols[info.col];
|
|
|
- if (col.field === 'minus') {
|
|
|
- return;
|
|
|
- }
|
|
|
// 未改变值则不提交
|
|
|
- const validText = info.editingText ? info.editingText.replace('\n', '') : null;
|
|
|
- let orgValue;
|
|
|
- if (col.field === 'tp') {
|
|
|
- orgValue = _.toNumber(validText) ? select.tp : select.expr;
|
|
|
- } else if (col.field === 'sprice') {
|
|
|
- orgValue = _.toNumber(validText) ? select.sprice : select.sexpr;
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- orgValue = _.toNumber(validText) ? select.rexpr : select.rexpr;
|
|
|
- } else {
|
|
|
- orgValue = select[col.field];
|
|
|
- }
|
|
|
+ const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
|
|
|
+ const orgValue = select[col.field];
|
|
|
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
return;
|
|
|
}
|
|
|
- // 获取更新信息
|
|
|
- const data = {
|
|
|
- type: (col.field === 'tp' || col.field === 'name') ? 'stage' : 'info',
|
|
|
- updateData: {}
|
|
|
- };
|
|
|
- // 获取更新数据
|
|
|
- if (col.field === 'tp') {
|
|
|
- data.updateData.pid = select.pid;
|
|
|
- const [valid, msg] = paySpreadObj._checkExpr(validText, data.updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (col.field === 'name') {
|
|
|
- data.updateData.pid = select.pid;
|
|
|
- data.updateData.name = validText;
|
|
|
- } else {
|
|
|
- data.updateData.id = select.pid;
|
|
|
- if (validText) {
|
|
|
- if (col.field === 'sprice') {
|
|
|
- const [valid, msg] = paySpreadObj._checkSExpr(select, validText, data.updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- const [valid, msg] = paySpreadObj._checkRExpr(select, validText, data.updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- data.updateData[col.field] = validText;
|
|
|
- }
|
|
|
- } else {
|
|
|
- data.updateData[col.field] = null;
|
|
|
- }
|
|
|
- }
|
|
|
+ select[col.field] = validText;
|
|
|
// 更新至服务器
|
|
|
- postData(window.location.pathname + '/save', data, function (result) {
|
|
|
- loadUpdateDealPays(result, col.field === 'name' ? ['name'] : null);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
+ postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
}, function () {
|
|
|
+ select[col.field] = orgValue;
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- buttonClicked: function (e, info) {
|
|
|
- if (info.sheet.zh_setting) {
|
|
|
- const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
- const col = info.sheet.zh_setting.cols[info.col];
|
|
|
- if (payCol.readOnly.minus(select)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (col.field === 'minus') {
|
|
|
- if (info.sheet.isEditing) {
|
|
|
- info.sheet.endEdit(true);
|
|
|
- }
|
|
|
- // 获取更新数据
|
|
|
- // 获取更新信息
|
|
|
- const data = {
|
|
|
- type: 'info',
|
|
|
- updateData: {id: select.pid},
|
|
|
- };
|
|
|
- data.updateData.minus = info.sheet.getValue(info.row, info.col) || false;
|
|
|
- // 更新至服务器
|
|
|
- postData(window.location.pathname + '/save', data, function (result) {
|
|
|
- loadUpdateDealPays(result);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- editStarting: function (e, info) {
|
|
|
- const col = info.sheet.zh_setting.cols[info.col];
|
|
|
- if (col.field === 'tp') {
|
|
|
- const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
- if (select.expr && select.expr !== '') {
|
|
|
- info.sheet.getCell(info.row, info.col).text(select.expr);
|
|
|
- }
|
|
|
- } else if (col.field === 'sprice') {
|
|
|
- const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
- if (select.sexpr && select.sexpr !== '') {
|
|
|
- info.sheet.getCell(info.row, info.col).text(select.sexpr);
|
|
|
- }
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
- if (select.rexpr && select.rexpr !== '') {
|
|
|
- info.sheet.getCell(info.row, info.col).text(select.rexpr);
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- deletePress: function (sheet) {
|
|
|
- if (sheet.zh_setting && sheet.zh_data) {
|
|
|
- const sel = sheet.getSelections()[0];
|
|
|
- if (!sel) return;
|
|
|
-
|
|
|
- const col = sheet.zh_setting.cols[sel.col];
|
|
|
- if (col.readOnly === true) { return; }
|
|
|
- if (sel.colCount > 1) {
|
|
|
- toast('请勿同时删除多列数据', 'warning');
|
|
|
- }
|
|
|
-
|
|
|
- const data = {type: col.field === 'tp' ? 'stage' : 'info', updateData: []};
|
|
|
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
|
|
|
- const node = sheet.zh_data[iRow];
|
|
|
- if (node && (node.ptype === 1 || node.ptype === 3)) {
|
|
|
- const updateData = {};
|
|
|
- if (col.field === 'tp') {
|
|
|
- updateData.pid = node.pid;
|
|
|
- updateData.tp = null;
|
|
|
- updateData.expr = null;
|
|
|
+ setReadOnly: function(readOnly) {
|
|
|
+ SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ materialSpreadObj.refreshActn();
|
|
|
+ materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
|
|
|
+ if (!readOnly) {
|
|
|
+ $('#add').click(materialSpreadObj.add);
|
|
|
+ $('#del').click(materialSpreadObj.del);
|
|
|
+ materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
|
|
|
+ // 右键菜单
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#material-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
|
|
|
+ return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ 'create': {
|
|
|
+ name: '新增材料',
|
|
|
+ icon: 'fa-sign-in',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ materialSpreadObj.add(materialSpread.getActiveSheet());
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'delete': {
|
|
|
+ name: '删除材料',
|
|
|
+ icon: 'fa-remove',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ materialSpreadObj.del(materialSpread.getActiveSheet());
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sheet = materialSpread.getActiveSheet();
|
|
|
+ if (sheet.zh_data.length > 0) {
|
|
|
+ const selection = sheet.getSelections();
|
|
|
+ return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
|
|
|
} else {
|
|
|
- updateData.id = node.pid;
|
|
|
- if (col.field === 'sprice') {
|
|
|
- const [valid, msg] = paySpreadObj._checkSExpr(node, null, updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- const [valid, msg] = paySpreadObj._checkRExpr(node, null, updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- updateData[col.field] = null;
|
|
|
- }
|
|
|
+ return true;
|
|
|
}
|
|
|
- data.updateData.push(updateData);
|
|
|
- }
|
|
|
- }
|
|
|
- if (data.updateData.length > 0) {
|
|
|
- if (data.updateData.length === 1 && sel.rowCount === 1) {
|
|
|
- data.updateData = data.updateData[0];
|
|
|
}
|
|
|
- postData(window.location.pathname + '/save', data, function (result) {
|
|
|
- loadUpdateDealPays(result, col.field === 'name' ? ['name'] : null);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- })
|
|
|
- }
|
|
|
+ },
|
|
|
}
|
|
|
- },
|
|
|
- clipboardPasted: function (e, info) {
|
|
|
- if (info.sheet.zh_setting && info.sheet.zh_data) {
|
|
|
- const col = info.sheet.zh_setting.cols[info.cellRange.col];
|
|
|
- if (col.readOnly === true) {
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (info.cellRange.colCount > 1) {
|
|
|
- toast('请勿同时复制粘贴多列数据', 'warning');
|
|
|
- }
|
|
|
-
|
|
|
- const sortData = info.sheet.zh_data;
|
|
|
- const data = {type: col.field === 'tp' ? 'stage' : 'info', updateData: []};
|
|
|
-
|
|
|
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
|
|
|
- const curRow = info.cellRange.row + iRow;
|
|
|
- const node = sortData[curRow];
|
|
|
- if (node && (node.ptype === 1 || node.ptype === 3)) {
|
|
|
- const validText = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
|
|
|
- const updateData = {};
|
|
|
- if (col.field === 'tp') {
|
|
|
- updateData.pid = node.pid;
|
|
|
- const [valid, msg] = paySpreadObj._checkExpr(validText, updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- updateData.id = node.pid;
|
|
|
- if (validText) {
|
|
|
- if (col.field === 'sprice') {
|
|
|
- const [valid, msg] = paySpreadObj._checkSExpr(node, validText, updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- const [valid, msg] = paySpreadObj._checkRExpr(node, validText, updateData);
|
|
|
- if (!valid) {
|
|
|
- toastr.warning(msg);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- updateData[col.field] = validText;
|
|
|
- }
|
|
|
- } else {
|
|
|
- updateData[col.field] = null;
|
|
|
- }
|
|
|
- }
|
|
|
- data.updateData.push(updateData);
|
|
|
- }
|
|
|
- if (data.updateData.length > 0) {
|
|
|
- postData(window.location.pathname + '/save', data, function (result) {
|
|
|
- loadUpdateDealPays(result, col.field === 'name' ? ['name'] : null);
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- }, function () {
|
|
|
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
|
|
|
+ }
|
|
|
+ $.subMenu({
|
|
|
+ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
|
|
|
+ toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
|
|
|
+ //key: 'stage.compare.memu.1.0.0',
|
|
|
+ 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();
|
|
|
+ materialSpread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|