|
@@ -43,8 +43,50 @@ $(document).ready(() => {
|
|
|
},
|
|
|
isGatherValid: function(data) {
|
|
|
return !data.pay_type && (!data.children || data.children.length === 0);
|
|
|
+ },
|
|
|
+ isOwner: function(data) {
|
|
|
+ return data.create_user_id === userID;
|
|
|
+ },
|
|
|
+ isFinish: function(data) {
|
|
|
+ return data.pre_finish;
|
|
|
+ },
|
|
|
+ isYB: function() {
|
|
|
+ return userID === phasePay.create_user_id;
|
|
|
+ },
|
|
|
+ isOld: function(data) {
|
|
|
+ return data.phase_id !== data.create_phase_id;
|
|
|
+ },
|
|
|
+ isLock: function (data) {
|
|
|
+ const result = !!lockPayExpr && payUtils.check.isStarted(data) && payCalc.hasBase(data.expr);
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ tpReadOnly: function(data) {
|
|
|
+ return payUtils.check.isYf(data) || payUtils.check.isLock(data);
|
|
|
+ },
|
|
|
+ startTpReadOnly: function(data) {
|
|
|
+ if (payUtils.check.isOld(data)) {
|
|
|
+ return payUtils.check.isStarted(data) || !payUtils.check.isYB(data) || payUtils.check.isLock(data);
|
|
|
+ } else {
|
|
|
+ return payUtils.check.isWC(data) || payUtils.check.isSF(data) || payUtils.check.isYf(data) || !(payUtils.check.isOwner(data) || payUtils.check.isYB());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ menuVisible: {
|
|
|
+ pause: function (data) {
|
|
|
+ if (payUtils.check.isOld(data)) {
|
|
|
+ return payUtils.check.isYB();
|
|
|
+ } else {
|
|
|
+ return payUtils.check.isOwner(data) || payUtils.check.isYB();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deadline: function (data) {
|
|
|
+ if (payUtils.check.isOld(data)) {
|
|
|
+ return !payUtils.check.isFinish(data) && payUtils.check.isYB();
|
|
|
+ } else {
|
|
|
+ return payUtils.check.isOwner(data) || payUtils.check.isYB();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
const payCalc = (function (b, a) {
|
|
|
class PayCalc {
|
|
@@ -61,6 +103,13 @@ $(document).ready(() => {
|
|
|
this.orderReg = /f\d+/ig;
|
|
|
this.nodeReg = /<<[a-z0-9\-]+>>/ig;
|
|
|
}
|
|
|
+ hasBase(expr) {
|
|
|
+ if (!expr) return false;
|
|
|
+ for (const b of this.bases) {
|
|
|
+ if (data.expr.indexOf(b.code) >= 0) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
trans2OrderExpr(expr, payTree) {
|
|
|
const nodeParam = expr.match(this.nodeReg);
|
|
|
if (nodeParam) {
|
|
@@ -283,8 +332,8 @@ $(document).ready(() => {
|
|
|
// 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;
|
|
|
+ // data.range_tp = num;
|
|
|
+ // data.range_expr = expr;
|
|
|
return [false, '已经开始使用,请勿修改扣款限额'];
|
|
|
}
|
|
|
} else {
|
|
@@ -458,31 +507,34 @@ $(document).ready(() => {
|
|
|
const preNode = payTree.getPreSiblingNode(select);
|
|
|
setObjEnable($('a[name=base-opr][type=add]'), !readOnly && !payUtils.check.isSf(select) && !payUtils.check.isYf(select));
|
|
|
const delValid = !payUtils.check.isFixed(select) && !payUtils.check.isStarted(select);
|
|
|
- setObjEnable($('a[name=base-opr][type=del]'), !readOnly && delValid);
|
|
|
+ setObjEnable($('a[name=base-opr][type=delete]'), !readOnly && delValid);
|
|
|
setObjEnable($('a[name=base-opr][type=up-move]'), !readOnly && !payUtils.check.isFixed(select) && preNode);
|
|
|
setObjEnable($('a[name=base-opr][type=down-move]'), !readOnly && !payUtils.check.isFixed(select) && !payTree.isLastSibling(select));
|
|
|
},
|
|
|
loadExprToInput: function() {
|
|
|
const sel = sheet.getSelections()[0];
|
|
|
const col = sheet.zh_setting.cols[sel.col];
|
|
|
- const data = SpreadJsObj.getSelectObject(this.sheet);
|
|
|
- if (data) {
|
|
|
+ const data = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ if (data && (!data.children || data.children.length === 0)) {
|
|
|
if (col.field === 'tp') {
|
|
|
- $('#expr').val(data.expr).attr('field', 'expr').attr('org', data.expr)
|
|
|
- .attr('readOnly', readOnly|| payCol.readOnly.tp(data));
|
|
|
- } else if (col.field === 'stage_tp') {
|
|
|
- $('#expr').val(data.start_expr).attr('field', 'start_expr').attr('org', data.start_expr)
|
|
|
- .attr('readOnly', readOnly|| payCol.readOnly.sprice(data) || payBase.isYF(data));
|
|
|
- } else if (col.field === 'rprice') {
|
|
|
- $('#expr').val(data.range_expr).attr('field', 'range_expr').attr('org', data.range_expr)
|
|
|
- .attr('readOnly', readOnly|| payCol.readOnly.rprice(data) || payBase.isYF(data));
|
|
|
+ const expr = payCalc.trans2OrderExpr(data.expr, payTree);
|
|
|
+ $('#pay-expr').val(expr).attr('field', 'expr').attr('org', expr)
|
|
|
+ .attr('readOnly', readOnly|| payUtils.check.tpReadOnly(data));
|
|
|
+ } else if (col.field === 'start_tp') {
|
|
|
+ const expr = payCalc.trans2OrderExpr(data.start_expr, payTree) || data.start_tp;
|
|
|
+ $('#pay-expr').val(expr).attr('field', 'start_expr').attr('org', expr)
|
|
|
+ .attr('readOnly', readOnly|| payUtils.check.startTpReadOnly(data) || payUtils.check.isYf(data));
|
|
|
+ } else if (col.field === 'range_tp') {
|
|
|
+ const expr = payCalc.trans2OrderExpr(data.range_expr, payTree);
|
|
|
+ $('#pay-expr').val(expr).attr('field', 'range_expr').attr('org', expr)
|
|
|
+ .attr('readOnly', readOnly|| payUtils.check.rangeTpReadOnly(data) || payUtils.check.isYf(data));
|
|
|
} else {
|
|
|
- $('#expr').val('').attr('readOnly', true);
|
|
|
+ $('#pay-expr').val('').attr('readOnly', true);
|
|
|
}
|
|
|
- $('#expr').attr('data-row', sel.row);
|
|
|
+ $('#pay-expr').attr('data-row', sel.row);
|
|
|
} else {
|
|
|
- $('#expr').val('').attr('readOnly', true);
|
|
|
- $('#expr').removeAttr('data-row');
|
|
|
+ $('#pay-expr').val('').attr('readOnly', true);
|
|
|
+ $('#pay-expr').removeAttr('data-row');
|
|
|
}
|
|
|
},
|
|
|
refreshTree: function (data) {
|
|
@@ -757,6 +809,162 @@ $(document).ready(() => {
|
|
|
$('#reload-calc-base').click(function() {
|
|
|
payEvent.reloadCalcBase();
|
|
|
});
|
|
|
+
|
|
|
+ const deadlineObj = {
|
|
|
+ payNode: null,
|
|
|
+ refreshHint: function() {
|
|
|
+ const dlType = $('[name=dl-type]:checked').val();
|
|
|
+ const dt = deadlineType[dlType];
|
|
|
+ if (dlType && dt) {
|
|
|
+ const dlValue = $('#dl-value').val();
|
|
|
+ $('#range-hint').text(`当 ${dt.name} >= ${dlValue} 时 `);
|
|
|
+ $('#dl-hint').show();
|
|
|
+ } else {
|
|
|
+ $('#dl-hint').hide();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ initView: function(data) {
|
|
|
+ this.payNode = data;
|
|
|
+ $('#dl-pay-name').html(data.name);
|
|
|
+ // 模式
|
|
|
+ if (data.dl_type) {
|
|
|
+ $('[name=dl-type][value=' + data.dl_type +']')[0].checked = true;
|
|
|
+ } else {
|
|
|
+ $('#dl-type-none')[0].checked = true;
|
|
|
+ }
|
|
|
+ $('#dl-value').val(data.dl_value);
|
|
|
+ this.refreshHint();
|
|
|
+ },
|
|
|
+ getDlCount: function() {
|
|
|
+ try {
|
|
|
+ const result = parseInt($('#dl-value').val());
|
|
|
+ if (result <= 0) throw '限制值请输入正整数';
|
|
|
+ return result;
|
|
|
+ } catch (err) {
|
|
|
+ toastr.warning('限制值请输入正整数');
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getDlTp: function() {
|
|
|
+ try {
|
|
|
+ const result = parseFloat($('#dl-value').val());
|
|
|
+ return result;
|
|
|
+ } catch (err) {
|
|
|
+ toastr.warning('限制值请输入数值');
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getUpdateData: function() {
|
|
|
+ const result = { postType: 'update', postData: { id: this.payNode.id } };
|
|
|
+ result.postData.dl_type = $('[name=dl-type]:checked').val();
|
|
|
+ if (result.postData.dl_type) {
|
|
|
+ if (result.postData.dl_type === deadlineType.phaseCount.key) {
|
|
|
+ result.postData.dl_value = this.getDlCount();
|
|
|
+ if (result.postData.dl_value < phasePay.phase_order) {
|
|
|
+ toastr.warning(`已计量至第${phasePay.phase_order}期,计提期限不可小于该期`);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if (result.postData.dl_type === deadlineType.stageCount.key) {
|
|
|
+ result.postData.dl_value = this.getDlCount();
|
|
|
+ if (result.postData.dl_value < maxStageOrder) {
|
|
|
+ toastr.warning(`已计量至第${maxStageOrder}期,计提期限不可小于该期`);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.postData.dl_value = this.getDlTp();
|
|
|
+ const dt = deadlineType[result.postData.dl_type];
|
|
|
+ if (!dt) {
|
|
|
+ toastr.warning('限制模式错误,请刷新页面重试');
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ const compareValue = payCalc.addBase[`pre_${dt.key}_tp`];
|
|
|
+ if (result.postData.dl_type < compareValue) {
|
|
|
+ toastr.warning(`截止上期,${dt.name}已计量${compareValue},计提期限不可小于该值`);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.postData.dl_value = 0;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ };
|
|
|
+ $('[name=dl-type]').change(deadlineObj.refreshHint);
|
|
|
+ $('#dl-value').change(deadlineObj.refreshHint);
|
|
|
+ $('#deadline-ok').click(function() {
|
|
|
+ const updateData = deadlineObj.getUpdateData();
|
|
|
+ if (!updateData) return;
|
|
|
+ postData('update', updateData, function(result) {
|
|
|
+ payEvent.reloadPays(result.reload);
|
|
|
+ $('#deadline').modal('hide');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 右键菜单
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#pay-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, spread);
|
|
|
+ return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ 'start': {
|
|
|
+ name: '启用',
|
|
|
+ icon: 'fa-play',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ const data = {
|
|
|
+ postType: 'update',
|
|
|
+ postData: { id: select.id, is_pause: 0 }
|
|
|
+ };
|
|
|
+ // 更新至服务器
|
|
|
+ postData('update', data, function (result) {
|
|
|
+ payEvent.reloadPays(result.reload);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ return (!select.children || select.children.length ===0) && !readOnly && select.is_pause && payUtils.menuVisible.pause(select);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'stop': {
|
|
|
+ name: '停用',
|
|
|
+ icon: 'fa-pause',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ const data = {
|
|
|
+ postType: 'update',
|
|
|
+ postData: { id: select.id, is_pause: 1 }
|
|
|
+ };
|
|
|
+ // 更新至服务器
|
|
|
+ postData('update', data, function (result) {
|
|
|
+ payEvent.reloadPays(result.reload);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ return (!select.children || select.children.length === 0) && !readOnly && !select.is_pause && payUtils.menuVisible.pause(select);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'setDeadline': {
|
|
|
+ name: '设置计提期限',
|
|
|
+ icon: 'fa-clipboard',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ if (select.range_tp) {
|
|
|
+ deadlineObj.initView(select);
|
|
|
+ $('#deadline').modal('show');
|
|
|
+ } else {
|
|
|
+ toastr.warning('计提期限用于达到条件时,即刻计量至付(扣)款限额,应先设置付(扣)款限额');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
+ return (!select.children || select.children.length === 0) && !readOnly && payUtils.menuVisible.deadline(select);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
return { spread, sheet, payTree, loadDatas: payEvent.reloadPays }
|