kts-component-invoice-operate 1.0.95 → 1.0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ declare const _default: (key: string | undefined, delayed: number | undefined, fn: Function) => void;
2
+ /**
3
+ * 有冷却时间的函数
4
+ * @param fn 方法
5
+ * @param key 方法key
6
+ * @param delayed 冷却时间
7
+ */
8
+ export default _default;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 判断一个字符串得字节长度
3
+ * @param str
4
+ * @returns
5
+ */
6
+ export declare function bytesLnegth(str: string): number;
7
+ export declare function cutStr(str: string, L: number): string | undefined;
package/dist/index.esm.js CHANGED
@@ -2,11 +2,11 @@ import 'kts-components-antd-x3/dist/kts-components-antd-x3.css';
2
2
  import React, { createElement } from 'react';
3
3
  import GreyReactBox, { decorator } from 'grey-react-box';
4
4
  import { chain as chain$1, bignumber, create, all } from 'mathjs';
5
- import { message, Form, Input, Icon, Tag, Select, Row, Col, Table, Button, Switch, Typography, Drawer, Menu, Dropdown, AutoComplete, Spin, Checkbox, Descriptions } from 'kts-components-antd-x3';
5
+ import { message, Form, Input, Icon, Tag, Select, Row, Col, Table, Button, Switch, Typography, Drawer, Menu, Dropdown, AutoComplete, Spin, Checkbox, Descriptions, Modal } from 'kts-components-antd-x3';
6
6
  import { v4 } from 'uuid';
7
7
  import classnames from 'classnames';
8
- import { createAsyncFormActions, FormEffectHooks, SchemaForm, FormButtonGroup, SchemaMarkupField } from '@formily/antd';
9
8
  import { Input as Input$1, NumberPicker } from '@formily/antd-components';
9
+ import { createAsyncFormActions, FormEffectHooks, SchemaForm, FormButtonGroup, SchemaMarkupField } from '@formily/antd';
10
10
 
11
11
  function ownKeys(object, enumerableOnly) {
12
12
  var keys = Object.keys(object);
@@ -2091,6 +2091,29 @@ var DrawerBody = decorator(Form.create())(function (props) {
2091
2091
  }, "\u4FDD\u5B58")));
2092
2092
  });
2093
2093
 
