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/api/member/auth.js");
  16. require("../../sheep/api/member/social.js");
  17. require("../../sheep/api/member/user.js");
  18. require("../../sheep/platform/provider/apple/index.js");
  19. require("../../sheep/platform/share.js");
  20. require("../../sheep/router/index.js");
  21. require("../../sheep/hooks/useModal.js");
  22. require("../../sheep/helper/index.js");
  23. require("../../sheep/helper/test.js");
  24. require("../../sheep/helper/digit.js");
  25. require("../../sheep/api/member/signin.js");
  26. require("../../sheep/helper/throttle.js");
  27. require("../../sheep/platform/pay.js");
  28. require("../../sheep/api/pay/order.js");
  29. require("../../sheep/store/user.js");
  30. require("../../sheep/store/cart.js");
  31. require("../../sheep/api/trade/cart.js");
  32. require("../../sheep/api/pay/wallet.js");
  33. require("../../sheep/api/promotion/coupon.js");
  34. require("../../sheep/store/sys.js");
  35. require("../../sheep/store/modal.js");
  36. require("../../sheep/config/index.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. console.log(state.orderInfo.shopRespVOMap);
  87. const shops = {};
  88. try {
  89. Object.keys(state.orderInfo.shopRespVOMap).forEach((shopId) => {
  90. const shopName = state.orderInfo.shopNameMap[shopId];
  91. if (shopName) {
  92. shops[shopName] = state.orderInfo.shopRespVOMap[shopId];
  93. shops[shopName].remark = "";
  94. shops[shopName].shopId = shopId;
  95. }
  96. });
  97. } catch (e) {
  98. }
  99. return shops;
  100. });
  101. const totalItemCount = common_vendor.computed(() => {
  102. let totalCount = 0;
  103. Object.values(shopsByNames.value).forEach((shop) => {
  104. shop.items.forEach((item) => {
  105. totalCount += item.count;
  106. });
  107. });
  108. return totalCount;
  109. });
  110. function onSelectAddress() {
  111. common_vendor.index.$once("SELECT_ADDRESS", (e) => {
  112. changeConsignee(e.addressInfo);
  113. });
  114. console.log(state.orderPayload.spuType);
  115. if (state.orderPayload.spuType) {
  116. sheep_index.sheep.$router.go("/pages/user/address/list");
  117. } else {
  118. sheep_index.sheep.$router.go("/pages/user/dummyAddress/list");
  119. }
  120. }
  121. async function changeConsignee(addressInfo = {}) {
  122. if (!common_vendor.lodashExports.isEmpty(addressInfo)) {
  123. state.addressInfo = addressInfo;
  124. }
  125. await getOrderInfo();
  126. }
  127. async function onInputPoints(points) {
  128. if (points == void 0) {
  129. points = 0;
  130. }
  131. const payprice = state.currentTotalPrice;
  132. state.orderInfo.price.payPrice = (payprice - points) * 100;
  133. state.usedPoint = points;
  134. state.showPoints = false;
  135. }
  136. function onConfirm() {
  137. if (!state.addressInfo.id) {
  138. sheep_index.sheep.$helper.toast("请选择收货地址");
  139. return;
  140. }
  141. if (state.usedPoint > state.currentMemberPoints) {
  142. sheep_index.sheep.$helper.toast("可用积分不足");
  143. return;
  144. }
  145. submitOrder();
  146. }
  147. function customRound(number, decimals) {
  148. let factor = Math.pow(10, decimals);
  149. let tempNumber = Math.floor(number * factor) / factor;
  150. return tempNumber.toFixed(decimals);
  151. }
  152. async function submitOrder() {
  153. const shops = shopsByNames.value;
  154. const shopRemarks = {};
  155. Object.keys(shops).forEach((shopName) => {
  156. const shop = shops[shopName];
  157. shopRemarks[shop.shopId] = shop.remark;
  158. });
  159. const usedPoint = state.orderPayload.highPrecision ? customRound(state.orderInfo.price.virtualPayPrice / 100, 2) : state.usedPoint;
  160. const {
  161. code,
  162. data
  163. } = await sheep_api_trade_order.OrderApi.createOrder({
  164. items: state.orderPayload.items,
  165. couponId: state.orderPayload.couponId,
  166. addressId: state.addressInfo.id,
  167. deliveryType: state.orderPayload.spuType == 1 ? 1 : 3,
  168. // TODO 非繁人:需要支持【门店自提】
  169. pointStatus: false,
  170. // TODO 非繁人:需要支持【积分选择】
  171. combinationActivityId: state.orderPayload.combinationActivityId,
  172. combinationHeadId: state.orderPayload.combinationHeadId,
  173. seckillActivityId: state.orderPayload.seckillActivityId,
  174. payIntegral: usedPoint,
  175. // payIntegral: 0.95,
  176. shopRemarks
  177. });
  178. if (code !== 0) {
  179. return;
  180. }
  181. if (state.orderPayload.items[0].cartId > 0) {
  182. sheep_index.sheep.$store("cart").getList();
  183. }
  184. sheep_index.sheep.$router.redirect("/pages/pay/index", {
  185. id: data.payOrderId
  186. });
  187. }
  188. async function getOrderInfo() {
  189. const shops = shopsByNames.value;
  190. let shopRemarks = {};
  191. if (Object.keys(shops).length !== 0) {
  192. Object.keys(shops).forEach((shopName) => {
  193. const shop = shops[shopName];
  194. shopRemarks[shopName] = shop.remark;
  195. });
  196. }
  197. const {
  198. data,
  199. code
  200. } = await sheep_api_trade_order.OrderApi.settlementOrder({
  201. items: state.orderPayload.items,
  202. couponId: state.orderPayload.couponId,
  203. addressId: state.addressInfo.id,
  204. deliveryType: state.orderPayload.spuType == 1 ? 1 : 3,
  205. // TODO 非繁人:需要支持【门店自提】
  206. pointStatus: false,
  207. // TODO 非繁人:需要支持【积分选择】
  208. combinationActivityId: state.orderPayload.combinationActivityId,
  209. combinationHeadId: state.orderPayload.combinationHeadId,
  210. seckillActivityId: state.orderPayload.seckillActivityId,
  211. usedPoint: state.usedPoint,
  212. addressType: state.orderPayload.spuType == 1 ? 1 : 2
  213. //如果是虚拟产品
  214. });
  215. if (code !== 0) {
  216. return;
  217. }
  218. state.orderInfo = data;
  219. if (Object.keys(shopRemarks).length !== 0) {
  220. Object.keys(shopRemarks).forEach((shopName) => {
  221. shopsByNames.value[shopName].remark = shopRemarks[shopName];
  222. });
  223. }
  224. if (state.orderInfo.address) {
  225. state.addressInfo = state.orderInfo.address;
  226. }
  227. state.currentMemberPoints = sheep_hooks_useGoods.points2point(state.orderInfo.currentQuota);
  228. state.currentTotalPrice = sheep_hooks_useGoods.fen2yuan(state.orderInfo.price.payPrice);
  229. state.currentDeliveryPrice = sheep_hooks_useGoods.fen2yuan(state.orderInfo.price.deliveryPrice);
  230. if (state.orderPayload.spuPayType == 2) {
  231. state.usedPoint = state.currentTotalPrice - 0.01;
  232. console.log(state.spuType);
  233. }
  234. }
  235. common_vendor.onLoad(async (options) => {
  236. if (!options.data) {
  237. sheep_index.sheep.$helper.toast("参数不正确,请检查!");
  238. return;
  239. }
  240. state.orderPayload = JSON.parse(options.data);
  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);