tplus-pos
Version:
pos module
732 lines (581 loc) • 23.4 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _defineProperty = require('babel-runtime/core-js/object/define-property');
var _defineProperty2 = _interopRequireDefault(_defineProperty);
var _getOwnPropertyDescriptor = require('babel-runtime/core-js/object/get-own-property-descriptor');
var _getOwnPropertyDescriptor2 = _interopRequireDefault(_getOwnPropertyDescriptor);
var _objectDestructuringEmpty2 = require('babel-runtime/helpers/objectDestructuringEmpty');
var _objectDestructuringEmpty3 = _interopRequireDefault(_objectDestructuringEmpty2);
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _desc, _value, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11;
var _mobx = require('mobx');
var _mutantsAppfx = require('mutants-appfx');
var _BatchApi = require('../api/BatchApi.js');
var _BatchApi2 = _interopRequireDefault(_BatchApi);
var _tools = require('../util/tools');
var _tools2 = _interopRequireDefault(_tools);
var _common = require('../util/common');
var _common2 = _interopRequireDefault(_common);
var _fixedViewInfo = require('../fixedViewInfo');
var _cloneDeep2 = require('lodash/cloneDeep');
var _cloneDeep3 = _interopRequireDefault(_cloneDeep2);
var _tplusPoslogin = require('tplus-poslogin');
var _tplusComponentsTouch = require('tplus-components-touch');
var _config = require('../config');
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _initDefineProp(target, property, descriptor, context) {
if (!descriptor) return;
(0, _defineProperty2.default)(target, property, {
enumerable: descriptor.enumerable,
configurable: descriptor.configurable,
writable: descriptor.writable,
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
});
}
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
function _initializerWarningHelper(descriptor, context) {
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}
var minDate = _config2.default.minDate;
var BatchModal = (_class = function (_ViewBase) {
(0, _inherits3.default)(BatchModal, _ViewBase);
(0, _createClass3.default)(BatchModal, [{
key: 'type',
get: function get() {
return 'BatchModal';
}
/* data */
//批次选择
//template 需要用到的viewinfo,多计量单位与单计量不同
//写入批号
/* viewInfo */
}]);
function BatchModal(store, name) {
var _this2 = this;
(0, _classCallCheck3.default)(this, BatchModal);
var _this = (0, _possibleConstructorReturn3.default)(this, (BatchModal.__proto__ || (0, _getPrototypeOf2.default)(BatchModal)).call(this, store, name));
_initDefineProp(_this, 'selectVisible', _descriptor, _this);
_initDefineProp(_this, 'cancelEnable', _descriptor2, _this);
_initDefineProp(_this, 'targetIndex', _descriptor3, _this);
_initDefineProp(_this, 'batchsData', _descriptor4, _this);
_initDefineProp(_this, 'writeData', _descriptor5, _this);
_initDefineProp(_this, 'writeBatchView', _descriptor6, _this);
_this.isQuantityLimit = function () {
var isBalanceCanChange = (0, _tplusPoslogin.PosInitData)("isBalanceCanChange"); //是否可以手动修改
var isWeigh = _this.retailDetail.Inventory.IsWeigh;
return !isBalanceCanChange && isWeigh;
};
_initDefineProp(_this, 'ok', _descriptor7, _this);
_initDefineProp(_this, 'cancel', _descriptor8, _this);
_initDefineProp(_this, 'show', _descriptor9, _this);
_initDefineProp(_this, 'reset', _descriptor10, _this);
_this.batchWrite = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var TextBox, formData, batchInputData;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return _this.hide();
case 2:
TextBox = _this.store.getViewItem('TextBoxModal');
formData = {
Title: '批号录入',
Head: _this.head,
Data: _this.writeBatchView,
check: _this.check.bind(_this),
update: _this.updateWrite.bind(_this)
};
_context.next = 6;
return new _promise2.default(function (resolve, reject) {
TextBox.inputForm(formData, resolve);
});
case 6:
batchInputData = _context.sent;
if (batchInputData) {
(0, _mobx.runInAction)(function () {
_this.batchsData = [batchInputData];
});
_this.ok();
} else {
_this.cancel();
}
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, _this2);
}));
_this.updateWrite = function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(_ref3) {
var formData = _ref3.formData,
updateProp = _ref3.updateProp;
var param, updateName, that;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
param = {};
param.updateProp = updateProp;
param.updateRetailDetail = _this.retailDetail;
updateName = updateProp.name;
if (!(updateName !== 'ProductionDate' && updateName !== 'ExpiryDate')) {
_context2.next = 6;
break;
}
return _context2.abrupt('return', false);
case 6:
console.log('批次录入update数据:', param);
that = _this;
return _context2.abrupt('return', _this.controllerEvent("updateBatchDetail", param).then(function () {
var updateResult = {};
var retailDetail = that.retailDetail;
var updateFieldName = ['ProductionDate', 'ExpiryDate'];
updateFieldName.forEach(function (el) {
if (el in retailDetail) {
updateResult[el] = retailDetail[el];
}
});
return updateResult;
}));
case 9:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this2);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}();
_initDefineProp(_this, 'error', _descriptor11, _this);
return _this;
}
(0, _createClass3.default)(BatchModal, [{
key: 'init',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(_ref5, out) {
var _this3 = this;
var cancelEnable = _ref5.cancelEnable,
retailDetail = _ref5.retailDetail;
var RetailDetails, storeInfo, idStore, result, data, BatchDispatchDetailDTOs, batchsData;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
this.out = out;
this.retailDetail = (0, _cloneDeep3.default)(retailDetail);
this.retailDetail['ExpiryDate'] = null;
this.retailDetail['ProductionDate'] = null;
if (!_tools2.default.isNull(cancelEnable)) {
this.cancelEnable = cancelEnable;
}
this.head = [{
'Title': '存货名称',
'Value': retailDetail.Inventory.Name
}];
/* 接口获取批次信息 */
RetailDetails = new Array();
RetailDetails.push(retailDetail);
storeInfo = _tplusPoslogin.TStore.restore();
idStore = storeInfo.storeID;
_context3.next = 12;
return _BatchApi2.default.getBatchDispatchForRE({ RetailDetails: RetailDetails, Idstore: idStore });
case 12:
result = _context3.sent;
data = new Array();
if (result && result.DataSource) {
data = result.DataSource[0].BatchDispatchDetailDTOs;
}
BatchDispatchDetailDTOs = data;
//可改成接口返回
this.selectBatchView = this.getSelectBatchView(result.ColumnInfo);
this.writeBatchView = this.getWriteBatchView();
//处理接口数据到 view数据(可接口返回)
batchsData = this.handleBatchsData(BatchDispatchDetailDTOs);
(0, _mobx.runInAction)(function () {
_this3.batchsData = batchsData;
if (_this3.batchsData.length == 1) {
_this3.targetIndex = 0;
}
_this3.show();
});
return _context3.abrupt('return');
case 21:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function init(_x2, _x3) {
return _ref4.apply(this, arguments);
}
return init;
}()
//接口数据不符合页面规范,需要整理
}, {
key: 'handleBatchsData',
value: function handleBatchsData(BatchDispatchDetailDTOs) {
var _this4 = this;
var data = (0, _cloneDeep3.default)(BatchDispatchDetailDTOs);
data.forEach(function (el) {
_this4.selectBatchView.forEach(function (field) {
var key = field.dataIndex;
var value = el[key];
if (key === 'Quantity' || key === 'Quantity2') {
if (!el[key]) el[key] = 0;
return;
}
el[key] = value;
});
});
return data;
}
/* 是否 是称重商品且不允许修改数量 */
}, {
key: 'getSelectBatchView',
/* 获取批次选择vm (可改为接口返回)*/
value: function getSelectBatchView(selectBatch) {
var retailDetail = this.retailDetail;
var isReturn = _common2.default.getIsReturn(this.store.data);
var isLaborCost = retailDetail.Inventory.IsLaborCost;
/* 数量column 控制 */
var quantityColumn = selectBatch.filter(function (el) {
return el.dataIndex === 'Quantity' || el.dataIndex === 'Quantity2';
});
var quick = true;
if (!isLaborCost && !isReturn) {
quantityColumn.forEach(function (el) {
el.minValue = 0;
});
}
if (retailDetail.ReturnSourceDetailId && retailDetail.ReturnSourceDetailId > 0) {
quantityColumn.forEach(function (el) {
el.maxValue = 0;
el.minValue = -999999999999;
});
}
if (!_common2.default.getIsModifyQuantityAuth()) {
quick = false;
}
quantityColumn.forEach(function (el) {
el.quick = quick;
el.readOnly = false;
});
var quantityDecimalDigits = (0, _tplusPoslogin.PosInitData)("QuantityPrecision");
selectBatch.forEach(function (el) {
el.precision = quantityDecimalDigits;
});
this.handleColumn(selectBatch);
console.log('selectBatch:', selectBatch);
return selectBatch;
}
//处理列 设置列宽
}, {
key: 'handleColumn',
value: function handleColumn(columns) {
if (columns && columns.length > 0) {
var fixedCount = 1; //固定列数
var columnWidth = 150;
var tableWidth = 740;
var columnLength = columns.length;
if (columnLength <= 5) {
columnWidth = tableWidth / columnLength;
} else {
columns.forEach(function (el, index) {
if (index < fixedCount) el.fixed = 'left';
});
}
columns.forEach(function (column) {
column.width = columnWidth;
});
}
}
/* 写入批次vm */
}, {
key: 'getWriteBatchView',
value: function getWriteBatchView() {
/* 写入批次模板 */
var writeBatchView = (0, _cloneDeep3.default)((0, _fixedViewInfo.filterField)('WriteBatch'));
//数量的控制
var quantityField = writeBatchView.find(function (el) {
return el.FieldName === 'Quantity';
});
var selectQuantityField = this.selectBatchView.find(function (el) {
return el.key === 'Quantity';
});
var isReturn = _common2.default.getIsReturn(this.store.data);
var updateProps = {};
if (this.isQuantityLimit()) {
//数量填入
updateProps = (0, _extends3.default)({}, updateProps, {
disabled: true,
Value: this.retailDetail.Quantity
});
}
updateProps = (0, _extends3.default)({}, updateProps, _common2.default.getInputLimit('quantity'), {
max: { value: _tools2.default.isNull(selectQuantityField.maxValue) ? null : selectQuantityField.maxValue },
min: { value: _tools2.default.isNull(selectQuantityField.minValue) ? null : selectQuantityField.minValue },
isReturn: isReturn
});
(0, _assign2.default)(quantityField, updateProps);
//没有启用有效期 去除时间选择表单
if (!this.retailDetail.Inventory.IsQualityPeriod) {
writeBatchView = writeBatchView.filter(function (el, index) {
if (el.FieldName !== 'ExpiryDate' && el.FieldName !== 'ProductionDate') {
return true;
}
});
}
//带入默认 生产日期/失效日期
var detail = this.retailDetail;
writeBatchView && writeBatchView.forEach(function (el) {
if (el.FieldName == 'ExpiryDate' || el.FieldName == 'ProductionDate') {
var val = detail[el.FieldName];
el.Value = val;
}
});
return writeBatchView;
}
//确定or取消
}, {
key: 'hide',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
var _this5 = this;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _mobx.runInAction)(function () {
_this5.selectVisible = false;
_this5.targetIndex = -1;
});
case 2:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function hide() {
return _ref6.apply(this, arguments);
}
return hide;
}()
}, {
key: 'changeTargetIndex',
value: function changeTargetIndex(_ref7) {
var _ref7$index = _ref7.index,
index = _ref7$index === undefined ? -1 : _ref7$index;
this.targetIndex = index;
}
/* ========================手动录入批次start=================== */
/* 弹框手动录入批次 */
/* form 数据改变 */
}, {
key: 'check',
/* 检查数据 return 错误数据 */
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(outData) {
var i, FieldName, Title, isReturn;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
i = 0;
case 1:
if (!(i < this.writeBatchView.length)) {
_context5.next = 9;
break;
}
FieldName = this.writeBatchView[i].FieldName;
Title = this.writeBatchView[i].Title;
if (!_tools2.default.isNull(outData[FieldName])) {
_context5.next = 6;
break;
}
return _context5.abrupt('return', this.error(FieldName, 'error', Title + '为空'));
case 6:
i++;
_context5.next = 1;
break;
case 9:
isReturn = _common2.default.getIsReturn(this.store.data);
if (!(!isReturn && Number(outData.Quantity) < 0)) {
_context5.next = 12;
break;
}
return _context5.abrupt('return', this.error('Quantity', 'error', '开单数量不能小于0'));
case 12:
return _context5.abrupt('return', null);
case 13:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function check(_x4) {
return _ref8.apply(this, arguments);
}
return check;
}()
}], [{
key: 'fromJS',
value: function fromJS(store, _ref9) {
(0, _objectDestructuringEmpty3.default)(_ref9);
return new BatchModal(store, 'BatchModal');
}
}]);
return BatchModal;
}(_mutantsAppfx.ViewBase), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'selectVisible', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return false;
}
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'cancelEnable', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return true;
}
}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, 'targetIndex', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return 0;
}
}), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, 'batchsData', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, 'writeData', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, 'writeBatchView', [_mobx.observable], {
enumerable: true,
initializer: null
}), _applyDecoratedDescriptor(_class.prototype, 'init', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'init'), _class.prototype), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, 'ok', [_mobx.action], {
enumerable: true,
initializer: function initializer() {
var _this6 = this;
return function () {
var batchsData = (0, _mobx.toJS)(_this6.batchsData);
if (_this6.isQuantityLimit()) {
var sum = 0;
batchsData.forEach(function (el) {
return sum += Number(el.Quantity);
});
if (sum != _this6.retailDetail.Quantity) {
_tplusComponentsTouch.Message.warn('总数量与商品称重数量不一致');
return;
}
}
console.log('批次弹框输出:', batchsData);
_this6.out(batchsData);
_this6.hide();
};
}
}), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, 'cancel', [_mobx.action], {
enumerable: true,
initializer: function initializer() {
var _this7 = this;
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
if (!_this7.cancelEnable) {
_context6.next = 4;
break;
}
_context6.next = 3;
return _this7.hide();
case 3:
_this7.out();
case 4:
case 'end':
return _context6.stop();
}
}
}, _callee6, _this7);
}));
}
}), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, 'show', [_mobx.action], {
enumerable: true,
initializer: function initializer() {
var _this8 = this;
return function () {
_this8.selectVisible = true;
};
}
}), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, 'reset', [_mobx.action], {
enumerable: true,
initializer: function initializer() {
var _this9 = this;
return function () {
_this9.writeBatchView.forEach(function (el) {
el.Value = "";
});
};
}
}), _applyDecoratedDescriptor(_class.prototype, 'changeTargetIndex', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'changeTargetIndex'), _class.prototype), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, 'error', [_mobx.action], {
enumerable: true,
initializer: function initializer() {
return function (key, state, errMsg) {
return {
FieldName: key,
State: state,
Label: errMsg
};
};
}
})), _class);
exports.default = BatchModal;
//# sourceMappingURL=BatchModal.js.map