2094
+ var keys = {};
2095
+ /**
2096
+ * 有冷却时间的函数
2097
+ * @param fn 方法
2098
+ * @param key 方法key
2099
+ * @param delayed 冷却时间
2100
+ */
2101
+
2102
+ var coolingFn = (function () {
2103
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
2104
+ var delayed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
2105
+ var fn = arguments.length > 2 ? arguments[2] : undefined;
2106
+
2107
+ if (keys[key]) {
2108
+ return;
2109
+ } else {
2110
+ fn();
2111
+ keys[key] = setTimeout(function () {
2112
+ delete keys[key];
2113
+ }, delayed);
2114
+ }
2115
+ });
2116
+
2094
2117
  var EndowCodeButton = (function () {
2095
2118
  var controller = default_1.useInvoiceController();
2096
2119
  /** 是否禁用 */
@@ -2123,9 +2146,8 @@ var EndowCodeButton = (function () {
2123
2146
  break;
2124
2147
  }
2125
2148
 
2126
- message.error({
2127
- content: '不能给正在编辑的货物赋码',
2128
- key: '不能给正在编辑的货物赋码'
2149
+ coolingFn('不能给正在编辑的货物赋码', 3000, function () {
2150
+ message.error('不能给正在编辑的货物赋码');
2129
2151
  });
2130
2152
  return _context.abrupt("return");
2131
2153
 
@@ -2141,9 +2163,8 @@ var EndowCodeButton = (function () {
2141
2163
  break;
2142
2164
  }
2143
2165
 
2144
- message.error({
2145
- content: '商品税率不一致不能操作批量赋码',
2146
- key: '商品税率不一致不能操作批量赋码'
2166
+ coolingFn('商品税率不一致不能操作批量赋码', 3000, function () {
2167
+ message.error('商品税率不一致不能操作批量赋码');
2147
2168
  });
2148
2169
  return _context.abrupt("return");
2149
2170
 
@@ -4479,9 +4500,7 @@ var Main = decorator(Form.create())(function (props) {
4479
4500
 
4480
4501
  React.useEffect(function () {
4481
4502
  var click = function click() {
4482
- setTimeout(function () {
4483
- controller.saveEditGood();
4484
- });
4503
+ setTimeout(controller.saveEditGood);
4485
4504
  };
4486
4505
 
4487
4506
  window.addEventListener('click', click);
@@ -4934,7 +4953,7 @@ var ImportBuyerDrawer = (function () {
4934
4953
  return /*#__PURE__*/React.createElement(Drawer, {
4935
4954
  title: "\u8D2D\u65B9\u5217\u8868",
4936
4955
  placement: "right",
4937
- closable: false,
4956
+ // closable={false}
4938
4957
  destroyOnClose: true,
4939
4958
  width: 983,
4940
4959
  onClose: onClose,
@@ -5039,6 +5058,7 @@ var ImportGoodsDrawer = (function () {
5039
5058
  return s.goodsListState.importGoods.topExpand;
5040
5059
  }, []);
5041
5060
  var onClose = React.useCallback(function () {
5061
+ console.log('===> 关闭抽屉');
5042
5062
  controller.pipeline( /*#__PURE__*/function () {
5043
5063
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(s) {
5044
5064
  return regeneratorRuntime.wrap(function _callee$(_context) {
@@ -5063,14 +5083,11 @@ var ImportGoodsDrawer = (function () {
5063
5083
  return /*#__PURE__*/React.createElement(Drawer, {
5064
5084
  title: "\u5546\u54C1\u5217\u8868",
5065
5085
  placement: "right",
5066
- closable: false,
5086
+ // closable={false}
5067
5087
  destroyOnClose: true,
5068
5088
  width: 983,
5069
5089
  onClose: onClose,
5070
- visible: visible,
5071
- getContainer: function getContainer() {
5072
- return window.document.querySelector('.kts-invoice-operate-goods-list-able');
5073
- }
5090
+ visible: visible
5074
5091
  }, topExpand && /*#__PURE__*/React.createElement("div", {
5075
5092
  style: {
5076
5093
  marginBottom: 10
@@ -5088,11 +5105,7 @@ var DrawerBody$2 = function DrawerBody() {
5088
5105
  }, []);
5089
5106
  var pagination = controller.useMemo(function (s) {
5090
5107
  return s.goodsListState.importGoods.pagination;
5091
- }, []);
5092
-
5093
- var _React$useState = React.useState(controller.state.goodsListState.editGood),
5094
- _React$useState2 = _slicedToArray(_React$useState, 1),
5095
- editGood = _React$useState2[0];
5108
+ }, []); // const [editGood] = React.useState(controller.state.goodsListState.editGood);
5096
5109
 
5097
5110
  React.useEffect(function () {
5098
5111
  controller.getGoodsList && controller.getGoodsList({
@@ -5210,9 +5223,61 @@ var getPriceExcludeTax = function getPriceExcludeTax(s, record) {
5210
5223
  return format15(evaluate("".concat(record.priceIncludeTax, " / (1+").concat(s.taxRate, "/100)")));
5211
5224
  };
5212
5225
 
5226
+ /**
5227
+ * 判断一个字符串得字节长度
5228
+ * @param str
5229
+ * @returns
5230
+ */
5231
+ function bytesLnegth(str) {
5232
+ var count = str.length;
5233
+
5234
+ for (var i = 0; i < str.length; i++) {
5235
+ if (str.charCodeAt(i) > 255) {
5236
+ count++;
5237
+ }
5238
+ }
5239
+
5240
+ return count;
5241
+ }
5242
+ /*
5243
+ * param str 要截取的字符串
5244
+ * param L 要截取的字节长度,注意是字节不是字符,一个汉字两个字节
5245
+ * return 截取后的字符串
5246
+ */
5247
+
5248
+ function cutStr(str, L) {
5249
+ var result = '',
5250
+ strlen = str.length,
5251
+ // 字符串长度
5252
+ chrlen = str.replace(/[^\x00-\xff]/g, '**').length; // 字节长度
5253
+
5254
+ if (chrlen <= L) {
5255
+ return str;
5256
+ }
5257
+
5258
+ for (var i = 0, j = 0; i < strlen; i++) {
5259
+ var chr = str.charAt(i);
5260
+
5261
+ if (/[\x00-\xff]/.test(chr)) {
5262
+ j++; // ascii码为0-255,一个字符就是一个字节的长度
5263
+ } else {
5264
+ j += 2; // ascii码为0-255以外,一个字符就是两个字节的长度
5265
+ }
5266
+
5267
+ if (j <= L) {
5268
+ // 当加上当前字符以后,如果总字节长度小于等于L,则将当前字符真实的+在result后
5269
+ result += chr;
5270
+ } else {
5271
+ // 反之则说明result已经是不拆分字符的情况下最接近L的值了,直接返回
5272
+ return result;
5273
+ }
5274
+ }
5275
+ }
5276
+
5213
5277
  var css_248z$a = ".kts-invoice-operate-goods-endow-code-button-list {\n display: flex;\n flex-direction: column;\n}\n.kts-invoice-operate-goods-endow-code-button-list > button {\n margin-bottom: 10px;\n}\n";
5214
5278
  styleInject(css_248z$a);
5215
5279
 
5280
+ var confirm = Modal.confirm;
5216
5281
  var EndowCodeDrawer = (function () {
5217
5282
  var controller = default_1.useInvoiceController();
5218
5283
  var visible = controller.useMemo(function (s) {
@@ -5482,12 +5547,16 @@ var DrawerBody$3 = function DrawerBody(props) {
5482
5547
  var onSubmit = React.useCallback(function (values) {
5483
5548
  controller.pipeline( /*#__PURE__*/function () {
5484
5549
  var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(s) {
5550
+ var endowCodeGood;
5485
5551
  return regeneratorRuntime.wrap(function _callee6$(_context6) {
5486
5552
  while (1) {
5487
5553
  switch (_context6.prev = _context6.next) {
5488
5554
  case 0:
5489
- s.goodsListState.endowCode.endowcodeGoodIndex.forEach(function (e) {
5490
- var good = s.goodsListState.goodsMap.get(e);
5555
+ endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(function (e) {
5556
+ return s.goodsListState.goodsMap.get(e);
5557
+ }); // 赋码
5558
+
5559
+ endowCodeGood.forEach(function (good) {
5491
5560
  if (!good) return; // const name = getItemName(good.itemName, values.shorthand);
5492
5561
 
5493
5562
  good.itemName = getItemName$1(good.itemName, values.shorthand); // `*${values.shorthand}*${name}`;
@@ -5512,11 +5581,41 @@ var DrawerBody$3 = function DrawerBody(props) {
5512
5581
  }
5513
5582
 
5514
5583
  good.taxAmount = chain$1(bignumber(good.lineAmountIncludeTax)).subtract(bignumber(good.lineAmountExcludeTax)).done().toNumber();
5515
- });
5584
+ }); //截取名称
5585
+
5586
+ if (!endowCodeGood.some(function (e) {
5587
+ return bytesLnegth((e === null || e === void 0 ? void 0 : e.itemName) || '') > 100;
5588
+ })) {
5589
+ _context6.next = 5;
5590
+ break;
5591
+ }
5592
+
5593
+ _context6.next = 5;
5594
+ return function () {
5595
+ return new Promise(function (resolve) {
5596
+ confirm({
5597
+ title: '温馨提示',
5598
+ content: '商品名称长度过长,是否截取名称',
5599
+ onOk: function onOk() {
5600
+ endowCodeGood.forEach(function (e) {
5601
+ if (e && e.itemName) {
5602
+ e.itemName = cutStr(e.itemName, 99);
5603
+ }
5604
+ });
5605
+ resolve();
5606
+ },
5607
+ onCancel: function onCancel() {
5608
+ resolve();
5609
+ }
5610
+ });
5611
+ });
5612
+ }();
5613
+
5614
+ case 5:
5516
5615
  s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
5517
5616
  s.goodsListState.endowCode.endowcodeGoodIndex = [];
5518
5617
 
5519
- case 3:
5618
+ case 7:
5520
5619
  case "end":
5521
5620
  return _context6.stop();
5522
5621
  }
package/dist/index.js CHANGED
@@ -9,8 +9,8 @@ var mathjs = require('mathjs');
9
9
  var ktsComponentsAntdX3 = require('kts-components-antd-x3');
10
10
  var uuid = require('uuid');
11
11
  var classnames = require('classnames');
12
- var antd = require('@formily/antd');
13
12
  var antdComponents = require('@formily/antd-components');
13
+ var antd = require('@formily/antd');
14
14
 
15
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
16
 
@@ -2101,6 +2101,29 @@ var DrawerBody = GreyReactBox.decorator(ktsComponentsAntdX3.Form.create())(funct
2101
2101
  }, "\u4FDD\u5B58")));
2102
2102
  });
2103
2103
 
2104
+ var keys = {};
2105
+ /**
2106
+ * 有冷却时间的函数
2107
+ * @param fn 方法
2108
+ * @param key 方法key
2109
+ * @param delayed 冷却时间
2110
+ */
2111
+
2112
+ var coolingFn = (function () {
2113
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
2114
+ var delayed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
2115
+ var fn = arguments.length > 2 ? arguments[2] : undefined;
2116
+
2117
+ if (keys[key]) {
2118
+ return;
2119
+ } else {
2120
+ fn();
2121
+ keys[key] = setTimeout(function () {
2122
+ delete keys[key];
2123
+ }, delayed);
2124
+ }
2125
+ });
2126
+
2104
2127
  var EndowCodeButton = (function () {
2105
2128
  var controller = default_1.useInvoiceController();
2106
2129
  /** 是否禁用 */
@@ -2133,9 +2156,8 @@ var EndowCodeButton = (function () {
2133
2156
  break;
2134
2157
  }
2135
2158
 
2136
- ktsComponentsAntdX3.message.error({
2137
- content: '不能给正在编辑的货物赋码',
2138
- key: '不能给正在编辑的货物赋码'
2159
+ coolingFn('不能给正在编辑的货物赋码', 3000, function () {
2160
+ ktsComponentsAntdX3.message.error('不能给正在编辑的货物赋码');
2139
2161
  });
2140
2162
  return _context.abrupt("return");
2141
2163
 
@@ -2151,9 +2173,8 @@ var EndowCodeButton = (function () {
2151
2173
  break;
2152
2174
  }
2153
2175
 
2154
- ktsComponentsAntdX3.message.error({
2155
- content: '商品税率不一致不能操作批量赋码',
2156
- key: '商品税率不一致不能操作批量赋码'
2176
+ coolingFn('商品税率不一致不能操作批量赋码', 3000, function () {
2177
+ ktsComponentsAntdX3.message.error('商品税率不一致不能操作批量赋码');
2157
2178
  });
2158
2179
  return _context.abrupt("return");
2159
2180
 
@@ -4489,9 +4510,7 @@ var Main = GreyReactBox.decorator(ktsComponentsAntdX3.Form.create())(function (p
4489
4510
 
4490
4511
  React__default['default'].useEffect(function () {
4491
4512
  var click = function click() {
4492
- setTimeout(function () {
4493
- controller.saveEditGood();
4494
- });
4513
+ setTimeout(controller.saveEditGood);
4495
4514
  };
4496
4515
 
4497
4516
  window.addEventListener('click', click);
@@ -4944,7 +4963,7 @@ var ImportBuyerDrawer = (function () {
4944
4963
  return /*#__PURE__*/React__default['default'].createElement(ktsComponentsAntdX3.Drawer, {
4945
4964
  title: "\u8D2D\u65B9\u5217\u8868",
4946
4965
  placement: "right",
4947
- closable: false,
4966
+ // closable={false}
4948
4967
  destroyOnClose: true,
4949
4968
  width: 983,
4950
4969
  onClose: onClose,
@@ -5049,6 +5068,7 @@ var ImportGoodsDrawer = (function () {
5049
5068
  return s.goodsListState.importGoods.topExpand;
5050
5069
  }, []);
5051
5070
  var onClose = React__default['default'].useCallback(function () {
5071
+ console.log('===> 关闭抽屉');
5052
5072
  controller.pipeline( /*#__PURE__*/function () {
5053
5073
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(s) {
5054
5074
  return regeneratorRuntime.wrap(function _callee$(_context) {
@@ -5073,14 +5093,11 @@ var ImportGoodsDrawer = (function () {
5073
5093
  return /*#__PURE__*/React__default['default'].createElement(ktsComponentsAntdX3.Drawer, {
5074
5094
  title: "\u5546\u54C1\u5217\u8868",
5075
5095
  placement: "right",
5076
- closable: false,
5096
+ // closable={false}
5077
5097
  destroyOnClose: true,
5078
5098
  width: 983,
5079
5099
  onClose: onClose,
5080
- visible: visible,
5081
- getContainer: function getContainer() {
5082
- return window.document.querySelector('.kts-invoice-operate-goods-list-able');
5083
- }
5100
+ visible: visible
5084
5101
  }, topExpand && /*#__PURE__*/React__default['default'].createElement("div", {
5085
5102
  style: {
5086
5103
  marginBottom: 10
@@ -5098,11 +5115,7 @@ var DrawerBody$2 = function DrawerBody() {
5098
5115
  }, []);
5099
5116
  var pagination = controller.useMemo(function (s) {
5100
5117
  return s.goodsListState.importGoods.pagination;
5101
- }, []);
5102
-
5103
- var _React$useState = React__default['default'].useState(controller.state.goodsListState.editGood),
5104
- _React$useState2 = _slicedToArray(_React$useState, 1),
5105
- editGood = _React$useState2[0];
5118
+ }, []); // const [editGood] = React.useState(controller.state.goodsListState.editGood);
5106
5119
 
5107
5120
  React__default['default'].useEffect(function () {
5108
5121
  controller.getGoodsList && controller.getGoodsList({
@@ -5220,9 +5233,61 @@ var getPriceExcludeTax = function getPriceExcludeTax(s, record) {
5220
5233
  return format15(evaluate("".concat(record.priceIncludeTax, " / (1+").concat(s.taxRate, "/100)")));
5221
5234
  };
5222
5235
 
5236
+ /**
5237
+ * 判断一个字符串得字节长度
5238
+ * @param str
5239
+ * @returns
5240
+ */
5241
+ function bytesLnegth(str) {
5242
+ var count = str.length;
5243
+
5244
+ for (var i = 0; i < str.length; i++) {
5245
+ if (str.charCodeAt(i) > 255) {
5246
+ count++;
5247
+ }
5248
+ }
5249
+
5250
+ return count;
5251
+ }
5252
+ /*
5253
+ * param str 要截取的字符串
5254
+ * param L 要截取的字节长度,注意是字节不是字符,一个汉字两个字节
5255
+ * return 截取后的字符串
5256
+ */
5257
+
5258
+ function cutStr(str, L) {
5259
+ var result = '',
5260
+ strlen = str.length,
5261
+ // 字符串长度
5262
+ chrlen = str.replace(/[^\x00-\xff]/g, '**').length; // 字节长度
5263
+
5264
+ if (chrlen <= L) {
5265
+ return str;
5266
+ }
5267
+
5268
+ for (var i = 0, j = 0; i < strlen; i++) {
5269
+ var chr = str.charAt(i);
5270
+
5271
+ if (/[\x00-\xff]/.test(chr)) {
5272
+ j++; // ascii码为0-255,一个字符就是一个字节的长度
5273
+ } else {
5274
+ j += 2; // ascii码为0-255以外,一个字符就是两个字节的长度
5275
+ }
5276
+
5277
+ if (j <= L) {
5278
+ // 当加上当前字符以后,如果总字节长度小于等于L,则将当前字符真实的+在result后
5279
+ result += chr;
5280
+ } else {
5281
+ // 反之则说明result已经是不拆分字符的情况下最接近L的值了,直接返回
5282
+ return result;
5283
+ }
5284
+ }
5285
+ }
5286
+
5223
5287
  var css_248z$a = ".kts-invoice-operate-goods-endow-code-button-list {\n display: flex;\n flex-direction: column;\n}\n.kts-invoice-operate-goods-endow-code-button-list > button {\n margin-bottom: 10px;\n}\n";
5224
5288
  styleInject(css_248z$a);
5225
5289
 
5290
+ var confirm = ktsComponentsAntdX3.Modal.confirm;
5226
5291
  var EndowCodeDrawer = (function () {
5227
5292
  var controller = default_1.useInvoiceController();
5228
5293
  var visible = controller.useMemo(function (s) {
@@ -5492,12 +5557,16 @@ var DrawerBody$3 = function DrawerBody(props) {
5492
5557
  var onSubmit = React__default['default'].useCallback(function (values) {
5493
5558
  controller.pipeline( /*#__PURE__*/function () {
5494
5559
  var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(s) {
5560
+ var endowCodeGood;
5495
5561
  return regeneratorRuntime.wrap(function _callee6$(_context6) {
5496
5562
  while (1) {
5497
5563
  switch (_context6.prev = _context6.next) {
5498
5564
  case 0:
5499
- s.goodsListState.endowCode.endowcodeGoodIndex.forEach(function (e) {
5500
- var good = s.goodsListState.goodsMap.get(e);
5565
+ endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(function (e) {
5566
+ return s.goodsListState.goodsMap.get(e);
5567
+ }); // 赋码
5568
+
5569
+ endowCodeGood.forEach(function (good) {
5501
5570
  if (!good) return; // const name = getItemName(good.itemName, values.shorthand);
5502
5571
 
5503
5572
  good.itemName = getItemName$1(good.itemName, values.shorthand); // `*${values.shorthand}*${name}`;
@@ -5522,11 +5591,41 @@ var DrawerBody$3 = function DrawerBody(props) {
5522
5591
  }
5523
5592
 
5524
5593
  good.taxAmount = mathjs.chain(mathjs.bignumber(good.lineAmountIncludeTax)).subtract(mathjs.bignumber(good.lineAmountExcludeTax)).done().toNumber();
5525
- });
5594
+ }); //截取名称
5595
+
5596
+ if (!endowCodeGood.some(function (e) {
5597
+ return bytesLnegth((e === null || e === void 0 ? void 0 : e.itemName) || '') > 100;
5598
+ })) {
5599
+ _context6.next = 5;
5600
+ break;
5601
+ }
5602
+
5603
+ _context6.next = 5;
5604
+ return function () {
5605
+ return new Promise(function (resolve) {
5606
+ confirm({
5607
+ title: '温馨提示',
5608
+ content: '商品名称长度过长,是否截取名称',
5609
+ onOk: function onOk() {
5610
+ endowCodeGood.forEach(function (e) {
5611
+ if (e && e.itemName) {
5612
+ e.itemName = cutStr(e.itemName, 99);
5613
+ }
5614
+ });
5615
+ resolve();
5616
+ },
5617
+ onCancel: function onCancel() {
5618
+ resolve();
5619
+ }
5620
+ });
5621
+ });
5622
+ }();
5623
+
5624
+ case 5:
5526
5625
  s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
5527
5626
  s.goodsListState.endowCode.endowcodeGoodIndex = [];
5528
5627
 
5529
- case 3:
5628
+ case 7:
5530
5629
  case "end":
5531
5630
  return _context6.stop();
5532
5631
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kts-component-invoice-operate",
3
- "version": "1.0.95",
3
+ "version": "1.0.99",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -0,0 +1,18 @@
1
+
2
+
3
+ const keys: { [key: string]: any } = {}
4
+
5
+ /**
6
+ * 有冷却时间的函数
7
+ * @param fn 方法
8
+ * @param key 方法key
9
+ * @param delayed 冷却时间
10
+ */
11
+ export default (key: string = 'default', delayed: number = 200, fn: Function) => {
12
+ if (keys[key]) {
13
+ return;
14
+ } else {
15
+ fn();
16
+ keys[key] = setTimeout(() => { delete keys[key] }, delayed);
17
+ }
18
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 判断一个字符串得字节长度
3
+ * @param str
4
+ * @returns
5
+ */
6
+ export function bytesLnegth(str: string) {
7
+ var count = str.length;
8
+ for (var i = 0; i < str.length; i++) {
9
+ if (str.charCodeAt(i) > 255) {
10
+ count++;
11
+ }
12
+ }
13
+ return count;
14
+ }
15
+
16
+ /*
17
+ * param str 要截取的字符串
18
+ * param L 要截取的字节长度,注意是字节不是字符,一个汉字两个字节
19
+ * return 截取后的字符串
20
+ */
21
+ export function cutStr(str: string, L: number) {
22
+ var result = '',
23
+ strlen = str.length, // 字符串长度
24
+ chrlen = str.replace(/[^\x00-\xff]/g, '**').length; // 字节长度
25
+
26
+ if (chrlen <= L) { return str; }
27
+
28
+ for (var i = 0, j = 0; i < strlen; i++) {
29
+ var chr = str.charAt(i);
30
+ if (/[\x00-\xff]/.test(chr)) {
31
+ j++; // ascii码为0-255,一个字符就是一个字节的长度
32
+ } else {
33
+ j += 2; // ascii码为0-255以外,一个字符就是两个字节的长度
34
+ }
35
+ if (j <= L) { // 当加上当前字符以后,如果总字节长度小于等于L,则将当前字符真实的+在result后
36
+ result += chr;
37
+ } else { // 反之则说明result已经是不拆分字符的情况下最接近L的值了,直接返回
38
+ return result;
39
+ }
40
+ }
41
+ }
@@ -1,6 +1,12 @@
1
1
  import React from 'react';
2
- import { Button, Drawer, Select } from 'kts-components-antd-x3';
2
+ import Invoice from '../../';
3
+ import { Button, Drawer, Select, Modal } from 'kts-components-antd-x3';
3
4
  import { chain, bignumber } from 'mathjs';
5
+ import { Input, NumberPicker } from '@formily/antd-components';
6
+ import { format15 } from '../GoodsList/hook/useColumns/autoFillFn';
7
+ import { LineAttributeType } from '../../InvoiceController';
8
+ import IGood from '../../InvoiceController/InvoiceControllerState/GoodsListState/IGood';
9
+ import { bytesLnegth, cutStr } from '../../tools/strringFn';
4
10
  import {
5
11
  SchemaForm,
6
12
  FormButtonGroup,
@@ -8,13 +14,10 @@ import {
8
14
  SchemaMarkupField as Field,
9
15
  FormEffectHooks,
10
16
  } from '@formily/antd';
11
- import { Input, NumberPicker } from '@formily/antd-components';
12
- import { format15 } from '../GoodsList/hook/useColumns/autoFillFn';
13
- import Invoice from '../../';
14
- import { LineAttributeType } from '../../InvoiceController';
15
- import IGood from '../../InvoiceController/InvoiceControllerState/GoodsListState/IGood';
16
17
  import './index.less';
17
18
 
19
+ const { confirm } = Modal;
20
+
18
21
  export default () => {
19
22
  const controller = Invoice.useInvoiceController();
20
23
 
@@ -153,10 +156,12 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
153
156
 
154
157
  // 确定
155
158
  const onSubmit = React.useCallback(values => {
156
- controller.pipeline(async (s) => {
157
- s.goodsListState.endowCode.endowcodeGoodIndex.forEach(e => {
159
+ controller.pipeline(async s => {
158
160
 
159
- const good = s.goodsListState.goodsMap.get(e);
161
+ const endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(e => s.goodsListState.goodsMap.get(e));
162
+
163
+ // 赋码
164
+ endowCodeGood.forEach(good => {
160
165
  if (!good) return;
161
166
 
162
167
  // const name = getItemName(good.itemName, values.shorthand);
@@ -186,12 +191,29 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
186
191
  good.taxAmount = chain(bignumber(good.lineAmountIncludeTax)).subtract(bignumber(good.lineAmountExcludeTax)).done().toNumber();
187
192
  });
188
193
 
194
+ //截取名称
195
+ if (endowCodeGood.some(e => bytesLnegth(e?.itemName || '') > 100)) {
196
+ await (() => new Promise<void>(resolve => {
197
+ confirm({
198
+ title: '温馨提示',
199
+ content: '商品名称长度过长,是否截取名称',
200
+ onOk() {
201
+ endowCodeGood.forEach(e => {
202
+ if (e && e.itemName) { e.itemName = cutStr(e.itemName, 99) }
203
+ })
204
+ resolve()
205
+ },
206
+ onCancel() {
207
+ resolve()
208
+ },
209
+ });
210
+ }))()
211
+ }
212
+
189
213
  s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
190
214
  s.goodsListState.endowCode.endowcodeGoodIndex = [];
191
215
  })();
192
- },
193
- [controller],
194
- );
216
+ }, [controller]);
195
217
 
196
218
  const effects = React.useCallback(() => {
197
219
  // 税率变化
@@ -251,7 +273,7 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
251
273
  title="免税类型"
252
274
  default={defaultValue?.taxFreeType}
253
275
  enum={taxFreeTypeList}
254
-
276
+
255
277
  x-rules={[{ message: '请选择免税类型', required: true }]}
256
278
  />
257
279
  }
@@ -1,3 +1,4 @@
1
+
1
2
  import React from 'react';
2
3
  import { Form } from 'kts-components-antd-x3';
3
4
  import { decorator } from 'grey-react-box';
@@ -58,9 +59,7 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
58
59
  /** 点击组件外部 保存正在编辑的货物 */
59
60
  React.useEffect(() => {
60
61
  const click = () => {
61
- setTimeout(() => {
62
- controller.saveEditGood();
63
- });
62
+ setTimeout(controller.saveEditGood);
64
63
  };
65
64
  window.addEventListener('click', click);
66
65
  return () => {
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import Invoice from '../../../../';
3
3
  import { Button, message } from 'kts-components-antd-x3';
4
+ import coolingFn from '../../../../tools/coolingFn'
4
5
  // import { LineAttributeType } from '../../../../InvoiceController';
5
6
 
6
7
  export default () => {
@@ -18,19 +19,13 @@ export default () => {
18
19
 
19
20
  // 不能给正在编辑的货物赋码
20
21
  if (s.goodsListState.editGood && s.goodsListState.selectedGoodIndex.indexOf(s.goodsListState.editGood.$index) >= 0) {
21
- message.error({
22
- content: '不能给正在编辑的货物赋码',
23
- key: '不能给正在编辑的货物赋码',
24
- });
22
+ coolingFn('不能给正在编辑的货物赋码', 3000, () => { message.error('不能给正在编辑的货物赋码') });
25
23
  return;
26
24
  }
27
25
 
28
26
  // 税率不一样不能批量赋码
29
27
  if (s.goodsListState.selectedGoodIndex.map(e => s.goodsListState.goodsMap.get(e)).some((e, _, arr) => e?.taxRate !== arr[0]?.taxRate)) {
30
- message.error({
31
- content: '商品税率不一致不能操作批量赋码',
32
- key: '商品税率不一致不能操作批量赋码',
33
- });
28
+ coolingFn('商品税率不一致不能操作批量赋码', 3000, () => { message.error('商品税率不一致不能操作批量赋码') });
34
29
  return;
35
30
  }
36
31
 
@@ -21,7 +21,7 @@ export default () => {
21
21
  <Drawer
22
22
  title="购方列表"
23
23
  placement="right"
24
- closable={false}
24
+ // closable={false}
25
25
  destroyOnClose={true}
26
26
  width={983}
27
27
  onClose={onClose}
@@ -20,6 +20,7 @@ export default () => {
20
20
  const topExpand = controller.useMemo(s => s.goodsListState.importGoods.topExpand, []);
21
21
 
22
22
  const onClose = React.useCallback(() => {
23
+ console.log('===> 关闭抽屉');
23
24
  controller.pipeline(async s => { s.goodsListState.importGoods.isVisibleDrawer = false })();
24
25
  }, [controller]);
25
26
 
@@ -27,12 +28,11 @@ export default () => {
27
28
  <Drawer
28
29
  title="商品列表"
29
30
  placement="right"
30
- closable={false}
31
+ // closable={false}
31
32
  destroyOnClose={true}
32
33
  width={983}
33
34
  onClose={onClose}
34
35
  visible={visible}
35
- getContainer={() => window.document.querySelector('.kts-invoice-operate-goods-list-able') as any}
36
36
  >
37
37
  {topExpand &&
38
38
  <div style={{ marginBottom: 10 }} >
@@ -52,7 +52,7 @@ const DrawerBody = () => {
52
52
 
53
53
  const pagination = controller.useMemo(s => s.goodsListState.importGoods.pagination, []);
54
54
 
55
- const [editGood] = React.useState(controller.state.goodsListState.editGood);
55
+ // const [editGood] = React.useState(controller.state.goodsListState.editGood);
56
56
 
57
57
  React.useEffect(() => {
58
58
  controller.getGoodsList &&
@@ -66,8 +66,8 @@ const DrawerBody = () => {
66
66
  columns={columns}
67
67
  dataSource={dataSource}
68
68
  pagination={pagination}
69
- onChange={(pagination) => { controller.getGoodsList && controller.getGoodsList({ pagination }) }}
70
- onRow={(record) => {
69
+ onChange={pagination => { controller.getGoodsList && controller.getGoodsList({ pagination }) }}
70
+ onRow={record => {
71
71
  return {
72
72
  onClick: () => {
73
73
  controller.pipeline(