tplus-pos
Version:
pos module
409 lines (340 loc) • 15.8 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Member = 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 _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 _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, _desc2, _value2, _class3, _descriptor5, _descriptor6;
var _tplusApi = require('tplus-api');
var _mobx = require('mobx');
var _each2 = require('lodash/each');
var _each3 = _interopRequireDefault(_each2);
var _findIndex2 = require('lodash/findIndex');
var _findIndex3 = _interopRequireDefault(_findIndex2);
var _utils = require('../selfsettle/utils');
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 SelfSettlementStore = (_class = function () {
function SelfSettlementStore() {
var _this = this;
(0, _classCallCheck3.default)(this, SelfSettlementStore);
_initDefineProp(this, 'amount', _descriptor, this);
this.quantity = 0;
_initDefineProp(this, 'paymodes', _descriptor2, this);
_initDefineProp(this, 'quickmode', _descriptor3, this);
_initDefineProp(this, 'czkenabled', _descriptor4, this);
this.validePwd = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(value) {
var result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return (0, _tplusApi.tApi)({ "CheckoutParams": {
"Idmember": _this.member.id,
"Password": value
} }, 'AA.DR.newRetailMember.CheckoutMemberPassword', false, false);
case 3:
result = _context.sent;
return _context.abrupt('return', _promise2.default.resolve(result.Success ? "" : result.Message));
case 7:
_context.prev = 7;
_context.t0 = _context['catch'](0);
return _context.abrupt('return', "failed");
case 10:
case 'end':
return _context.stop();
}
}
}, _callee, _this, [[0, 7]]);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
}
(0, _createClass3.default)(SelfSettlementStore, [{
key: 'init',
value: function init(store) {
var _this2 = this;
var data = store.data,
onHandleAmount = store.onHandleAmount,
voucherVM = store.voucherVM;
this.dto = data.dto;
this.member = new Member(data.member);
this.quantity = data.totalQuantity;
this.discount = data.totalDiscountAmount;
(0, _mobx.runInAction)(function () {
_this2.amount = data.totalTaxAmount;
});
if (onHandleAmount) {
onHandleAmount(_utils.PayStyle.hyczk).then(function () {
(0, _mobx.runInAction)(function () {
_this2.czkenabled = voucherVM.store.getViewItem('Voucher').availableAmount == _this2.amount;
});
});
}
}
}, {
key: 'setQuickmode',
value: function setQuickmode(mode) {
this.quickmode = mode || this.quickmode;
this.setTheMode(mode || this.quickmode);
}
}, {
key: 'setTheMode',
value: function setTheMode(mode) {
this.themode = mode;
if (mode) {
this.paymentType = mode.paymentType;
}
}
}, {
key: 'setMember',
value: function setMember(m) {
this.member = new Member(m);
}
}, {
key: 'commit',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return this.save();
case 3:
return _context2.abrupt('return', _promise2.default.resolve(true));
case 6:
_context2.prev = 6;
_context2.t0 = _context2['catch'](0);
console.error('settlementStore.commit失败,错误信息:' + _context2.t0);
return _context2.abrupt('return', _promise2.default.resolve(_context2.t0));
case 10:
case 'end':
return _context2.stop();
}
}
}, _callee2, this, [[0, 6]]);
}));
function commit() {
return _ref2.apply(this, arguments);
}
return commit;
}()
}, {
key: 'save',
value: function save() {
var _this3 = this;
var mode = this;
(0, _mobx.runInAction)(function () {
_this3.dto.RetailPaymentDetails = [];
_this3.dto.RetailStorageDetails = [];
var value = parseFloat(_this3.amount);
if (_this3.paymentType == _utils.PayStyle.hyczk) {
_this3.dto.RetailStorageDetails.push({
Code: mode.paymethodId,
StoragePaymentAmount: value,
IsOrigReturn: false,
BalanceStorage: _this3.member.balance - value,
Idmember: mode.member.id,
DynamicPropertyKeys: [],
DynamicPropertyValues: [],
DataSource: { Id: _this3.dto.DataSource.Id },
Password: mode.authCode
});
if (!_this3.dto.Idmember) {
_this3.dto.Idmember = mode.member.id;
}
}
_this3.dto.RetailPaymentDetails.push({
Code: mode.paymethodId,
OrigAmount: _this3.themode.exchangeRate != 1 ? _this3.themode.calDirection == "88" ? value / _this3.themode.exchangeRate : value * _this3.themode.exchangeRate : value,
Amount: value,
GiveChange: 0,
IdsettleStyle: _this3.themode.idSettleStyle,
IdbankAccount: _this3.themode.idBankAccount,
Idcurrency: _this3.themode.idCurrency,
ExchangeRate: _this3.themode.exchangeRate,
PaymentCode: _this3.authCode,
DynamicPropertyKeys: [],
DynamicPropertyValues: [],
DataSource: { Id: _this3.dto.DataSource.Id }
});
});
console.log('结算数据:', this.dto);
return (0, _tplusApi.tApi)({ dto: this.dto.cut() }, 'chanjet.RE.newRetail.Settle', false, false).then(function (resp) {
(0, _mobx.runInAction)(function () {
_this3.dto.ID = resp.ID;
});
});
}
}, {
key: 'genMode',
value: function genMode(mode, bquick) {
return {
name: mode.Name,
isDefault: mode.IsDefaultSettleStyle,
isQuick: bquick,
hotKey: '',
orderBy: 1,
paymentType: mode.Code,
idSettleStyle: mode.IdSettleStyle,
idBankAccount: mode.IdBankAccount,
exchangeRate: mode.Currency ? mode.Currency.ExchangeRate : 1,
idCurrency: mode.Currency ? mode.Currency.ID : -1,
calDirection: mode.Currency ? mode.Currency.CalDirection.Id : "88",
bankNoType: mode.BankNoType
};
}
}, {
key: 'getPaymodes',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
var _this4 = this;
var modes;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return (0, _tplusApi.tApi)({ settleStyleType: '63003' }, 'chanjet.RE.NewPos.GetStoreSettleStyles', false, false);
case 2:
modes = _context3.sent;
if (modes) {
(0, _mobx.runInAction)(function () {
_this4.paymodes = [];
if (modes.QuickSettleStyles.length > 0) {
var mode = _this4.genMode(modes.QuickSettleStyles[0], true);
_this4.paymodes.push(mode);
_this4.setQuickmode(mode);
}
(0, _each3.default)(modes.SettleStyles, function (mode) {
_this4.paymodes.push(_this4.genMode(mode));
});
});
}
case 4:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function getPaymodes() {
return _ref3.apply(this, arguments);
}
return getPaymodes;
}()
}]);
return SelfSettlementStore;
}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'amount', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'paymodes', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, 'quickmode', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, 'czkenabled', [_mobx.observable], {
enumerable: true,
initializer: function initializer() {
return true;
}
}), _applyDecoratedDescriptor(_class.prototype, 'setQuickmode', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'setQuickmode'), _class.prototype)), _class);
exports.default = SelfSettlementStore;
var Member = exports.Member = (_class3 = function () {
function Member(m) {
var _this5 = this;
(0, _classCallCheck3.default)(this, Member);
_initDefineProp(this, 'cardNo', _descriptor5, this);
_initDefineProp(this, 'balance', _descriptor6, this);
if (m) {
this.id = m.ID;
this.uid = m.Uid;
this.type = m.MemberType ? m.MemberType.Name : "普通";
this.rawbalance = m.BalanceStorage;
var index = (0, _findIndex3.default)(m.DynamicPropertyKeys, function (key) {
return key == 'canusedbalancestorage';
});
(0, _mobx.runInAction)(function () {
_this5.cardNo = m.CardCode;
if (index >= 0) {
_this5.balance = parseFloat(m.DynamicPropertyValues[index]);
} else {
_this5.balance = _this5.rawbalance;
}
});
this.needPwd = m.MemberType ? m.MemberType.IsNeedPwd : false;
this.NeedModifyPassword = m.NeedModifyPassword;
}
}
(0, _createClass3.default)(Member, [{
key: 'setCardNo',
value: function setCardNo(v) {
this.cardNo = v;
}
}]);
return Member;
}(), (_descriptor5 = _applyDecoratedDescriptor(_class3.prototype, 'cardNo', [_mobx.observable], {
enumerable: true,
initializer: null
}), _descriptor6 = _applyDecoratedDescriptor(_class3.prototype, 'balance', [_mobx.observable], {
enumerable: true,
initializer: null
}), _applyDecoratedDescriptor(_class3.prototype, 'setCardNo', [_mobx.action], (0, _getOwnPropertyDescriptor2.default)(_class3.prototype, 'setCardNo'), _class3.prototype)), _class3);
//# sourceMappingURL=selfSettlementStore.js.map