@pisell/pisellos 0.0.404 → 0.0.406

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.
@@ -315,7 +315,8 @@ export var formatBundle = function formatBundle(bundle) {
315
315
  options: formatOptions(item === null || item === void 0 ? void 0 : item.option),
316
316
  _bundle_product_id: item._bundle_product_id,
317
317
  discount_list: item.discount_list,
318
- originBundleItem: item.originBundleItem || item
318
+ originBundleItem: item.originBundleItem || item,
319
+ is_charge_tax: item === null || item === void 0 ? void 0 : item.is_charge_tax
319
320
  };
320
321
  });
321
322
  };
@@ -15,9 +15,10 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
15
15
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
17
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ import Decimal from 'decimal.js';
18
19
  import { BaseModule } from "../BaseModule";
19
20
  import { ScheduleModule } from "../Schedule";
20
- import { calculatePriceDetails, getSurcharge, getTax } from "./utils";
21
+ import { calculatePriceDetails, getSurcharge, getSurchargeAmount, getTax } from "./utils";
21
22
  export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
22
23
  _inherits(SummaryModule, _BaseModule);
23
24
  var _super = _createSuper(SummaryModule);
@@ -186,8 +187,8 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
186
187
  }, {
187
188
  key: "getSurchargeforUtils",
188
189
  value: function getSurchargeforUtils(items) {
189
- var surchargeList = this.store.surchargeList;
190
- var surchargeAmount = getSurcharge({
190
+ // const surchargeList = this.store.surchargeList;
191
+ var surchargeList = getSurcharge({
191
192
  service: items,
192
193
  addons: [],
193
194
  bookingDetail: null,
@@ -195,12 +196,18 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
195
196
  }, {
196
197
  isEdit: false,
197
198
  isInScheduleByDate: ScheduleModule.isInScheduleByDate,
198
- surcharge_list: surchargeList,
199
+ surcharge_list: this.store.surchargeList,
199
200
  scheduleById: {}
200
201
  });
202
+ var surchargeAmount = new Decimal(getSurchargeAmount({
203
+ bookingDetail: null,
204
+ bookingId: undefined
205
+ }, surchargeList, {
206
+ isEdit: false
207
+ }));
201
208
  return {
202
209
  surchargeList: surchargeList,
203
- surchargeAmount: surchargeAmount
210
+ surchargeAmount: surchargeAmount.toFixed(2)
204
211
  };
205
212
  }
206
213
  }]);
@@ -55,10 +55,10 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
55
55
  }),
56
56
  tax = _getTax.tax,
57
57
  originTax = _getTax.originTax;
58
- var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal.plus(surchargeAmount) : subtotal.plus(totalTaxFee).plus(surchargeAmount);
58
+ var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
59
59
 
60
60
  // 计算总价 不包含折扣卡商品券折扣信息价格
61
- var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
61
+ var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal.plus(surchargeAmount) : subOriginTotal.plus(totalTaxFee).plus(surchargeAmount);
62
62
 
63
63
  // 计算定金
64
64
  var deposit = calculateDeposit(items);
@@ -328,6 +328,7 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
328
328
  var bundlePreciseTax = new Decimal(0);
329
329
  var bundleRoundedOriginTax = new Decimal(0);
330
330
  var bundleRoundedTax = new Decimal(0);
331
+ debugger;
331
332
  if (Array.isArray(item === null || item === void 0 ? void 0 : item.bundle)) {
332
333
  var _iterator3 = _createForOfIteratorHelper(item === null || item === void 0 ? void 0 : item.bundle),
333
334
  _step3;
@@ -847,6 +848,14 @@ export var getSurcharge = function getSurcharge(_ref10, options) {
847
848
  }
848
849
  return [];
849
850
  }
851
+
852
+ // 用于“计算总价”的场景:每次调用都应重新计算(避免重复调用导致 surcharge_fee 累加)
853
+ // 注意:同一次调用内仍会在多条 surcharge 配置之间累加
854
+ resetItemsSurchargeSideEffects({
855
+ service: service,
856
+ addons: addons
857
+ });
858
+
850
859
  // 无附加费规则
851
860
  if (!Array.isArray(surcharge_list) || !(surcharge_list !== null && surcharge_list !== void 0 && surcharge_list.length)) return [];
852
861
 
@@ -1132,4 +1141,66 @@ export var getSurcharge = function getSurcharge(_ref10, options) {
1132
1141
  });
1133
1142
  }
1134
1143
  return surchargeWithAmount;
