confirmCreateOrder.js 13 KB

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