confirm.js 15 KB

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