1135
- };
1144
+ };
1145
+ function resetItemsSurchargeSideEffects(_ref12) {
1146
+ var service = _ref12.service,
1147
+ addons = _ref12.addons;
1148
+ var resetItem = function resetItem(item) {
1149
+ if (!item) return;
1150
+ item.surcharge_fee = 0;
1151
+ item.surcharge_rounding_remainder = 0;
1152
+ item.relation_surcharge_ids = [];
1153
+ };
1154
+ if (Array.isArray(service)) {
1155
+ var _iterator10 = _createForOfIteratorHelper(service),
1156
+ _step10;
1157
+ try {
1158
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1159
+ var item = _step10.value;
1160
+ resetItem(item);
1161
+ var _iterator11 = _createForOfIteratorHelper((item === null || item === void 0 ? void 0 : item.bundle) || []),
1162
+ _step11;
1163
+ try {
1164
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1165
+ var bundleItem = _step11.value;
1166
+ resetItem(bundleItem);
1167
+ }
1168
+ } catch (err) {
1169
+ _iterator11.e(err);
1170
+ } finally {
1171
+ _iterator11.f();
1172
+ }
1173
+ var _iterator12 = _createForOfIteratorHelper((item === null || item === void 0 ? void 0 : item.relation_details) || []),
1174
+ _step12;
1175
+ try {
1176
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1177
+ var relationDetail = _step12.value;
1178
+ resetItem(relationDetail);
1179
+ }
1180
+ } catch (err) {
1181
+ _iterator12.e(err);
1182
+ } finally {
1183
+ _iterator12.f();
1184
+ }
1185
+ }
1186
+ } catch (err) {
1187
+ _iterator10.e(err);
1188
+ } finally {
1189
+ _iterator10.f();
1190
+ }
1191
+ }
1192
+ if (Array.isArray(addons === null || addons === void 0 ? void 0 : addons.value)) {
1193
+ var _iterator13 = _createForOfIteratorHelper(addons.value),
1194
+ _step13;
1195
+ try {
1196
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1197
+ var _item3 = _step13.value;
1198
+ resetItem(_item3);
1199
+ }
1200
+ } catch (err) {
1201
+ _iterator13.e(err);
1202
+ } finally {
1203
+ _iterator13.f();
1204
+ }
1205
+ }
1206
+ }
@@ -280,7 +280,8 @@ var formatBundle = (bundle) => {
280
280
  options: formatOptions(item == null ? void 0 : item.option),
281
281
  _bundle_product_id: item._bundle_product_id,
282
282
  discount_list: item.discount_list,
283
- originBundleItem: item.originBundleItem || item
283
+ originBundleItem: item.originBundleItem || item,
284
+ is_charge_tax: item == null ? void 0 : item.is_charge_tax
284
285
  };
285
286
  });
286
287
  };
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Summary/index.ts
@@ -22,6 +32,7 @@ __export(Summary_exports, {
22
32
  SummaryModule: () => SummaryModule
23
33
  });
24
34
  module.exports = __toCommonJS(Summary_exports);
35
+ var import_decimal = __toESM(require("decimal.js"));
25
36
  var import_BaseModule = require("../BaseModule");
26
37
  var import_Schedule = require("../Schedule");
27
38
  var import_utils = require("./utils");
@@ -100,11 +111,11 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
100
111
  });
101
112
  }
102
113
  getSurchargeforUtils(items) {
103
- const surchargeList = this.store.surchargeList;
104
- const surchargeAmount = (0, import_utils.getSurcharge)({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate: import_Schedule.ScheduleModule.isInScheduleByDate, surcharge_list: surchargeList, scheduleById: {} });
114
+ const surchargeList = (0, import_utils.getSurcharge)({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate: import_Schedule.ScheduleModule.isInScheduleByDate, surcharge_list: this.store.surchargeList, scheduleById: {} });
115
+ const surchargeAmount = new import_decimal.default((0, import_utils.getSurchargeAmount)({ bookingDetail: null, bookingId: void 0 }, surchargeList, { isEdit: false }));
105
116
  return {
106
117
  surchargeList,
107
- surchargeAmount
118
+ surchargeAmount: surchargeAmount.toFixed(2)
108
119
  };
109
120
  }
110
121
  };
@@ -56,8 +56,8 @@ var calculatePriceDetails = (shopInfo, items, isInScheduleByDate, surchargeList)
56
56
  tax_rate: shopInfo == null ? void 0 : shopInfo.tax_rate,
57
57
  is_price_include_tax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax
58
58
  });
59
- const total = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subtotal.plus(surchargeAmount) : subtotal.plus(totalTaxFee).plus(surchargeAmount);
60
- const originTotal = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
59
+ const total = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
60
+ const originTotal = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subOriginTotal.plus(surchargeAmount) : subOriginTotal.plus(totalTaxFee).plus(surchargeAmount);
61
61
  const deposit = calculateDeposit(items);
62
62
  return {
63
63
  subtotal: subtotal.toFixed(2),
@@ -202,6 +202,7 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
202
202
  let bundlePreciseTax = new import_decimal.default(0);
203
203
  let bundleRoundedOriginTax = new import_decimal.default(0);
204
204
  let bundleRoundedTax = new import_decimal.default(0);
205
+ debugger;
205
206
  if (Array.isArray(item == null ? void 0 : item.bundle)) {
206
207
  for (let bundleItem of item == null ? void 0 : item.bundle) {
207
208
  if (getBundleItemIsOriginalPrice(bundleItem)) {
@@ -501,6 +502,7 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
501
502
  }
502
503
  return [];
503
504
  }
505
+ resetItemsSurchargeSideEffects({ service, addons });
504
506
  if (!Array.isArray(surcharge_list) || !(surcharge_list == null ? void 0 : surcharge_list.length))
505
507
  return [];
506
508
  const surchargeWithAmount = [];
@@ -708,6 +710,28 @@ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
708
710
  }
709
711
  return surchargeWithAmount;
710
712
  };
713
+ function resetItemsSurchargeSideEffects({ service, addons }) {
714
+ const resetItem = (item) => {
715
+ if (!item)
716
+ return;
717
+ item.surcharge_fee = 0;
718
+ item.surcharge_rounding_remainder = 0;
719
+ item.relation_surcharge_ids = [];
720
+ };
721
+ if (Array.isArray(service)) {
722
+ for (let item of service) {
723
+ resetItem(item);
724
+ for (let bundleItem of (item == null ? void 0 : item.bundle) || [])
725
+ resetItem(bundleItem);
726
+ for (let relationDetail of (item == null ? void 0 : item.relation_details) || [])
727
+ resetItem(relationDetail);
728
+ }
729
+ }
730
+ if (Array.isArray(addons == null ? void 0 : addons.value)) {
731
+ for (let item of addons.value)
732
+ resetItem(item);
733
+ }
734
+ }
711
735
  // Annotate the CommonJS export names for ESM import in node:
712
736
  0 && (module.exports = {
713
737
  calculateDeposit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.404",
4
+ "version": "0.0.406",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",