confirm.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_api_trade_order = require("../../sheep/api/trade/order.js");
  5. const sheep_api_promotion_coupon = require("../../sheep/api/promotion/coupon.js");
  6. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  7. require("../../sheep/url/index.js");
  8. require("../../sheep/store/index.js");
  9. require("../../sheep/store/app.js");
  10. require("../../sheep/api/promotion/diy.js");
  11. require("../../sheep/request/index.js");
  12. require("../../sheep/config/index.js");
  13. require("../../sheep/platform/index.js");
  14. require("../../sheep/platform/provider/wechat/index.js");
  15. require("../../sheep/platform/provider/wechat/miniProgram.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/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/store/sys.js");
  34. require("../../sheep/store/modal.js");
  35. require("../../sheep/config/zIndex.js");
  36. require("../../sheep/util/index.js");
  37. if (!Array) {
  38. const _easycom_s_address_item2 = common_vendor.resolveComponent("s-address-item");
  39. const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
  40. const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  41. const _easycom_s_coupon_select2 = common_vendor.resolveComponent("s-coupon-select");
  42. const _easycom_s_discount_list2 = common_vendor.resolveComponent("s-discount-list");
  43. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  44. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  45. (_easycom_s_address_item2 + _easycom_s_goods_item2 + _easycom_uni_easyinput2 + _easycom_s_coupon_select2 + _easycom_s_discount_list2 + _easycom_su_fixed2 + _easycom_s_layout2)();
  46. }
  47. const _easycom_s_address_item = () => "../../sheep/components/s-address-item/s-address-item.js";
  48. const _easycom_s_goods_item = () => "../../sheep/components/s-goods-item/s-goods-item.js";
  49. const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
  50. const _easycom_s_coupon_select = () => "../../sheep/components/s-coupon-select/s-coupon-select.js";
  51. const _easycom_s_discount_list = () => "../../sheep/components/s-discount-list/s-discount-list.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_coupon_select + _easycom_s_discount_list + _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. showCoupon: false,
  71. // 是否展示优惠劵
  72. couponInfo: [],
  73. // 优惠劵列表
  74. showDiscount: false
  75. // 是否展示营销活动
  76. });
  77. function onSelectAddress() {
  78. common_vendor.index.$once("SELECT_ADDRESS", (e) => {
  79. changeConsignee(e.addressInfo);
  80. });
  81. sheep_index.sheep.$router.go("/pages/user/address/list");
  82. }
  83. async function changeConsignee(addressInfo = {}) {
  84. if (!common_vendor.lodashExports.isEmpty(addressInfo)) {
  85. state.addressInfo = addressInfo;
  86. }
  87. await getOrderInfo();
  88. }
  89. async function onSelectCoupon(couponId) {
  90. state.orderPayload.couponId = couponId || 0;
  91. await getOrderInfo();
  92. state.showCoupon = false;
  93. }
  94. function onConfirm() {
  95. if (!state.addressInfo.id) {
  96. sheep_index.sheep.$helper.toast("请选择收货地址");
  97. return;
  98. }
  99. submitOrder();
  100. }
  101. async function submitOrder() {
  102. const { code, data } = await sheep_api_trade_order.OrderApi.createOrder({
  103. items: state.orderPayload.items,
  104. couponId: state.orderPayload.couponId,
  105. addressId: state.addressInfo.id,
  106. deliveryType: 1,
  107. // TODO 芋艿:需要支持【门店自提】
  108. pointStatus: false,
  109. // TODO 芋艿:需要支持【积分选择】
  110. combinationActivityId: state.orderPayload.combinationActivityId,
  111. combinationHeadId: state.orderPayload.combinationHeadId,
  112. seckillActivityId: state.orderPayload.seckillActivityId
  113. });
  114. if (code !== 0) {
  115. return;
  116. }
  117. if (state.orderPayload.items[0].cartId > 0) {
  118. sheep_index.sheep.$store("cart").getList();
  119. }
  120. sheep_index.sheep.$router.redirect("/pages/pay/index", {
  121. id: data.payOrderId
  122. });
  123. }
  124. async function getOrderInfo() {
  125. const { data, code } = await sheep_api_trade_order.OrderApi.settlementOrder({
  126. items: state.orderPayload.items,
  127. couponId: state.orderPayload.couponId,
  128. addressId: state.addressInfo.id,
  129. deliveryType: 1,
  130. // TODO 芋艿:需要支持【门店自提】
  131. pointStatus: false,
  132. // TODO 芋艿:需要支持【积分选择】
  133. combinationActivityId: state.orderPayload.combinationActivityId,
  134. combinationHeadId: state.orderPayload.combinationHeadId,
  135. seckillActivityId: state.orderPayload.seckillActivityId
  136. });
  137. if (code !== 0) {
  138. return;
  139. }
  140. state.orderInfo = data;
  141. if (state.orderInfo.address) {
  142. state.addressInfo = state.orderInfo.address;
  143. }
  144. }
  145. async function getCoupons() {
  146. const { code, data } = await sheep_api_promotion_coupon.CouponApi.getMatchCouponList(
  147. state.orderInfo.price.payPrice,
  148. state.orderInfo.items.map((item) => item.spuId),
  149. state.orderPayload.items.map((item) => item.skuId),
  150. state.orderPayload.items.map((item) => item.categoryId)
  151. );
  152. if (code === 0) {
  153. state.couponInfo = data;
  154. }
  155. }
  156. common_vendor.onLoad(async (options) => {
  157. if (!options.data) {
  158. sheep_index.sheep.$helper.toast("参数不正确,请检查!");
  159. return;
  160. }
  161. state.orderPayload = JSON.parse(options.data);
  162. await getOrderInfo();
  163. await getCoupons();
  164. });
  165. return (_ctx, _cache) => {
  166. return common_vendor.e({
  167. a: common_vendor.p({
  168. item: state.addressInfo,
  169. hasBorderBottom: false
  170. }),
  171. b: common_vendor.o(onSelectAddress),
  172. c: common_vendor.f(state.orderInfo.items, (item, k0, i0) => {
  173. return {
  174. a: item.skuId,
  175. b: "324e7894-2-" + i0 + ",324e7894-0",
  176. c: common_vendor.p({
  177. img: item.picUrl,
  178. title: item.spuName,
  179. skuText: item.properties.map((property) => property.valueName).join(" "),
  180. price: item.price,
  181. num: item.count,
  182. marginBottom: "10"
  183. })
  184. };
  185. }),
  186. d: common_vendor.o(($event) => state.orderPayload.remark = $event),
  187. e: common_vendor.p({
  188. maxlength: "20",
  189. placeholder: "建议留言前先与商家沟通",
  190. inputBorder: false,
  191. clearable: false,
  192. modelValue: state.orderPayload.remark
  193. }),
  194. f: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.totalPrice)),
  195. g: state.orderPayload.order_type === "score"
  196. }, state.orderPayload.order_type === "score" ? {
  197. h: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/goods/score1.svg"),
  198. i: common_vendor.t(state.orderInfo.score_amount)
  199. } : {}, {
  200. j: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.deliveryPrice)),
  201. k: state.orderInfo.type === 0
  202. }, state.orderInfo.type === 0 ? common_vendor.e({
  203. l: state.orderPayload.couponId > 0
  204. }, state.orderPayload.couponId > 0 ? {
  205. m: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.couponPrice))
  206. } : {
  207. n: common_vendor.t(state.couponInfo.length > 0 ? state.couponInfo.length + " 张可用" : "暂无可用优惠券"),
  208. o: common_vendor.n(state.couponInfo.length > 0 ? "text-red" : "text-disabled")
  209. }, {
  210. p: common_vendor.o(($event) => state.showCoupon = true)
  211. }) : {}, {
  212. q: state.orderInfo.price.discountPrice > 0
  213. }, state.orderInfo.price.discountPrice > 0 ? {
  214. r: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.discountPrice))
  215. } : {}, {
  216. s: common_vendor.t(state.orderInfo.items.reduce((acc, item) => acc + item.count, 0)),
  217. t: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice)),
  218. v: common_vendor.o(onSelectCoupon),
  219. w: common_vendor.o(($event) => state.showCoupon = false),
  220. x: common_vendor.o(($event) => state.couponInfo = $event),
  221. y: common_vendor.p({
  222. show: state.showCoupon,
  223. modelValue: state.couponInfo
  224. }),
  225. z: common_vendor.o(($event) => state.showDiscount = false),
  226. A: common_vendor.o(($event) => state.orderInfo = $event),
  227. B: common_vendor.p({
  228. show: state.showDiscount,
  229. modelValue: state.orderInfo
  230. }),
  231. C: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice)),
  232. D: common_vendor.o(onConfirm),
  233. E: common_vendor.p({
  234. bottom: true,
  235. opacity: false,
  236. bg: "bg-white",
  237. placeholder: true,
  238. noFixed: false,
  239. index: 200
  240. }),
  241. F: common_vendor.p({
  242. title: "确认订单"
  243. })
  244. });
  245. };
  246. }
  247. };
  248. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-324e7894"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/pages/order/confirm.vue"]]);
  249. wx.createPage(MiniProgramPage);