UNPKG

tplus-pos

Version:

pos module

386 lines (319 loc) 15.2 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _promise = require('babel-runtime/core-js/promise'); var _promise2 = _interopRequireDefault(_promise); var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); 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 _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); var _dec, _class, _class2, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _mobx = require('mobx'); var _mobx2 = _interopRequireDefault(_mobx); var _mutantsMicrofx = require('mutants-microfx'); var _mutantsAppfx = require('mutants-appfx'); var _tplusComponentsTouch = require('tplus-components-touch'); var _pageStores = require('../../pageStores'); var _tools = require('../../util/tools.js'); var _tools2 = _interopRequireDefault(_tools); var _get2 = require('lodash/get'); var _get3 = _interopRequireDefault(_get2); var _throttle2 = require('lodash/throttle'); var _throttle3 = _interopRequireDefault(_throttle2); var _tplusApi = require('tplus-api'); var _uiCommon = require('../../util/uiCommon.js'); var _uiCommon2 = _interopRequireDefault(_uiCommon); var _ControlMinDiscountRateProcessorBlock = require('../../domain/retail/validate/controlMinDiscountRate/ControlMinDiscountRateProcessorBlock'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Content = _tplusComponentsTouch.Layout.Content; var VoucherBody = (_dec = (0, _mutantsAppfx.injectViewModel)('Voucher'), _dec(_class = (0, _mutantsMicrofx.observer)(_class = (_temp = _class2 = function (_Component) { (0, _inherits3.default)(VoucherBody, _Component); function VoucherBody(props, context) { var _this2 = this; (0, _classCallCheck3.default)(this, VoucherBody); var _this = (0, _possibleConstructorReturn3.default)(this, (VoucherBody.__proto__ || (0, _getPrototypeOf2.default)(VoucherBody)).call(this, props, context)); _this.resize = function () { _this.setTableHeight(); }; _this.setTableHeight = function () { setTimeout(function () { var height = Number(_this.tableDom.clientHeight); _this.setState({ tableHeight: height }); }, 0); }; _this.isReturn = function () { var dataModel = _this.props.viewModel.store.data; var idBusiType = dataModel.IdbusiType; var isReturn = idBusiType === 35; return isReturn; }; _this.rowClick = function (type, index, record, fieldName) { var controllerEvent = _this.props.controllerEvent; if (_tools2.default.isNull(index) || _tools2.default.isNull(record)) return; //业务逻辑 switch (type) { case 'delete': if (record.uiState.record && !record.uiState.record.delete) return; controllerEvent('deleteBodyItem', { index: index }); break; case 'update': controllerEvent('updateBodyItem', { index: index, record: record }); break; case 'updateField': if (_tools2.default.isNull(fieldName)) return; var uiState = record.uiState; if (uiState[fieldName] && uiState[fieldName].disable) { if (!!uiState.disableTip) _tplusComponentsTouch.Message.info(uiState.disableTip); return; } controllerEvent('updateFieldFlow', { index: index, record: record, fieldName: fieldName }); break; case 'click': console.time('setfengtao'); controllerEvent('selectRow', { index: index, record: record }); } }; _this.handleDropBorder = function (event, width) { if (!width || !_this.isAllowDragg) return; var el = event && event.target; var key = el.getAttribute('data-line-key'); key = _this.getTableColumnName(key); _this.setVoucherWidth('RetailOrder', key, width); _this.handleTouchTableCallback(); console.log('调整列宽:' + key + ';' + width); }; _this.getTableColumnName = function (key) { var viewInfo = _this.props.viewModel; var columns = _mobx2.default.toJS(viewInfo.columns); var item = columns && columns.find(function (v) { return v.FieldName == key; }); if (item && item['Name']) { return item['Name']; } else { key = (key + "").indexOf('.') > -1 ? (key + "").replace('.', '_') : key; return key; } }; _this.handleDraggingBorder = function (event, width) { if (!width) return; var el = event && event.target; var key = el.getAttribute('data-line-key'); if (key == 'rowNum') { _this.isAllowDragg = false; } else { _this.isAllowDragg = true; } }; _this.handleTouchTableCallback = function () { var viewInfo = _this.props.viewModel; var dataSource = _mobx2.default.toJS(viewInfo.data); var wh = 0; var thead = $.find('.VoucherPattern').find('.u-table-thead'); var theadNode = thead && thead.currentNode; if (theadNode) { wh = thead.currentNode.clientWidth; } var tbody = $.find('.VoucherPattern').find('.u-table-tbody'); var tbodyNode = tbody && tbody.currentNode; if (tbodyNode && wh) { tbodyNode.style.width = wh; if (dataSource && dataSource.length == 0) { tbodyNode.style.width = wh + 'px'; tbodyNode.style.height = '1px'; tbodyNode.style.display = 'block'; } else { tbodyNode.style = ""; } } }; _this.setVoucherWidth = function () { var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(vouchername, fieldName, totalWidth) { var params, result; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: params = { vouchername: vouchername, fieldName: fieldName, totalWidth: totalWidth }; _context.next = 3; return (0, _tplusApi.tApi)((0, _extends3.default)({}, params), 'chanjet.RE.INewRetailVoucherService.setVoucherWidth', false, false); case 3: result = _context.sent; return _context.abrupt('return', result); case 5: case 'end': return _context.stop(); } } }, _callee, _this2); })); return function (_x, _x2, _x3) { return _ref.apply(this, arguments); }; }(); _this.authorityValidate = function (_ref2) { var _callback = _ref2.callback; var controllerEvent = _this.props.controllerEvent; _uiCommon2.default.mask({}); // 需要异步校验 return new _promise2.default(function (resolve, reject) { controllerEvent('authorityValidate', { callback: function callback(result) { _uiCommon2.default.deleteMask({ async: true }); _callback && _callback(result); resolve(result); } }); }); }; _this.state = { tableHeight: 200 }; _this.height = 50; return _this; } (0, _createClass3.default)(VoucherBody, [{ key: 'componentWillMount', value: function componentWillMount() { this.resizeThrottled = (0, _throttle3.default)(this.resize, 100); } }, { key: 'componentDidMount', value: function componentDidMount() { this.resize(); /* 监听页面resize */ window.addEventListener('resize', this.resizeThrottled); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { window.removeEventListener('resize', this.resizeThrottled); } }, { key: 'componentDidUpdate', value: function componentDidUpdate() { this.scrollIntoView(); } }, { key: 'scrollIntoView', value: function scrollIntoView() { var viewInfo = this.props.viewModel; var targetIndex = _mobx2.default.toJS(viewInfo.targetIndex); var scrollDom = this.tableDom.getElementsByClassName('u-table-body')[0]; if (scrollDom) { var scrollTopMin = this.height * (targetIndex + 1) - scrollDom.clientHeight; var scrollTopMax = this.height * targetIndex; var scrollTop = scrollDom.scrollTop; if (scrollTopMin > 5) { if (scrollTop < scrollTopMin) scrollDom.scrollTop = scrollTopMin; if (scrollTop > scrollTopMax) scrollDom.scrollTop = scrollTopMax; } } } }, { key: 'getWaterMark', value: function getWaterMark() { var isReturn = this.isReturn(); var stateStore = _pageStores.voucherStateStore; var waterMark = ''; if (isReturn && stateStore.mode === 'practice') { waterMark = '练习退货'; } if (!isReturn && stateStore.mode === 'practice') { waterMark = '练习收银'; } if (isReturn && stateStore.mode === 'formal') { waterMark = '零售退货'; } return waterMark; } //加载完成回调事件 /* 结算校验 */ }, { key: 'render', value: function render() { var _this3 = this; var viewInfo = this.props.viewModel; var dataSource = _mobx2.default.toJS(viewInfo.data), columns = _mobx2.default.toJS(viewInfo.columns), targetIndex = _mobx2.default.toJS(viewInfo.targetIndex); if (columns && columns.length > 0) { columns = columns.filter(function (v) { return v.Visible == true; }); } var targetData = _mobx2.default.toJS(viewInfo.retailDetails[targetIndex]); var voucherDetail = _mobx2.default.toJS(viewInfo.voucherDetail); console.log('voucher_voucherDetail=======', voucherDetail); console.log('voucher_columns=======', columns); console.log('targetData=======', targetData); var waterMark = this.getWaterMark(); var hasDataSource = !!dataSource.length; return _react2.default.createElement( _tplusComponentsTouch.Layout, { className: this.props.className, style: { height: '100%', position: 'relative' } }, _react2.default.createElement( Content, { className: _tplusComponentsTouch.hotKey.hotKeyBindClass('1', 'voucher-table') }, _react2.default.createElement( 'div', { style: { height: "100%", 'overflow': 'hidden' }, ref: function ref(dom) { _this3.tableDom = dom; } }, _react2.default.createElement(_tplusComponentsTouch.TouchTable, { badge: true, lineNum: true, isFixDelColumn: true, dragborder: true, lastColumnResize: true, onDraggingBorder: function onDraggingBorder(e, width) { return _this3.handleDraggingBorder(e, width); }, onDropBorder: function onDropBorder(e, width) { return _this3.handleDropBorder(e, width); }, waterMark: waterMark, waterMarkOption: { color: '#BEBEBE', width: "220px", height: "180px", font: "20px sans-serif", only: true }, headerHeight: 40, height: this.height, tableHeight: this.state.tableHeight - (hasDataSource ? 90 : 0), dataSource: dataSource, columns: columns, rowIndex: targetIndex, emptyStyle: waterMark ? 'none' : undefined, handleCallback: this.handleTouchTableCallback, authorityValidate: this.authorityValidate, rowClick: function rowClick(type, index, record, fieldName) { _this3.rowClick(type, index, record, fieldName); } }) ) ) ); } }]); return VoucherBody; }(_react.Component), _class2.contextTypes = { onEvent: _propTypes2.default.func }, _temp)) || _class) || _class); exports.default = VoucherBody; //# sourceMappingURL=voucherBody.js.map