tplus-pos
Version:
pos module
976 lines (824 loc) • 38.6 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
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 _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
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, _descriptor11, _descriptor12, _descriptor13, _desc2, _value2, _class3, _descriptor14, _descriptor15, _descriptor16, _descriptor17, _descriptor18, _descriptor19, _descriptor20, _descriptor21, _descriptor22, _descriptor23, _descriptor24, _descriptor25, _desc3, _value3, _class5, _descriptor26, _descriptor27, _descriptor28, _descriptor29, _descriptor30, _desc4, _value4, _class7, _descriptor31, _descriptor32, _descriptor33, _descriptor34, _descriptor35, _descriptor36, _descriptor37, _descriptor38, _descriptor39, _descriptor40, _descriptor41, _descriptor42, _descriptor43, _descriptor44, _descriptor45, _descriptor46, _descriptor47, _descriptor48, _descriptor49, _descriptor50, _descriptor51, _descriptor52, _descriptor53, _descriptor54;
var _mobx = require('mobx');
var _mutantsAppfx = require('mutants-appfx');
var _get2 = require('lodash/get');
var _get3 = _interopRequireDefault(_get2);
var _set2 = require('lodash/set');
var _set3 = _interopRequireDefault(_set2);
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 DetailTab = (_class = function () {
(0, _createClass3.default)(DetailTab, [{
key: 'setCurrent',
value: function setCurrent(index) {
this.currentIndex = index;
}
}, {
key: 'currentRow',
get: function get() {
return this.data[this.currentIndex];
} // update or copy
}]);
function DetailTab(columns) {
var _this = this;
(0, _classCallCheck3.default)(this, DetailTab);
_initDefineProp(this, 'sortBy', _descriptor, this);
_initDefineProp(this, 'mergesBy', _descriptor2, this);
_initDefineProp(this, 'addBy', _descriptor3, this);
_initDefineProp(this, 'selectIndexs', _descriptor4, this);
_initDefineProp(this, 'checkEnabled', _descriptor5, this);
_initDefineProp(this, 'clickType', _descriptor6, this);
_initDefineProp(this, 'title', _descriptor7, this);
_initDefineProp(this, 'columns', _descriptor8, this);
_initDefineProp(this, 'data', _descriptor9, this);
_initDefineProp(this, 'currentIndex', _descriptor10, this);
_initDefineProp(this, 'info', _descriptor11, this);
_initDefineProp(this, 'ok', _descriptor12, this);
_initDefineProp(this, 'cancel', _descriptor13, this);
this.columns = columns || [];
(0, _mobx.reaction)(function () {
return (0, _mobx.toJS)(_this.data);
}, function () {
var mergeData = _this.data.reduce(function (rows, it) {
var row = rows.find(function (e) {
return _this.mergesBy.every(function (key) {
return (0, _get3.default)(e, key) === (0, _get3.default)(it, key);
});
});
if (!row) {
rows.push((0, _extends3.default)({}, it));
} else if (_this.addBy) {
(0, _set3.default)(row, _this.addBy, (0, _get3.default)(row, _this.addBy) + (0, _get3.default)(it, _this.addBy));
}
return rows;
}, []);
if (mergeData.length !== _this.data.length) {
_this.data = mergeData;
}
});
}
(0, _createClass3.default)(DetailTab, [{
key: 'setColumns',
value: function setColumns(title, columns, merges, addField, sortBy, clickType) {
this.title = title;
this.mergesBy = merges;
this.addBy = addField;
this.columns = columns || [];
this.sortBy = sortBy;
this.clickType = clickType;
}
}, {
key: 'mergeColumns',
value: function mergeColumns(columns) {
var _columns,
_this2 = this;
(_columns = this.columns).push.apply(_columns, (0, _toConsumableArray3.default)(columns.filter(function (it) {
return !_this2.columns.some(function (e) {
return e.key === it.key;
});
})));
}
}, {
key: 'load',
value: function load(data) {
this.data = data || [];
}
}, {
key: 'setInfo',
value: function setInfo(info, ok, cancel) {
this.info = info;
this.ok = ok;
this.cancel = cancel;
}
}, {
key: 'mergeRows',
value: function mergeRows(i) {
var _this3 = this;
// 合并重复行
var row = this.data[i];
var detailKey = this.getDetailKey(row);
var rows = this.data.filter(function (e) {
return _this3.getDetailKey(e) === detailKey;
});
if (rows.length > 1) {
for (var _i = 1; _i < rows.length; _i++) {
var remRow = rows[_i];
this.data.splice(this.data.indexOf(remRow), 1);
if (this.addBy == 'Quantity') {
(0, _set3.default)(rows[0], this.addBy, parseInt((0, _get3.default)(rows[0], this.addBy)) + parseInt((0, _get3.default)(remRow, this.addBy)));
} else {
(0, _set3.default)(rows[0], this.addBy, (0, _get3.default)(rows[0], this.addBy) + (0, _get3.default)(remRow, this.addBy));
}
}
}
this.currentIndex = this.data.indexOf(rows[0]);
}
}, {
key: 'mergeByRow',
value: function mergeByRow(row) {}
}, {
key: 'getDetailKey',
value: function getDetailKey(detail) {
var returnKey = "";
for (var index = 0; index < this.mergesBy.length; index++) {
var value = "";
if ((0, _get3.default)(detail, this.mergesBy[index])) {
value = (0, _get3.default)(detail, this.mergesBy[index]);
}
if (value && (this.mergesBy[index] == 'ProductionDate' || this.mergesBy[index] == 'ExpiryDate')) {
var date = value;
if (typeof value == "string") {
date = new Date(value);
}
if (date > new Date(Date.parse('1900-01-01'))) {
value = date.toLocaleDateString();
} else {
value = "";
}
}
returnKey = returnKey + "|" + this.mergesBy[index] + "=" + value;
}
return returnKey;
}
}, {
key: 'updateRow',
value: function updateRow(i, raw) {
var _this4 = this;
(0, _keys2.default)(raw).forEach(function (key) {
//if (key in this.data[i]) {
_this4.data[i][key] = raw[key];
//}
});
//this.currentIndex = this.rows.findIndex(item=> item.key == i)
// this.data.forEach((item, index) => {
// console.log(item,index, '00000000')
// if (item.key === i){
// this.currentIndex = index
// }
// })
//this.currentIndex = i;
this.mergeRows(i);
}
}, {
key: 'copyRow',
value: function copyRow(i) {
// const row = this.data[i];
// if (row[this.addBy] > 0) {
// row[this.addBy] = 1;
// this.data.push(row);
// }
}
}, {
key: 'addRow',
value: function addRow(row) {
var _this5 = this;
// this.data.push(row);
// this.currentIndex = this.data.length - 1;
// this.mergeRows(this.data.length - 1);
//合并重复行
var detailKey = this.getDetailKey(row);
var rows = this.data.filter(function (e) {
return _this5.getDetailKey(e) === detailKey;
});
if (rows.length > 0) {
(0, _set3.default)(rows[0], this.addBy, parseInt((0, _get3.default)(rows[0], this.addBy)) + parseInt((0, _get3.default)(row, this.addBy)));
this.currentIndex = this.data.indexOf(rows[0]);
} else {
this.data.push(row);
this.currentIndex = this.data.length - 1;
}
}
}, {
key: 'deleteRow',
value: function deleteRow(row) {
this.data.splice(this.data.indexOf(row), 1);
this.currentIndex = this.data.length - 1;
}
}, {
key: 'showCheckBox',
value: function showCheckBox() {
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.checkEnabled = enabled;
}
}, {
key: 'select',
value: function select(index, checked) {
if (checked) {
if (this.selectIndexs.indexOf(index) === -1) {
this.selectIndexs.push(index);
}
} else {
this.selectIndexs.splice(this.selectIndexs.indexOf(index), 1);
}
}
}, {
key: 'selectAll',
value: function selectAll() {
var _selectIndexs,
_this6 = this;
(_selectIndexs = this.selectIndexs).push.apply(_selectIndexs, (0, _toConsumableArray3.default)(this.rows.map(function (d, i) {
return i;
}).filter(function (index) {
return _this6.selectIndexs.indexOf(index) === -1;
})));
}
}, {
key: 'selecteds',
get: function get() {
var _this7 = this;
return this.selectIndexs.map(function (i) {
return _this7.data[i];
});
}
}, {
key: 'rows',
get: function get() {
var _this8 = this;
return this.data.reduce(function (rows, it, i) {
// const row = rows.find(e => this.mergesBy.every(key => _get(e, key) === _get(it, key)));
// if (!row) {
rows.push((0, _extends3.default)({}, (0, _mobx.toJS)(it), {
key: i,
_checked: _this8.selectIndexs.indexOf(i) > -1
}));
// } else if (this.addBy) {
// _set(row, this.addBy, _get(row, this.addBy) + _get(it, this.addBy));
// }
return rows;
}, []).sort(function (a, b) {
return (0, _get3.default)(a, _this8.sortBy) - (0, _get3.default)(b, _this8.sortBy);
});
}
}]);
return DetailTab;
}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'sortBy', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'mergesBy', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, 'addBy', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, 'selectIndexs', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, 'checkEnabled', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, 'clickType', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, 'title', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, 'columns', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, 'data', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, 'currentIndex', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, 'info', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor12 = _applyDecoratedDescriptor(_class.prototype, 'ok', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return true;
}
}), _descriptor13 = _applyDecoratedDescriptor(_class.prototype, 'cancel', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return true;
}
}), _applyDecoratedDescriptor(_class.prototype, 'currentRow', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'currentRow'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setCurrent', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setCurrent'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'selecteds', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'selecteds'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'rows', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'rows'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setColumns', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setColumns'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'mergeColumns', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'mergeColumns'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'load', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'load'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setInfo', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setInfo'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'mergeRows', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'mergeRows'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'mergeByRow', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'mergeByRow'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getDetailKey', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'getDetailKey'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'updateRow', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'updateRow'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'copyRow', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'copyRow'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'addRow', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'addRow'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'deleteRow', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'deleteRow'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'showCheckBox', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'showCheckBox'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'select', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'select'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'selectAll', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'selectAll'), _class.prototype)), _class);
// 相关明细:赠品、打折商品
var PlanDetail = (_class3 = function () {
(0, _createClass3.default)(PlanDetail, [{
key: 'activeTab',
get: function get() {
return this.tabs[this.activeTabIndex] || this.tabs[0];
}
// 明细数据是否显示编辑
}, {
key: 'selectRow',
get: function get() {
if (this.selectIndex === -1 || this.data.length <= 0) {
return null;
}
return this.data[this.selectIndex] || null;
}
}]);
function PlanDetail(tabs) {
(0, _classCallCheck3.default)(this, PlanDetail);
_initDefineProp(this, 'title', _descriptor14, this);
_initDefineProp(this, 'visible', _descriptor15, this);
_initDefineProp(this, 'reason', _descriptor16, this);
_initDefineProp(this, 'extraMessage', _descriptor17, this);
_initDefineProp(this, 'tabs', _descriptor18, this);
_initDefineProp(this, 'activeTabIndex', _descriptor19, this);
_initDefineProp(this, 'selectorResult', _descriptor20, this);
_initDefineProp(this, 'visibleSelector', _descriptor21, this);
_initDefineProp(this, 'columns', _descriptor22, this);
_initDefineProp(this, 'data', _descriptor23, this);
_initDefineProp(this, 'selectIndex', _descriptor24, this);
_initDefineProp(this, 'titleSelector', _descriptor25, this);
this.tabs = tabs;
}
(0, _createClass3.default)(PlanDetail, [{
key: 'showSelector',
value: function showSelector(title, columns, data) {
this.titleSelector = title;
this.columns = columns;
this.data = data;
this.visibleSelector = true;
}
}, {
key: 'select',
value: function select(index) {
this.selectIndex = index;
}
}, {
key: 'hideSelector',
value: function hideSelector(reason) {
this.selectorResult = reason;
this.visibleSelector = false;
}
}, {
key: 'setActiveTab',
value: function setActiveTab(index) {
this.activeTabIndex = index;
}
}, {
key: 'createTabs',
value: function createTabs() {
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
this.tabs.clear();
for (var i = 0; i < count; i++) {
this.tabs.push(new DetailTab());
}
}
}, {
key: 'show',
value: function show(title, extraMessage) {
this.title = title;
this.visible = true;
this.reason = null;
this.extraMessage = extraMessage;
}
}, {
key: 'hide',
value: function hide() {
var reason = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ok';
this.reason = reason;
this.visible = false;
}
}, {
key: 'clear',
value: function clear() {
this.data.length = 0;
}
}], [{
key: 'fromJS',
value: function fromJS() {
var objs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [{}];
var tabs = objs.map(function (_ref) {
var columns = _ref.columns,
rows = _ref.rows;
var tab = new DetailTab(columns || []);
if (rows) {
tab.load(rows);
}
return tab;
});
var data = new PlanDetail(tabs);
return data;
}
}]);
return PlanDetail;
}(), (_descriptor14 = _applyDecoratedDescriptor(_class3.prototype, 'title', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor15 = _applyDecoratedDescriptor(_class3.prototype, 'visible', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor16 = _applyDecoratedDescriptor(_class3.prototype, 'reason', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor17 = _applyDecoratedDescriptor(_class3.prototype, 'extraMessage', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor18 = _applyDecoratedDescriptor(_class3.prototype, 'tabs', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor19 = _applyDecoratedDescriptor(_class3.prototype, 'activeTabIndex', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return 0;
}
}), _descriptor20 = _applyDecoratedDescriptor(_class3.prototype, 'selectorResult', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor21 = _applyDecoratedDescriptor(_class3.prototype, 'visibleSelector', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor22 = _applyDecoratedDescriptor(_class3.prototype, 'columns', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor23 = _applyDecoratedDescriptor(_class3.prototype, 'data', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor24 = _applyDecoratedDescriptor(_class3.prototype, 'selectIndex', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return -1;
}
}), _descriptor25 = _applyDecoratedDescriptor(_class3.prototype, 'titleSelector', [_mobx.observable], {
enumerable: true,
initializer: null
}), _applyDecoratedDescriptor(_class3.prototype, 'activeTab', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'activeTab'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'selectRow', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'selectRow'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'showSelector', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'showSelector'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'select', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'select'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'hideSelector', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'hideSelector'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'setActiveTab', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'setActiveTab'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'createTabs', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'createTabs'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'show', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'show'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'hide', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'hide'), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, 'clear', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'clear'), _class3.prototype)), _class3);
// 方案项
var PlanItem = (_class5 = function () {
function PlanItem(planList, key, title, description, extra) {
(0, _classCallCheck3.default)(this, PlanItem);
_initDefineProp(this, 'title', _descriptor26, this);
_initDefineProp(this, 'description', _descriptor27, this);
_initDefineProp(this, 'extra', _descriptor28, this);
_initDefineProp(this, 'tabs', _descriptor29, this);
_initDefineProp(this, 'visible', _descriptor30, this);
this.planList = planList;
this.key = key;
this.title = title;
this.description = description;
this.extra = extra;
this.visible = true;
}
// 方案是否显示
(0, _createClass3.default)(PlanItem, [{
key: 'remove',
value: function remove() {
this.planList.selectedDetails.splice(this.planList.selectedKeys.indexOf(this.key), 1);
this.planList.selectedKeys.splice(this.planList.selectedKeys.indexOf(this.key), 1);
}
}, {
key: 'toString',
value: function toString() {
return this.title;
}
}], [{
key: 'fromJS',
value: function fromJS(planList, obj) {
return new PlanItem(planList, obj.key, obj.title, obj.description, obj.extra);
}
}]);
return PlanItem;
}(), (_descriptor26 = _applyDecoratedDescriptor(_class5.prototype, 'title', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor27 = _applyDecoratedDescriptor(_class5.prototype, 'description', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor28 = _applyDecoratedDescriptor(_class5.prototype, 'extra', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor29 = _applyDecoratedDescriptor(_class5.prototype, 'tabs', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor30 = _applyDecoratedDescriptor(_class5.prototype, 'visible', [_mobx.observable], {
enumerable: true,
initializer: null
}), _applyDecoratedDescriptor(_class5.prototype, 'remove', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class5.prototype, 'remove'), _class5.prototype)), _class5);
// 方案列表,提供促销等方案选择
var PlanListModel = (_class7 = function (_ViewBase) {
(0, _inherits3.default)(PlanListModel, _ViewBase);
(0, _createClass3.default)(PlanListModel, [{
key: 'type',
get: function get() {
return 'PlanListModel';
}
// 所有方案项
// 选中方案,有顺序
// 相关明细数据
// 方案加载
// 方案选择事件
// 数据改变后事件
// 取消所有方案事件
}, {
key: 'selecteds',
get: function get() {
var _this10 = this;
return this.selectedKeys.map(function (key) {
return _this10.items.find(function (it) {
return key === it.key;
});
});
}
// 待选方案项
}, {
key: 'waitingItems',
get: function get() {
return this.items.filter(function (it) {
return it.visible;
});
}
// 当前有效的方案
}, {
key: 'activeItem',
get: function get() {
if (this.selecteds.length <= 0) {
return null;
}
return this.selecteds[this.selecteds.length - 1];
}
}, {
key: 'activeDetail',
get: function get() {
if (this.selecteds.length <= 0) {
return null;
}
return this.selectedDetails[this.selecteds.length - 1];
}
}]);
function PlanListModel(store, name, title, loadMapping, extraLabel, placeholder, editor, onLoad, onSelected, onDetailOk, onDetailCancel, onDetailChange, onSearch, onCancel, onOk, onRowClick, onMoreClick) {
(0, _classCallCheck3.default)(this, PlanListModel);
var _this9 = (0, _possibleConstructorReturn3.default)(this, (PlanListModel.__proto__ || (0, _getPrototypeOf2.default)(PlanListModel)).call(this, store, name));
_initDefineProp(_this9, 'visible', _descriptor31, _this9);
_initDefineProp(_this9, 'title', _descriptor32, _this9);
_initDefineProp(_this9, 'isLoading', _descriptor33, _this9);
_initDefineProp(_this9, 'result', _descriptor34, _this9);
_initDefineProp(_this9, 'loadMapping', _descriptor35, _this9);
_initDefineProp(_this9, 'detailEditor', _descriptor36, _this9);
_initDefineProp(_this9, 'extraLabel', _descriptor37, _this9);
_initDefineProp(_this9, 'placeholder', _descriptor38, _this9);
_initDefineProp(_this9, 'items', _descriptor39, _this9);
_initDefineProp(_this9, 'selectedKeys', _descriptor40, _this9);
_initDefineProp(_this9, 'selectedDetails', _descriptor41, _this9);
_initDefineProp(_this9, 'moreBtns', _descriptor42, _this9);
_initDefineProp(_this9, 'onLoad', _descriptor43, _this9);
_initDefineProp(_this9, 'onSelected', _descriptor44, _this9);
_initDefineProp(_this9, 'onDetailOk', _descriptor45, _this9);
_initDefineProp(_this9, 'onDetailCancel', _descriptor46, _this9);
_initDefineProp(_this9, 'onDetailChange', _descriptor47, _this9);
_initDefineProp(_this9, 'onSearch', _descriptor48, _this9);
_initDefineProp(_this9, 'onCancel', _descriptor49, _this9);
_initDefineProp(_this9, 'onOk', _descriptor50, _this9);
_initDefineProp(_this9, 'onSelectOk', _descriptor51, _this9);
_initDefineProp(_this9, 'onSelectCancel', _descriptor52, _this9);
_initDefineProp(_this9, 'onRowClick', _descriptor53, _this9);
_initDefineProp(_this9, 'onMoreClick', _descriptor54, _this9);
_this9.title = title;
_this9.onLoad = onLoad;
_this9.extraLabel = extraLabel;
_this9.placeholder = placeholder;
_this9.loadMapping = loadMapping;
(0, _keys2.default)(editor || {}).forEach(function (key) {
_this9.detailEditor.set(key, editor[key]);
});
_this9.onSelected = onSelected;
_this9.onDetailOk = onDetailOk;
_this9.onDetailChange = onDetailChange;
_this9.onDetailCancel = onDetailCancel;
_this9.onCancel = onCancel;
_this9.onSearch = onSearch;
_this9.onOk = onOk;
_this9.onRowClick = onRowClick;
_this9.onMoreClick = onMoreClick;
return _this9;
}
(0, _createClass3.default)(PlanListModel, [{
key: 'addMoreButtons',
value: function addMoreButtons(name, text) {
this.moreBtns.push({ name: text, action: name, visible: false });
}
}, {
key: 'setBtnVisible',
value: function setBtnVisible(name, visible) {
var btn = this.moreBtns.find(function (it) {
return it.action === name;
});
btn.visible = visible;
}
}, {
key: 'show',
value: function show() {
this.visible = true;
}
}, {
key: 'hide',
value: function hide(result) {
this.result = result;
this.visible = false;
}
// 加载方案
}, {
key: 'load',
value: function load(planItems) {
var _items,
_this11 = this;
this.clear();
this.items.length = 0;
var mapping = void 0;
if (this.loadMapping) {
mapping = new _mutantsAppfx.Expression(this.loadMapping);
}
(_items = this.items).push.apply(_items, (0, _toConsumableArray3.default)(planItems.map(function (it) {
return PlanItem.fromJS(_this11, mapping ? mapping.exec(it) : it);
})));
}
}, {
key: 'setVisible',
value: function setVisible(items) {
this.items.forEach(function (it) {
it.visible = items.some(function (sit) {
return sit === it.key;
});
});
}
// 选中方案
}, {
key: 'select',
value: function select(key) {
this.selectedKeys.push(key);
var detail = PlanDetail.fromJS();
this.selectedDetails.push(detail);
}
// 清空选中方案
}, {
key: 'clear',
value: function clear() {
this.selectedKeys.length = 0;
this.selectedDetails.length = 0;
this.items.forEach(function (it) {
return it.visible = true;
});
}
}], [{
key: 'fromJS',
value: function fromJS(store, _ref2) {
var _ref2$planInfo = _ref2.planInfo,
planInfo = _ref2$planInfo === undefined ? {} : _ref2$planInfo;
return new PlanListModel(store, planInfo.name, planInfo.title, planInfo.loadMapping, planInfo.extraLabel, planInfo.placeholder, planInfo.editor, _mutantsAppfx.Action.fromJS(store, planInfo.onLoad), _mutantsAppfx.Action.fromJS(store, planInfo.onSelected), _mutantsAppfx.Action.fromJS(store, planInfo.onDetailOk), _mutantsAppfx.Action.fromJS(store, planInfo.onDetailCancel), _mutantsAppfx.Action.fromJS(store, planInfo.onDetailChange), _mutantsAppfx.Action.fromJS(store, planInfo.onSearch), _mutantsAppfx.Action.fromJS(store, planInfo.onCancel), _mutantsAppfx.Action.fromJS(store, planInfo.onOk), _mutantsAppfx.Action.fromJS(store, planInfo.onRowClick), _mutantsAppfx.Action.fromJS(store, planInfo.onMoreClick));
}
}]);
return PlanListModel;
}(_mutantsAppfx.ViewBase), (_descriptor31 = _applyDecoratedDescriptor(_class7.prototype, 'visible', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor32 = _applyDecoratedDescriptor(_class7.prototype, 'title', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor33 = _applyDecoratedDescriptor(_class7.prototype, 'isLoading', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor34 = _applyDecoratedDescriptor(_class7.prototype, 'result', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor35 = _applyDecoratedDescriptor(_class7.prototype, 'loadMapping', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor36 = _applyDecoratedDescriptor(_class7.prototype, 'detailEditor', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return _mobx.observable.map();
}
}), _descriptor37 = _applyDecoratedDescriptor(_class7.prototype, 'extraLabel', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor38 = _applyDecoratedDescriptor(_class7.prototype, 'placeholder', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor39 = _applyDecoratedDescriptor(_class7.prototype, 'items', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor40 = _applyDecoratedDescriptor(_class7.prototype, 'selectedKeys', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor41 = _applyDecoratedDescriptor(_class7.prototype, 'selectedDetails', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor42 = _applyDecoratedDescriptor(_class7.prototype, 'moreBtns', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor43 = _applyDecoratedDescriptor(_class7.prototype, 'onLoad', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor44 = _applyDecoratedDescriptor(_class7.prototype, 'onSelected', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor45 = _applyDecoratedDescriptor(_class7.prototype, 'onDetailOk', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor46 = _applyDecoratedDescriptor(_class7.prototype, 'onDetailCancel', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor47 = _applyDecoratedDescriptor(_class7.prototype, 'onDetailChange', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor48 = _applyDecoratedDescriptor(_class7.prototype, 'onSearch', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor49 = _applyDecoratedDescriptor(_class7.prototype, 'onCancel', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor50 = _applyDecoratedDescriptor(_class7.prototype, 'onOk', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor51 = _applyDecoratedDescriptor(_class7.prototype, 'onSelectOk', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor52 = _applyDecoratedDescriptor(_class7.prototype, 'onSelectCancel', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor53 = _applyDecoratedDescriptor(_class7.prototype, 'onRowClick', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor54 = _applyDecoratedDescriptor(_class7.prototype, 'onMoreClick', [_mobx.observable], {
enumerable: true,
initializer: null
}), _applyDecoratedDescriptor(_class7.prototype, 'selecteds', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'selecteds'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'waitingItems', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'waitingItems'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'activeItem', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'activeItem'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'activeDetail', [_mobx.computed], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'activeDetail'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'addMoreButtons', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'addMoreButtons'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'setBtnVisible', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'setBtnVisible'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'show', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'show'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'hide', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'hide'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'load', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'load'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'setVisible', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'setVisible'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'select', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'select'), _class7.prototype), _applyDecoratedDescriptor(_class7.prototype, 'clear', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class7.prototype, 'clear'), _class7.prototype)), _class7);
exports.default = PlanListModel;
//# sourceMappingURL=PlanListModel.js.map