|
@@ -52,11 +52,43 @@ $(document).ready(() => {
|
|
|
readOnly: readOnly,
|
|
|
};
|
|
|
|
|
|
+ const spCol = _.find(materialSpreadSetting.cols, {field: 'quantity'});
|
|
|
+ spCol.readOnly = true;
|
|
|
+ spCol.cellType = 'activeImageBtn';
|
|
|
+ spCol.normalImg = '#ellipsis-icon';
|
|
|
+ spCol.indent = 5;
|
|
|
+ spCol.showImage = function (data) {
|
|
|
+ // return !readOnly && data.t_type === 2 && data.mid === materialID;
|
|
|
+ return data.t_type === 2;
|
|
|
+ };
|
|
|
+ materialSpreadSetting.imageClick = function (data) {
|
|
|
+ if (data.t_type === 2) {
|
|
|
+ $('#bcyy').modal('show');
|
|
|
+ console.log(data);
|
|
|
+ $('#materialbillsId').val(data.id);
|
|
|
+ $('#expr').val(data.expr);
|
|
|
+ if (!readOnly && data.mid === materialID) {
|
|
|
+ $('#expr').attr('readOnly', false);
|
|
|
+ $('#expr_btn').show();
|
|
|
+ $('#expr_select').show();
|
|
|
+ } else {
|
|
|
+ $('#expr').attr('readOnly', true);
|
|
|
+ $('#expr_btn').hide();
|
|
|
+ $('#expr_select').hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const materialBase = {
|
|
|
isEdit: function (data) {
|
|
|
- return materialListData.find(function (item) {
|
|
|
- return item.mb_id === data.id;
|
|
|
- });
|
|
|
+ if (data.t_type === 2) {
|
|
|
+ return data.mid === materialID;
|
|
|
+ } else {
|
|
|
+ const mlInfo = materialListData.find(function (item) {
|
|
|
+ return item.mb_id === data.id;
|
|
|
+ });
|
|
|
+ return data.mid === materialID && mlInfo === undefined;
|
|
|
+ }
|
|
|
},
|
|
|
// isStage: function (data) {
|
|
|
// return data.mid === materialID;
|
|
@@ -79,7 +111,7 @@ $(document).ready(() => {
|
|
|
},
|
|
|
readOnly: {
|
|
|
isEdit: function (data) {
|
|
|
- return !(!readOnly && materialBase.isEdit(data) === undefined);
|
|
|
+ return !(!readOnly && materialBase.isEdit(data));
|
|
|
},
|
|
|
remark: function () {
|
|
|
return readOnly;
|
|
@@ -102,7 +134,7 @@ $(document).ready(() => {
|
|
|
const sheet = materialSpread.getActiveSheet();
|
|
|
const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
// 还需判断是否已被调差清单调用
|
|
|
- setObjEnable($('#del'), !readOnly && select && materialBase.isEdit(select) === undefined);
|
|
|
+ setObjEnable($('#del'), !readOnly && select && materialBase.isEdit(select));
|
|
|
},
|
|
|
add: function () {
|
|
|
const sheet = materialSpread.getActiveSheet();
|
|
@@ -250,7 +282,7 @@ $(document).ready(() => {
|
|
|
const sheet = materialSpread.getActiveSheet();
|
|
|
const select = SpreadJsObj.getSelectObject(sheet);
|
|
|
materialSpreadObj.refreshActn();
|
|
|
- if (!readOnly && select && materialBase.isEdit(select) === undefined) {
|
|
|
+ if (!readOnly && select && materialBase.isEdit(select)) {
|
|
|
return false;
|
|
|
} else {
|
|
|
return true;
|
|
@@ -267,6 +299,151 @@ $(document).ready(() => {
|
|
|
$('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
|
|
|
$('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
|
|
|
});
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#expr_select button').on('click', function () {
|
|
|
+ const code = $(this).text();
|
|
|
+ $('#expr').val($('#expr').val() + code);
|
|
|
+ });
|
|
|
+
|
|
|
+ const ExprObj = {
|
|
|
+ _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, ''];
|
|
|
+ },
|
|
|
+ _checkExpr: function (text) {
|
|
|
+ if (text) {
|
|
|
+ const num = _.toNumber(text);
|
|
|
+ if (num) {
|
|
|
+ console.log(num);
|
|
|
+ } else {
|
|
|
+ const expr = text.replace('=', '').toLowerCase();
|
|
|
+ const [valid, msg] = this._checkExprValid(expr);
|
|
|
+ if (!valid) return [valid, msg];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return [true, ''];
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ $('#expr_btn').click(function () {
|
|
|
+ const expr = $('#expr').val();
|
|
|
+ // 判断表达式格式
|
|
|
+ const [valid, msg] = ExprObj._checkExpr(expr);
|
|
|
+ console.log(msg);
|
|
|
+ if (!valid) {
|
|
|
+ toastr.error(msg);
|
|
|
+ }
|
|
|
})
|
|
|
} else {
|
|
|
// SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
|