UNPKG

tplus-pos

Version:

pos module

517 lines (445 loc) 21.3 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; 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 _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _desc, _value, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10; var _mobx = require('mobx'); var _api = require('./api'); var _api2 = _interopRequireDefault(_api); var _mutantsUtil = require('mutants-util'); var _tplusApi = require('tplus-api'); var _mutantsMicrofx = require('mutants-microfx'); var _tplusPoslogin = require('tplus-poslogin'); 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 _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); } 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; } (0, _tplusApi.registerLogoutMiddleWare)('product', function () { console.log('执行注销后的清理动作 => 清空商品等级'); _mutantsMicrofx.localStore.set('productLevel', ''); _mutantsMicrofx.localStore.set('product-keyboard', ''); _mutantsMicrofx.localStore.set('ByProduct', ''); _mutantsMicrofx.localStore.set('ByMember', ''); }); var ProductStore = (_class = function () { function ProductStore() { (0, _classCallCheck3.default)(this, ProductStore); _initDefineProp(this, 'level_1', _descriptor, this); _initDefineProp(this, 'level_2', _descriptor2, this); _initDefineProp(this, 'productLevel', _descriptor3, this); _initDefineProp(this, 'productList', _descriptor4, this); _initDefineProp(this, 'backupsProductList', _descriptor5, this); _initDefineProp(this, 'params', _descriptor6, this); _initDefineProp(this, 'pageCount', _descriptor7, this); _initDefineProp(this, 'dataLoading', _descriptor8, this); _initDefineProp(this, 'showPageCount', _descriptor9, this); _initDefineProp(this, 'pageTotalCount', _descriptor10, this); this.justOneResultCallBack = function () {}; this.posCode = _tplusPoslogin.PosInitData && (0, _tplusPoslogin.PosInitData)('posCode'); var localStoreData = _mutantsMicrofx.localStore.get('setting_setData'); var item = localStoreData && localStoreData.find(function (value) { return value.Name === 'RE_POSProductPageStyle'; }); this.POSProductPageStyle = item && item.Value === '56831' ? false : true; } (0, _createClass3.default)(ProductStore, [{ key: 'init', value: function init(configure) { this.getProductList('init'); this.getProductLevel(configure); } }, { key: 'setLocalStorage', value: function setLocalStorage(key, value) { _mutantsMicrofx.localStore.set(key, value); } }, { key: 'getLocalStorage', value: function getLocalStorage(key) { return _mutantsMicrofx.localStore.get(key); } }, { key: 'getCurrentProductList', value: function getCurrentProductList(count) { this.pageTotalCount = Math.ceil(this.backupsProductList.length / this.showPageCount); // console.log(this.backupsProductList.length, this.showPageCount, this.pageTotalCount, 'pageTotalCount-------------------') // console.log(count * this.showPageCount, this.showPageCount * (count + 1), 'showPageCount-------------------'); this.productList = this.backupsProductList.slice(count * this.showPageCount, this.showPageCount * (count + 1)); console.log(this.productList, count * this.showPageCount, this.showPageCount * (count + 1), '====='); } }, { key: 'setShowPageCount', value: function setShowPageCount(showPageCount) { this.showPageCount = showPageCount; } }, { key: 'getProductLevel', value: function () { var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(configure) { var productLevel, Re_InventoryClass, InventoryClassNotDisplay, InventoryClassOnlyDisplay, Data; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: productLevel = this.getLocalStorage('productLevel'); Re_InventoryClass = this.getLocalStorage('Re_InventoryClass'); InventoryClassNotDisplay = this.getLocalStorage('InventoryClassNotDisplay'); InventoryClassOnlyDisplay = this.getLocalStorage('InventoryClassOnlyDisplay'); if (!(productLevel && productLevel.length > 0 && Re_InventoryClass && Re_InventoryClass == configure.Re_InventoryClass && InventoryClassNotDisplay == configure.InventoryClassNotDisplay && InventoryClassOnlyDisplay == configure.InventoryClassOnlyDisplay)) { _context.next = 8; break; } this.setProductLevel(productLevel); _context.next = 16; break; case 8: _context.next = 10; return _api2.default.loadInventoryClass(configure.idStore, this.posCode); case 10: Data = _context.sent; this.setProductLevel(Data); this.setLocalStorage("productLevel", this.productLevel); this.setLocalStorage("InventoryClassNotDisplay", configure.InventoryClassNotDisplay); this.setLocalStorage("InventoryClassOnlyDisplay", configure.InventoryClassOnlyDisplay); this.setLocalStorage("Re_InventoryClass", configure.Re_InventoryClass); case 16: return _context.abrupt('return', (0, _mobx.toJS)(this.productLevel)); case 17: case 'end': return _context.stop(); } } }, _callee, this); })); function getProductLevel(_x) { return _ref.apply(this, arguments); } return getProductLevel; }() }, { key: 'setProductLevel', value: function setProductLevel(value) { this.productLevel = value; } }, { key: 'setParams', value: function setParams(type, value) { this.params[type] = value; } }, { key: 'retrunFirsterLevel', value: function retrunFirsterLevel(ID) { this.level_1 = '-1'; this.level_2 = ''; this.changeParams('ID'); } }, { key: 'changeFirshLevel', value: function changeFirshLevel(ID) { this.level_1 = ID; var level1 = this.productLevel.filter(function (v) { return v.ID === ID; })[0]; this.level_2 = level1 && level1.ChildClass && level1.ChildClass.length > 0 ? level1.ChildClass[0].ID : ''; this.changeParams('ID'); } }, { key: 'changeSecondLevel', value: function changeSecondLevel(ID) { this.level_2 = ID; this.changeParams('ID'); } }, { key: 'getParams', value: function getParams(type) { return this.params[type]; } }, { key: 'changeParams', value: function changeParams(type, value) { if (type === 'key') { // 搜索关键字 this.level_1 = -2; this.level_2 = ''; this.params = (0, _extends3.default)({}, this.params, { Key: value, SearchType: 0, IdinventoryClass: -2, // 关键字搜索的时候,存货分类变成 全部 PageNo: 1, PageSize: this.params.PageSize }); } else if (type === 'ID') { // 按级别搜索 this.params = (0, _extends3.default)({}, this.params, { Key: '', SearchType: 0, IdinventoryClass: this.level_2 || this.level_1, PageNo: 1, PageSize: this.params.PageSize }); } } }, { key: 'reset', value: function reset() {} }, { key: 'resetParams', value: function resetParams() { this.params = { Key: '', // 存货条码录入框输入的值,可以是助记码、存货编码,也可以是条形码 SearchType: 0, // “0”不指定,1:“条形码” 2:“非条形码” IdinventoryClass: -2, // 存货分类Id,-1代表常用分类,-2代表全部分类,其他以数据库的为准 PageNo: 1, // 当前页号 从1开始 PageSize: this.params.PageSize, // 每页大小 isReturn: this.params.isReturn, IsSelfCash: _mutantsUtil.platform.isVerticalTouch }; } }, { key: 'getProductList', value: function getProductList(isInit) { var _this = this; (0, _mobx.autorun)((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { var _ref3, RetailDetailData, InventoryData, TotalCount, IsBarCode; return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: console.log(_this.params); _this.dataLoading = true; // try { _context2.next = 4; return _api2.default.searchInventory((0, _extends3.default)({}, _this.params, { posCode: _this.posCode })); case 4: _ref3 = _context2.sent; RetailDetailData = _ref3.RetailDetailData; InventoryData = _ref3.InventoryData; TotalCount = _ref3.TotalCount; IsBarCode = _ref3.IsBarCode; _this.dataLoading = false; // } catch (e) { // console.log(e); // this.dataLoading = false; // } if (!(isInit && TotalCount == 0)) { _context2.next = 14; break; } _this.changeFirshLevel(-2); isInit = null; return _context2.abrupt('return'); case 14: isInit = null; console.log(TotalCount); console.log('InventoryData===========', InventoryData); if (!(!InventoryData && _this.params.Key)) { _context2.next = 21; break; } // 重置状态 _this.resetParams(); _this.reset(); return _context2.abrupt('return'); case 21: // if (TotalCount == 1 && IsBarCode && this.params.PageNo == 1 && RetailDetailData) { // this.justOneResultCallBack && this.justOneResultCallBack(RetailDetailData); // this.resetParams(); // } if (_this.params.Key && _this.params.PageNo == 1 && InventoryData.length == 0) {// 关键字查找 查不到数据 // 重置状态 // this.resetParams(); // this.reset(); // return; } _this.setProductList(InventoryData); _this.setTotalCount(Math.ceil(TotalCount / _this.params.PageSize)); case 24: case 'end': return _context2.stop(); } } }, _callee2, _this); }))); } }, { key: 'setTotalCount', value: function setTotalCount(value) { this.pageCount = value; } }, { key: 'getMoreProductList', value: function () { var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() { return _regenerator2.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: if (this.pageCount > this.params.PageNo) { this.params = { Key: this.params.Key, SearchType: this.params.SearchType, IdinventoryClass: this.params.IdinventoryClass, PageNo: +this.params.PageNo + 1, PageSize: this.params.PageSize, Idstore: this.params.Idstore }; } case 1: case 'end': return _context3.stop(); } } }, _callee3, this); })); function getMoreProductList() { return _ref4.apply(this, arguments); } return getMoreProductList; }() }, { key: 'setProductList', value: function setProductList(Data) { var _this2 = this; if (this.params.PageNo != 1) { this.productList = this.productList.concat(Data); } else { this.productList = []; setTimeout(function () { _this2.set(Data); }); } } }, { key: 'set', value: function set(data) { this.backupsProductList = this.productList = data; !this.POSProductPageStyle && this.getCurrentProductList(0); } }, { key: 'getSecondLevelChildClass', get: function get() { var _this3 = this; var level1 = this.productLevel.filter(function (item) { return item.ID == _this3.level_1; })[0]; if (level1 && level1.ChildClass && level1.ChildClass.length > 0) { return (0, _mobx.toJS)(level1.ChildClass); } return undefined; } }, { key: 'getToJsProductList', get: function get() { return (0, _mobx.toJS)(this.productList); } }]); return ProductStore; }(), (_applyDecoratedDescriptor(_class.prototype, 'init', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'init'), _class.prototype), _descriptor = _applyDecoratedDescriptor(_class.prototype, 'level_1', [_mobx.observable], { enumerable: true, initializer: function initializer() { return '-1'; } }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'level_2', [_mobx.observable], { enumerable: true, initializer: function initializer() { return ''; } }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, 'productLevel', [_mobx.observable], { enumerable: true, initializer: function initializer() { return []; } }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, 'productList', [_mobx.observable], { enumerable: true, initializer: function initializer() { return []; } }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, 'backupsProductList', [_mobx.observable], { enumerable: true, initializer: function initializer() { return []; } }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, 'params', [_mobx.observable], { enumerable: true, initializer: function initializer() { return { Key: '', // 存货条码录入框输入的值,可以是助记码、存货编码,也可以是条形码 SearchType: 0, // “0”不指定,1:“条形码” 2:“非条形码” IdinventoryClass: -1, // 存货分类Id,-1代表常用分类,-2代表全部分类,其他以数据库的为准 PageNo: 1, // 当前页号 从1开始 PageSize: 20, // 每页大小 isReturn: false, IsSelfCash: _mutantsUtil.platform.isVerticalTouch, //是否是自助收银 Idmember: '', //会员ID Idstore: '' // 门店ID }; } }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, 'pageCount', [_mobx.observable], { enumerable: true, initializer: function initializer() { return 0; } }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, 'dataLoading', [_mobx.observable], { enumerable: true, initializer: function initializer() { return false; } }), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, 'showPageCount', [_mobx.observable], { enumerable: true, initializer: function initializer() { return 0; } }), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, 'pageTotalCount', [_mobx.observable], { enumerable: true, initializer: function initializer() { return 0; } }), _applyDecoratedDescriptor(_class.prototype, 'getCurrentProductList', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getCurrentProductList'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setShowPageCount', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setShowPageCount'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getProductLevel', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getProductLevel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setProductLevel', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setProductLevel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setParams', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setParams'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'retrunFirsterLevel', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'retrunFirsterLevel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeFirshLevel', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'changeFirshLevel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeSecondLevel', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'changeSecondLevel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getParams', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getParams'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeParams', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'changeParams'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'reset', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'reset'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'resetParams', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'resetParams'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setTotalCount', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setTotalCount'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getMoreProductList', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getMoreProductList'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setProductList', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setProductList'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getSecondLevelChildClass', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getSecondLevelChildClass'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getToJsProductList', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getToJsProductList'), _class.prototype)), _class); exports.default = ProductStore; //# sourceMappingURL=store.js.map