confirm.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const sheep_index = require("../../sheep/index.js");
  5. const sheep_api_trade_order = require("../../sheep/api/trade/order.js");
  6. require("../../sheep/request/index.js");
  7. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  8. require("../../sheep/api/index.js");
  9. require("../../sheep/api/distri/score.js");
  10. require("../../sheep/api/distri/share.js");
  11. require("../../sheep/api/distri/team.js");
  12. require("../../sheep/api/infra/file.js");
  13. require("../../sheep/config/index.js");
  14. require("../../sheep/api/member/address.js");
  15. require("../../sheep/api/member/auth.js");
  16. require("../../sheep/api/member/point.js");
  17. require("../../sheep/api/member/signin.js");
  18. require("../../sheep/api/member/social.js");
  19. require("../../sheep/api/member/user.js");
  20. require("../../sheep/api/migration/app.js");
  21. require("../../sheep/api/migration/chat.js");
  22. require("../../sheep/api/migration/index.js");
  23. require("../../sheep/api/migration/third.js");
  24. require("../../sheep/api/pay/channel.js");
  25. require("../../sheep/api/pay/order.js");
  26. require("../../sheep/api/pay/wallet.js");
  27. require("../../sheep/api/product/category.js");
  28. require("../../sheep/api/product/comment.js");
  29. require("../../sheep/api/product/favorite.js");
  30. require("../../sheep/api/product/history.js");
  31. require("../../sheep/api/product/spu.js");
  32. require("../../sheep/api/promotion/activity.js");
  33. require("../../sheep/api/promotion/article.js");
  34. require("../../sheep/api/promotion/bargain.js");
  35. require("../../sheep/api/promotion/combination.js");
  36. require("../../sheep/api/promotion/coupon.js");
  37. require("../../sheep/api/promotion/diy.js");
  38. require("../../sheep/api/promotion/rewardActivity.js");
  39. require("../../sheep/api/promotion/seckill.js");
  40. require("../../sheep/api/system/area.js");
  41. require("../../sheep/api/system/voice.js");
  42. require("../../sheep/api/trade/afterSale.js");
  43. require("../../sheep/api/trade/brokerage.js");
  44. require("../../sheep/api/trade/cart.js");
  45. require("../../sheep/api/trade/config.js");
  46. require("../../sheep/api/trade/delivery.js");
  47. require("../../sheep/url/index.js");
  48. require("../../sheep/store/index.js");
  49. require("../../sheep/store/app.js");
  50. require("../../sheep/platform/index.js");
  51. require("../../sheep/platform/provider/wechat/index.js");
  52. require("../../sheep/platform/provider/wechat/miniProgram.js");
  53. require("../../sheep/platform/provider/apple/index.js");
  54. require("../../sheep/platform/share.js");
  55. require("../../sheep/router/index.js");
  56. require("../../sheep/hooks/useModal.js");
  57. require("../../sheep/helper/index.js");
  58. require("../../sheep/helper/test.js");
  59. require("../../sheep/helper/digit.js");
  60. require("../../sheep/helper/throttle.js");
  61. require("../../sheep/platform/pay.js");
  62. require("../../sheep/store/user.js");
  63. require("../../sheep/store/cart.js");
  64. require("../../sheep/store/sys.js");
  65. require("../../sheep/store/modal.js");
  66. require("../../sheep/config/zIndex.js");
  67. require("../../sheep/util/index.js");
  68. if (!Array) {
  69. const _easycom_s_address_item2 = common_vendor.resolveComponent("s-address-item");
  70. const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
  71. const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  72. const _easycom_s_points_pop2 = common_vendor.resolveComponent("s-points-pop");
  73. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  74. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  75. (_easycom_s_address_item2 + _easycom_s_goods_item2 + _easycom_uni_easyinput2 + _easycom_s_points_pop2 + _easycom_su_fixed2 + _easycom_s_layout2)();
  76. }
  77. const _easycom_s_address_item = () => "../../sheep/components/s-address-item/s-address-item.js";
  78. const _easycom_s_goods_item = () => "../../sheep/components/s-goods-item/s-goods-item.js";
  79. const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
  80. const _easycom_s_points_pop = () => "../../sheep/components/s-points-pop/s-points-pop.js";
  81. const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
  82. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  83. if (!Math) {
  84. (_easycom_s_address_item + _easycom_s_goods_item + _easycom_uni_easyinput + _easycom_s_points_pop + _easycom_su_fixed + _easycom_s_layout)();
  85. }
  86. const _sfc_main = {
  87. __name: "confirm",
  88. setup(__props) {
  89. const state = common_vendor.reactive({
  90. orderPayload: {},
  91. orderInfo: {
  92. items: [],
  93. // 商品项列表
  94. price: {}
  95. // 价格信息
  96. },
  97. addressInfo: {},
  98. // 选择的收货地址
  99. showPoints: false,
  100. // 是否积分抵扣
  101. couponInfo: [],
  102. // 优惠劵列表
  103. showDiscount: false,
  104. // 是否展示营销活动
  105. currentMemberPoints: 0,
  106. //用户当前可用积分
  107. usedPoint: 0,
  108. //用户使用的积分
  109. currentTotalPrice: 0,
  110. //当前的整个订单的总价格
  111. currentDeliveryPrice: 0
  112. // 当前订单的总运费
  113. });
  114. const shopsByNames = common_vendor.computed(() => {
  115. const shops = {};
  116. try {
  117. Object.keys(state.orderInfo.shopRespVOMap).forEach((shopId) => {
  118. const shopName = state.orderInfo.shopNameMap[shopId];
  119. if (shopName) {
  120. shops[shopName] = state.orderInfo.shopRespVOMap[shopId];
  121. shops[shopName].remark = "";
  122. shops[shopName].shopId = shopId;
  123. }
  124. });
  125. } catch (e) {
  126. }
  127. return shops;
  128. });
  129. const totalItemCount = common_vendor.computed(() => {
  130. let totalCount = 0;
  131. Object.values(shopsByNames.value).forEach((shop) => {
  132. shop.items.forEach((item) => {
  133. totalCount += item.count;
  134. });
  135. });
  136. return totalCount;
  137. });
  138. function onSelectAddress() {
  139. common_vendor.index.$once("SELECT_ADDRESS", (e) => {
  140. changeConsignee(e.addressInfo);
  141. });
  142. console.log(state.orderPayload.spuType);
  143. if (state.orderPayload.spuType) {
  144. sheep_index.sheep.$router.go("/pages/user/address/list");
  145. } else {
  146. sheep_index.sheep.$router.go("/pages/user/dummyAddress/list");
  147. }
  148. }
  149. async function changeConsignee(addressInfo = {}) {
  150. if (!common_vendor.lodashExports.isEmpty(addressInfo)) {
  151. state.addressInfo = addressInfo;
  152. }
  153. await getOrderInfo();
  154. }
  155. async function onInputPoints(points) {
  156. if (points == void 0) {
  157. points = 0;
  158. }
  159. const payprice = state.currentTotalPrice;
  160. state.orderInfo.price.payPrice = (payprice - points) * 100;
  161. state.usedPoint = points;
  162. state.showPoints = false;
  163. }
  164. function onConfirm() {
  165. if (!state.addressInfo.id) {
  166. sheep_index.sheep.$helper.toast("请选择收货地址");
  167. return;
  168. }
  169. if (state.usedPoint > state.currentMemberPoints) {
  170. sheep_index.sheep.$helper.toast("可用积分不足");
  171. return;
  172. }
  173. submitOrder();
  174. }
  175. function customRound(number, decimals) {
  176. let factor = Math.pow(10, decimals);
  177. let tempNumber = Math.floor(number * factor) / factor;
  178. return tempNumber.toFixed(decimals);
  179. }
  180. async function submitOrder() {
  181. const shops = shopsByNames.value;
  182. const shopRemarks = {};
  183. Object.keys(shops).forEach((shopName) => {
  184. const shop = shops[shopName];
  185. shopRemarks[shop.shopId] = shop.remark;
  186. });
  187. const usedPoint = state.orderPayload.highPrecision ? customRound(state.orderInfo.price.virtualPayPrice / 100, 2) : state.usedPoint;
  188. const {
  189. code,
  190. data
  191. } = await sheep_api_trade_order.OrderApi.createOrder({
  192. items: state.orderPayload.items,
  193. couponId: state.orderPayload.couponId,
  194. addressId: state.addressInfo.id,
  195. deliveryType: state.orderPayload.spuType == 1 ? 1 : 3,
  196. // TODO 非繁人:需要支持【门店自提】
  197. pointStatus: false,
  198. // TODO 非繁人:需要支持【积分选择】
  199. combinationActivityId: state.orderPayload.combinationActivityId,
  200. combinationHeadId: state.orderPayload.combinationHeadId,
  201. seckillActivityId: state.orderPayload.seckillActivityId,
  202. payIntegral: usedPoint,
  203. // payIntegral: 0.95,
  204. shopRemarks
  205. });
  206. if (code !== 0) {
  207. return;
  208. }
  209. if (state.orderPayload.items[0].cartId > 0) {
  210. sheep_index.sheep.$store("cart").getList();
  211. }
  212. sheep_index.sheep.$router.redirect("/pages/pay/index", {
  213. id: data.payOrderId
  214. });
  215. }
  216. async function getOrderInfo() {
  217. const shops = shopsByNames.value;
  218. let shopRemarks = {};
  219. if (Object.keys(shops).length !== 0) {
  220. Object.keys(shops).forEach((shopName) => {
  221. const shop = shops[shopName];
  222. shopRemarks[shopName] = shop.remark;
  223. });
  224. }
  225. const {
  226. data,
  227. code
  228. } = await sheep_api_trade_order.OrderApi.settlementOrder({
  229. items: state.orderPayload.items,
  230. couponId: state.orderPayload.couponId,
  231. addressId: state.addressInfo.id,
  232. deliveryType: state.orderPayload.spuType == 1 ? 1 : 3,
  233. // TODO 非繁人:需要支持【门店自提】
  234. pointStatus: false,
  235. // TODO 非繁人:需要支持【积分选择】
  236. combinationActivityId: state.orderPayload.combinationActivityId,
  237. combinationHeadId: state.orderPayload.combinationHeadId,
  238. seckillActivityId: state.orderPayload.seckillActivityId,
  239. usedPoint: state.usedPoint,
  240. addressType: state.orderPayload.spuType == 1 ? 1 : 2
  241. //如果是虚拟产品
  242. });
  243. if (code !== 0) {
  244. return;
  245. }
  246. state.orderInfo = data;
  247. if (Object.keys(shopRemarks).length !== 0) {
  248. Object.keys(shopRemarks).forEach((shopName) => {
  249. shopsByNames.value[shopName].remark = shopRemarks[shopName];
  250. });
  251. }
  252. if (state.orderInfo.address) {
  253. state.addressInfo = state.orderInfo.address;
  254. }
  255. state.currentMemberPoints = sheep_hooks_useGoods.points2point(state.orderInfo.currentQuota);
  256. state.currentTotalPrice = sheep_hooks_useGoods.fen2yuan(state.orderInfo.price.payPrice);
  257. state.currentDeliveryPrice = sheep_hooks_useGoods.fen2yuan(state.orderInfo.price.deliveryPrice);
  258. if (state.orderPayload.spuPayType == 2) {
  259. state.usedPoint = state.currentTotalPrice - 0.01;
  260. console.log(state.spuType);
  261. }
  262. }
  263. common_vendor.onLoad(async (options) => {
  264. if (!options.data) {
  265. sheep_index.sheep.$helper.toast("参数不正确,请检查!");
  266. return;
  267. }
  268. state.orderPayload = JSON.parse(options.data);
  269. console.log(state.orderPayload);
  270. await getOrderInfo();
  271. });
  272. return (_ctx, _cache) => {
  273. return common_vendor.e({
  274. a: common_vendor.p({
  275. item: state.addressInfo,
  276. spuType: state.orderPayload.spuType,
  277. hasBorderBottom: false
  278. }),
  279. b: common_vendor.o(onSelectAddress),
  280. c: common_vendor.f(shopsByNames.value, (items, name, i0) => {
  281. return common_vendor.e({
  282. a: common_vendor.t(name),
  283. b: common_vendor.f(items.items, (item, k1, i1) => {
  284. var _a;
  285. return {
  286. a: item == null ? void 0 : item.skuId,
  287. b: "324e7894-2-" + i0 + "-" + i1 + ",324e7894-0",
  288. c: common_vendor.p({
  289. img: item == null ? void 0 : item.picUrl,
  290. title: item == null ? void 0 : item.spuName,
  291. skuText: (_a = item == null ? void 0 : item.properties) == null ? void 0 : _a.map((property) => property.valueName).join(" "),
  292. price: item.highPrecisionPrice ? item == null ? void 0 : item.highPrecisionPrice : item == null ? void 0 : item.price,
  293. num: item == null ? void 0 : item.count,
  294. virtualPirce: item.highPrecisionPrice ? true : false
  295. })
  296. };
  297. }),
  298. c: common_vendor.t(items.price.deliveryPrice ? "¥" + common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(items.price.deliveryPrice) : "包邮"),
  299. d: "324e7894-3-" + i0 + ",324e7894-0",
  300. e: common_vendor.o(($event) => items.remark = $event, name),
  301. f: common_vendor.p({
  302. maxlength: "20",
  303. placeholder: "建议留言前先与商家沟通",
  304. inputBorder: false,
  305. clearable: false,
  306. modelValue: items.remark
  307. })
  308. }, state.orderPayload.spuType == 0 ? {
  309. g: common_vendor.t(totalItemCount.value)
  310. } : common_vendor.e({
  311. h: state.orderPayload.spuPayType == 2
  312. }, state.orderPayload.spuPayType == 2 ? {
  313. i: common_assets._imports_0
  314. } : {}, {
  315. j: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(items.price.payPrice))
  316. }), {
  317. k: name
  318. });
  319. }),
  320. d: state.orderPayload.spuType == 0,
  321. e: common_vendor.t(totalItemCount.value),
  322. f: state.orderPayload.spuPayType == 2
  323. }, state.orderPayload.spuPayType == 2 ? {
  324. g: common_assets._imports_0
  325. } : {}, {
  326. h: state.orderPayload.highPrecision
  327. }, state.orderPayload.highPrecision ? {
  328. i: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan6)(state.orderInfo.price.virtualTotalPrice))
  329. } : {
  330. j: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.totalPrice))
  331. }, {
  332. k: state.orderPayload.spuPayType == 2
  333. }, state.orderPayload.spuPayType == 2 ? {
  334. l: common_assets._imports_0
  335. } : {}, {
  336. m: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.deliveryPrice)),
  337. n: state.orderPayload.spuPayType != 2
  338. }, state.orderPayload.spuPayType != 2 ? {
  339. o: common_vendor.t(state.usedPoint > 0 ? " 可抵扣" + state.usedPoint + "元" : "不使用积分"),
  340. p: common_vendor.n(state.usedPoint > 0 ? "text-red" : "text-disabled"),
  341. q: common_vendor.o(($event) => state.showPoints = true)
  342. } : {}, {
  343. r: common_vendor.t(totalItemCount.value),
  344. s: state.orderPayload.spuPayType == 2
  345. }, state.orderPayload.spuPayType == 2 ? {
  346. t: common_assets._imports_0
  347. } : {}, {
  348. v: state.orderPayload.highPrecision
  349. }, state.orderPayload.highPrecision ? {
  350. w: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan6)(state.orderInfo.price.virtualTotalPrice))
  351. } : state.orderPayload.spuPayType == 2 ? {
  352. y: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice) - 0.01)
  353. } : {
  354. z: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice))
  355. }, {
  356. x: state.orderPayload.spuPayType == 2,
  357. A: common_vendor.o(onInputPoints),
  358. B: common_vendor.o(($event) => state.showPoints = false),
  359. C: common_vendor.o(($event) => state.couponInfo = $event),
  360. D: common_vendor.p({
  361. currentMemberPoints: state.currentMemberPoints,
  362. currentTotalPrice: state.currentTotalPrice,
  363. currentDeliveryPrice: state.currentDeliveryPrice,
  364. show: state.showPoints,
  365. modelValue: state.couponInfo
  366. }),
  367. E: state.orderPayload.highPrecision
  368. }, state.orderPayload.highPrecision ? common_vendor.e({
  369. F: state.orderPayload.spuPayType == 2
  370. }, state.orderPayload.spuPayType == 2 ? {
  371. G: common_assets._imports_0
  372. } : {}, {
  373. H: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan6)(state.orderInfo.price.virtualPayPrice) - 0.01)
  374. }) : state.orderPayload.spuPayType == 2 ? common_vendor.e({
  375. J: state.orderPayload.spuPayType == 2
  376. }, state.orderPayload.spuPayType == 2 ? {
  377. K: common_assets._imports_0
  378. } : {}, {
  379. L: common_vendor.t(state.usedPoint)
  380. }) : {
  381. M: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice))
  382. }, {
  383. I: state.orderPayload.spuPayType == 2,
  384. N: common_vendor.o(onConfirm),
  385. O: common_vendor.p({
  386. bottom: true,
  387. opacity: false,
  388. bg: "bg-white",
  389. placeholder: true,
  390. noFixed: false,
  391. index: 200
  392. }),
  393. P: common_vendor.p({
  394. title: "确认订单"
  395. })
  396. });
  397. };
  398. }
  399. };
  400. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-324e7894"], ["__file", "D:/zx/mall-front-app/pages/order/confirm.vue"]]);
  401. wx.createPage(MiniProgramPage);