confirmCreateOrder.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_order = require("../api/order.js");
  4. const common_assets = require("../common/assets.js");
  5. const EvanSwitch = () => "../components/evan-switch/evan-switch.js";
  6. const popupBottom = () => "../components/px-popup-bottom/px-popup-bottom.js";
  7. const _sfc_main = {
  8. components: {
  9. EvanSwitch,
  10. popupBottom
  11. },
  12. data() {
  13. return {
  14. address: null,
  15. addressId: null,
  16. totalNum: null,
  17. orderKey: null,
  18. price: null,
  19. liveId: null,
  20. orderList: [],
  21. userInfo: null,
  22. userAddrLiat: [],
  23. //用户地址
  24. temps: [],
  25. couponUserId: null,
  26. couponText: "请选择",
  27. couponsList: [],
  28. couponVisible: false,
  29. priceAll: {
  30. payPrice: 0,
  31. totalPostage: 0,
  32. usedIntegral: 0,
  33. totalPrice: 0
  34. },
  35. carts: [],
  36. checked: false,
  37. type: null,
  38. cartIds: null,
  39. // form:{
  40. // useIntegral:0,
  41. // orderKey:null,
  42. // addressId:null,
  43. // mark:null,
  44. // companyId:null,
  45. // companyUserId:null,
  46. // createOrderKey:null,
  47. // },
  48. confirmParam: []
  49. };
  50. },
  51. computed: {
  52. priceSum() {
  53. return this.price * this.totalNum;
  54. }
  55. },
  56. onLoad(options) {
  57. console.log("确认订单", options);
  58. this.orderKey = options.orderKey;
  59. this.liveId = options.liveId;
  60. this.productId = options.productId;
  61. this.totalNum = Number(options.totalNum);
  62. this.price = Number(options.price);
  63. this.type = options.type;
  64. },
  65. mounted() {
  66. this.getUserAddr();
  67. common_vendor.index.$on("updateAddress", (e) => {
  68. this.address = e;
  69. this.addressId = e.addressId;
  70. });
  71. },
  72. beforeDestroy() {
  73. common_vendor.index.$off("updateAddress");
  74. },
  75. methods: {
  76. // 获取用户收货地址
  77. getUserAddr() {
  78. this.userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  79. api_order.userAddr(this.userInfo.userId).then(
  80. (res) => {
  81. if (res.code == 200) {
  82. console.log("用户收货地址>>>>", res.data);
  83. this.address = res.data.find((item) => item.isDefault == 1);
  84. } else {
  85. common_vendor.index.showToast({
  86. title: res.msg,
  87. icon: "none"
  88. });
  89. }
  90. },
  91. (rej) => {
  92. }
  93. );
  94. },
  95. // 创建订单
  96. createLiveOrder() {
  97. let data = {
  98. liveId: this.liveId,
  99. orderKey: this.orderKey,
  100. // storeId:this.storeId,,
  101. userName: this.address.realName,
  102. userPhone: this.address.phone,
  103. userAddress: this.address.province + this.address.city + this.address.district + this.address.detail,
  104. // cartId:"5",
  105. productId: this.productId,
  106. totalNum: this.totalNum
  107. // totalPrice:999,
  108. // remark:"随便备注",
  109. };
  110. return api_order.createliveOrder(data).then((res) => {
  111. if (res.code == 200) {
  112. this.orderList = res.order;
  113. return res.order;
  114. } else {
  115. common_vendor.index.showToast({
  116. title: res.msg,
  117. icon: "none"
  118. });
  119. throw new Error(res.msg);
  120. }
  121. });
  122. },
  123. getWeixinOrderTemps: function() {
  124. getWeixinOrderTemps().then(
  125. (res) => {
  126. if (res.code == 200) {
  127. this.temps = res.temp;
  128. }
  129. },
  130. (rej) => {
  131. }
  132. );
  133. },
  134. couponSelect(item) {
  135. this.couponText = "-¥" + item.couponPrice.toFixed(2);
  136. this.couponUserId = item.id;
  137. this.couponVisible = false;
  138. this.computed();
  139. },
  140. openCoupon() {
  141. let that = this;
  142. var data = {
  143. couponType: 2,
  144. useMinPrice: this.price.payPrice
  145. };
  146. getMyEnableCouponList(data).then((res) => {
  147. this.couponVisible = true;
  148. that.couponsList = res.data;
  149. });
  150. },
  151. integralChange(e) {
  152. this.form.useIntegral = e ? 1 : 0;
  153. this.computed();
  154. },
  155. openAddress() {
  156. common_vendor.index.navigateTo({
  157. url: "/pages_user/address"
  158. });
  159. },
  160. // 提交订单
  161. async submitOrder() {
  162. try {
  163. if (this.orderKey == null) {
  164. common_vendor.index.showToast({
  165. icon: "none",
  166. title: "订单KEY不存在"
  167. });
  168. return;
  169. }
  170. if (this.address == null) {
  171. common_vendor.index.showToast({
  172. icon: "none",
  173. title: "收货地址不能为空"
  174. });
  175. return;
  176. }
  177. const orderList = await this.createLiveOrder();
  178. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  179. common_vendor.index.navigateTo({
  180. url: `/pages_shop/paymentOrder?orderList=${orderListStr}`
  181. });
  182. } catch (error) {
  183. console.error("订单创建失败:", error);
  184. common_vendor.index.showToast({
  185. title: "提交失败",
  186. icon: "none"
  187. });
  188. }
  189. },
  190. // 购物车支付订单
  191. async creatCartOrder() {
  192. try {
  193. if (this.orderKey == null) {
  194. common_vendor.index.showToast({
  195. icon: "none",
  196. title: "订单KEY不存在"
  197. });
  198. return;
  199. }
  200. if (this.address == null) {
  201. common_vendor.index.showToast({
  202. icon: "none",
  203. title: "收货地址不能为空"
  204. });
  205. return;
  206. }
  207. const orderList = await this.cartOrder();
  208. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  209. common_vendor.index.navigateTo({
  210. url: `/pages_shop/paymentOrder?orderList=${orderListStr}`
  211. });
  212. } catch (error) {
  213. console.error("订单创建失败:", error);
  214. common_vendor.index.showToast({
  215. title: "提交失败",
  216. icon: "none"
  217. });
  218. }
  219. }
  220. // var that=this;
  221. // if(this.form.orderKey==null){
  222. // uni.showToast({
  223. // icon:'none',
  224. // title: '订单KEY不存在',
  225. // });
  226. // return;
  227. // }
  228. // if(this.form.addressId==null){
  229. // uni.showToast({
  230. // icon:'none',
  231. // title: '收货地址不能为空',
  232. // });
  233. // return;
  234. // }
  235. // uni.requestSubscribeMessage({
  236. // tmplIds: this.temps,
  237. // success(res) {
  238. // that.createOrder();
  239. // },
  240. // fail(res) {
  241. // that.createOrder();
  242. // }
  243. // })
  244. // createOrder() {
  245. // const mark = this.carts.map(item => item.markinfo)
  246. // var that = this;
  247. // var data = null;
  248. // var tuiUserId = uni.getStorageSync('tuiUserId');
  249. // uni.showLoading({
  250. // title: '正在处理中...'
  251. // });
  252. // if (tuiUserId != null && tuiUserId != undefined && tuiUserId > 0) {
  253. // data = {
  254. // createOrderKey: this.form.createOrderKey,
  255. // orderCreateType: 3,
  256. // tuiUserId: tuiUserId,
  257. // companyId: this.form.companyId,
  258. // companyUserId: this.form.companyUserId,
  259. // couponUserId: this.couponUserId,
  260. // mark: mark,
  261. // orderKeys: this.form.orderKey,
  262. // addressId: this.form.addressId,
  263. // useIntegral: this.form.useIntegral,
  264. // payType: 1
  265. // };
  266. // } else {
  267. // data = {
  268. // createOrderKey: this.form.createOrderKey,
  269. // orderCreateType: 3,
  270. // companyId: this.form.companyId,
  271. // companyUserId: this.form.companyUserId,
  272. // couponUserId: this.couponUserId,
  273. // mark: mark,
  274. // orderKeys: this.form.orderKey,
  275. // addressId: this.form.addressId,
  276. // useIntegral: this.form.useIntegral,
  277. // payType: 1
  278. // };
  279. // }
  280. // create(data).then(
  281. // res => {
  282. // uni.hideLoading()
  283. // if (!res.code && res.code !== 0) {
  284. // uni.hideLoading()
  285. // // if(res.order.isPrescribe==1){
  286. // // setTimeout(function(){
  287. // // uni.redirectTo({
  288. // // url:"prescribe?orderId="+res.order.id
  289. // // })
  290. // // },200);
  291. // // }
  292. // // else{
  293. // // setTimeout(function(){
  294. // // uni.redirectTo({
  295. // // url: './paymentOrder?orderId='+res.order.id
  296. // // })
  297. // // },200);
  298. // // }
  299. // if (res.some(item => item.order.isPrescribe) == 1) {
  300. // setTimeout(function() {
  301. // let orderIds = res.filter(item => item.order.isPrescribe == 1).map(it => it
  302. // .order.id)
  303. // orderIds = orderIds.join(',')
  304. // uni.redirectTo({
  305. // url: "prescribe?orderId=" + orderIds + "&combinationOrderId=" +
  306. // encodeURIComponent(res[0].order.combinationOrderId)
  307. // })
  308. // }, 200);
  309. // } else {
  310. // setTimeout(function() {
  311. // uni.redirectTo({
  312. // url: './paymentOrder?combinationOrderId=' + encodeURIComponent(
  313. // res[0].order.combinationOrderId)
  314. // })
  315. // }, 200);
  316. // }
  317. // return;
  318. // } else {
  319. // if (res.code == 501) {
  320. // uni.showToast({
  321. // icon: 'none',
  322. // title: res.msg,
  323. // });
  324. // setTimeout(function() {
  325. // uni.navigateBack({
  326. // delta: 1
  327. // })
  328. // }, 200);
  329. // return;
  330. // } else {
  331. // uni.showToast({
  332. // icon: 'none',
  333. // title: res.msg,
  334. // });
  335. // }
  336. // }
  337. // },
  338. // rej => {}
  339. // );
  340. // },// confirm(item) {
  341. // // let data = {type:this.type,cartIds:this.cartIds};
  342. // confirm(this.confirmParam).then(
  343. // res => {
  344. // if (res.code == 200) {
  345. // this.carts = res.carts.map(item => ({
  346. // ...item,
  347. // markinfo: ""
  348. // }));
  349. // this.form.orderKey = res.orderKeys;
  350. // if (res.address != null) {
  351. // this.form.addressId = res.address.id;
  352. // this.address = res.address;
  353. // }
  354. // this.computed()
  355. // } else {
  356. // uni.showToast({
  357. // icon: 'none',
  358. // title: res.msg,
  359. // });
  360. // }
  361. // },
  362. // rej => {}
  363. // );
  364. // },
  365. // computed(item) {
  366. // let data = {
  367. // createOrderKey: this.form.createOrderKey,
  368. // couponUserId: this.couponUserId,
  369. // orderKeys: this.form.orderKey,
  370. // addressId: this.form.addressId,
  371. // useIntegral: this.form.useIntegral
  372. // };
  373. // computed(data).then(
  374. // res => {
  375. // if (res.code == 200) {
  376. // // this.price=res.data
  377. // this.price = res.data && res.data.length > 0 ? res.data : []
  378. // this.priceAll = res.data && res.data.length > 0 ? res.data[res.data.length - 1] : {
  379. // payPrice: 0,
  380. // totalPostage: 0,
  381. // usedIntegral: 0,
  382. // totalPrice: 0.00,
  383. // }
  384. // } else {
  385. // if (res.code == 501) {
  386. // uni.showToast({
  387. // icon: 'none',
  388. // title: res.msg,
  389. // });
  390. // setTimeout(function() {
  391. // uni.navigateBack({
  392. // delta: 1
  393. // })
  394. // }, 500);
  395. // return;
  396. // } else {
  397. // uni.showToast({
  398. // icon: 'none',
  399. // title: res.msg,
  400. // });
  401. // }
  402. // }
  403. // },
  404. // rej => {}
  405. // );
  406. // },
  407. }
  408. };
  409. if (!Array) {
  410. const _component_popupBottom = common_vendor.resolveComponent("popupBottom");
  411. _component_popupBottom();
  412. }
  413. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  414. var _a, _b, _c;
  415. return common_vendor.e({
  416. a: $data.address == null
  417. }, $data.address == null ? {
  418. b: common_assets._imports_0$10,
  419. c: common_vendor.o(($event) => $options.openAddress())
  420. } : {}, {
  421. d: $data.address != null
  422. }, $data.address != null ? common_vendor.e({
  423. e: common_vendor.t($data.address.realName),
  424. f: $data.address.phone != null
  425. }, $data.address.phone != null ? {
  426. g: common_vendor.t(_ctx.$parsePhone($data.address.phone))
  427. } : {}, {
  428. h: common_vendor.t($data.address.province),
  429. i: common_vendor.t($data.address.city),
  430. j: common_vendor.t($data.address.district),
  431. k: common_vendor.t($data.address.detail),
  432. l: common_assets._imports_0$10,
  433. m: common_vendor.o(($event) => $options.openAddress())
  434. }) : {}, {
  435. n: common_vendor.f($data.carts, (shop, idx, i0) => {
  436. return common_vendor.e({
  437. a: shop.storeName && shop.storeName != "null"
  438. }, shop.storeName && shop.storeName != "null" ? {
  439. b: common_vendor.t(shop.storeName)
  440. } : {}, {
  441. c: common_vendor.f(shop.list, (item, index, i1) => {
  442. var _a2;
  443. return {
  444. a: item.productAttrImage ? item.productAttrImage : item.productImage,
  445. b: common_vendor.t(_ctx.utils.getDictLabelName("storeProductType", item.productType)),
  446. c: common_vendor.t(item.productName),
  447. d: common_vendor.t(item.productAttrName),
  448. e: common_vendor.t((_a2 = item.price) == null ? void 0 : _a2.toFixed(2)),
  449. f: common_vendor.t(item.cartNum),
  450. g: index
  451. };
  452. })
  453. }, $data.price && $data.price.length > 0 ? {
  454. d: common_vendor.t($data.price[idx].payPostage == null || $data.price[idx].payPostage == 0 ? "免运费" : $data.price[idx].payPostage.toFixed(2))
  455. } : {}, {
  456. e: shop.markinfo,
  457. f: common_vendor.o(($event) => shop.markinfo = $event.detail.value, idx),
  458. g: idx
  459. });
  460. }),
  461. o: $data.price && $data.price.length > 0,
  462. p: common_vendor.t((_a = $data.price) == null ? void 0 : _a.toFixed(2)),
  463. q: common_vendor.t((_b = $options.priceSum) == null ? void 0 : _b.toFixed(2)),
  464. r: common_vendor.t((_c = $options.priceSum) == null ? void 0 : _c.toFixed(2)),
  465. s: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
  466. t: $data.couponsList.length > 0
  467. }, $data.couponsList.length > 0 ? {
  468. v: common_vendor.f($data.couponsList, (item, index, i0) => {
  469. return common_vendor.e({
  470. a: item.status == 0
  471. }, item.status == 0 ? {
  472. b: common_assets._imports_2$6
  473. } : {}, {
  474. c: item.status != 0
  475. }, item.status != 0 ? {
  476. d: common_assets._imports_3$2
  477. } : {}, {
  478. e: common_vendor.t(item.couponPrice),
  479. f: common_vendor.t(item.useMinPrice),
  480. g: common_vendor.t(item.couponTitle),
  481. h: common_vendor.t(item.limitTime),
  482. i: common_vendor.o(($event) => $options.couponSelect(item), index),
  483. j: index
  484. });
  485. })
  486. } : {}, {
  487. w: $data.couponsList.length == 0
  488. }, $data.couponsList.length == 0 ? {
  489. x: common_assets._imports_2$3
  490. } : {}, {
  491. y: common_vendor.sr("popup", "5fa01107-0"),
  492. z: common_vendor.p({
  493. visible: $data.couponVisible,
  494. title: " ",
  495. bgColor: "#f5f5f5",
  496. radius: "30",
  497. maxHeight: "60%"
  498. })
  499. });
  500. }
  501. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-5fa01107"]]);
  502. wx.createPage(MiniProgramPage);