integralSubmitOrder.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // pages/submit-order/submit-order.js
  2. var http = require("../../../utils/http.js");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. popupShow: false,
  9. couponSts: 1,
  10. couponList: [],
  11. // 订单入口 0购物车 1立即购买
  12. orderEntry: "0",
  13. userAddr: null,
  14. orderItems: [],
  15. shopCartOrders: [], //所有店铺的数据
  16. productItemDto: [], //商品信息
  17. coupons: {
  18. totalLength: 0,
  19. canUseCoupons: [],
  20. noCanUseCoupons: []
  21. },
  22. actualTotal: 0,
  23. total: 0,
  24. totalCount: 0,
  25. transfee: 0,
  26. reduceAmount: 0,
  27. couponIds: [],
  28. orderReduce: 0,
  29. platformCoupons: [], //整个订单可以使用的优惠券列表
  30. scorePrice: 0,
  31. remarks: '', //留言
  32. isPurePoints: false, // 是否纯积分商品
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function(options) {
  38. this.setData({
  39. orderEntry: options.orderEntry,
  40. });
  41. this.loadOrderData()
  42. },
  43. //加载订单数据
  44. loadOrderData: function() {
  45. var addrId = 0;
  46. if (this.data.userAddr != null) {
  47. addrId = this.data.userAddr.addrId;
  48. }
  49. wx.showLoading({
  50. mask: true
  51. });
  52. console.log(JSON.parse(wx.getStorageSync("orderItem")))
  53. // console.log(JSON.parse(wx.getStorageSync("basketIds")))
  54. var params = {
  55. url: "/p/score/confirm",
  56. method: "POST",
  57. data: {
  58. addrId: addrId,
  59. orderItem: this.data.orderEntry === "1" ? JSON.parse(wx.getStorageSync("orderItem")) : undefined,
  60. basketIds: this.data.orderEntry === "0" ? JSON.parse(wx.getStorageSync("basketIds")) : undefined,
  61. couponIds: this.data.couponIds,
  62. userChangeCoupon: 1
  63. },
  64. callBack: res => {
  65. wx.hideLoading();
  66. var shopCartOrders = res.shopCartOrders;
  67. this.setData({
  68. // shopCartOrders: shopCartOrders, //每个店铺的购物车信息
  69. productItemDto: res.productItemDto, //商品信息
  70. actualTotal: res.actualTotal, //实际总值
  71. total: res.total, //商品总值
  72. totalCount: res.totalCount, //商品总数
  73. userAddr: res.userAddr, //地址Dto
  74. // transfee: res.totalTransfee, //总运费
  75. // orderReduce: res.orderReduce, //订单优惠金额(所有店铺优惠金额和使用积分抵现相加)
  76. scorePrice: res.productItemDto.scorePrice, //商品所需积分
  77. // remarks: res.remarks, //留言
  78. });
  79. },
  80. errCallBack: res => {
  81. wx.hideLoading();
  82. this.chooseCouponErrHandle(res)
  83. }
  84. };
  85. http.request(params);
  86. },
  87. /**
  88. * 优惠券选择出错处理方法
  89. */
  90. // chooseCouponErrHandle(res) {
  91. // // 优惠券不能共用处理方法
  92. // if (res.statusCode == 601) {
  93. // wx.showToast({
  94. // title: res.data,
  95. // icon: "none",
  96. // duration: 3000,
  97. // success: res => {
  98. // this.setData({
  99. // couponIds: []
  100. // })
  101. // }
  102. // })
  103. // setTimeout(() => {
  104. // this.loadOrderData();
  105. // }, 2500)
  106. // }
  107. // },
  108. /**
  109. * 提交订单
  110. */
  111. toPay: function() {
  112. if (!this.data.userAddr) {
  113. wx.showToast({
  114. title: '请选择地址',
  115. icon: "none"
  116. })
  117. return;
  118. }
  119. this.submitOrder();
  120. },
  121. // 提交订单
  122. submitOrder: function() {
  123. wx.showLoading({
  124. mask: true
  125. });
  126. // var shopCartOrders = this.data.shopCartOrders;
  127. // var orderShopParam = [];
  128. // shopCartOrders.forEach(shopCart => {
  129. // orderShopParam.push({
  130. // remarks: shopCart.remarks,
  131. // shopId: shopCart.shopId
  132. // });
  133. // })
  134. var params = {
  135. url: "/p/score/submit",
  136. method: "POST",
  137. data: {
  138. // orderShopParam: orderShopParam
  139. remarks: this.data.remarks
  140. },
  141. callBack: res => {
  142. wx.hideLoading();
  143. this.calWeixinPay(res.orderNumbers);
  144. }
  145. };
  146. http.request(params);
  147. },
  148. /**
  149. * 唤起微信支付
  150. */
  151. calWeixinPay: function(orderNumbers) {
  152. if (this.data.actualTotal == 0) {
  153. this.setData({
  154. isPurePoints: true
  155. })
  156. }
  157. wx.showLoading({
  158. mask: true
  159. });
  160. var params = {
  161. url: "/p/order/pay",
  162. method: "POST",
  163. data: {
  164. payType: 1,
  165. orderNumbers: orderNumbers
  166. },
  167. callBack: res => {
  168. wx.hideLoading();
  169. if (this.data.isPurePoints) {
  170. wx.navigateTo({
  171. url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + orderNumbers + "&orderType=" + this.data.orderType,
  172. })
  173. } else {
  174. wx.requestPayment({
  175. timeStamp: res.timeStamp,
  176. nonceStr: res.nonceStr,
  177. package: res.packageValue,
  178. signType: res.signType,
  179. paySign: res.paySign,
  180. success: e => {
  181. console.log('积分+钱')
  182. wx.navigateTo({
  183. url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + orderNumbers + "&orderType=" + this.data.orderType,
  184. })
  185. },
  186. fail: err => {
  187. console.log('积分+钱')
  188. wx.navigateTo({
  189. url: '/pages/pay-result/pay-result?sts=0&orderNumbers=' + orderNumbers + "&orderType=" + this.data.orderType,
  190. })
  191. }
  192. })
  193. }
  194. }
  195. };
  196. http.request(params);
  197. },
  198. /**
  199. * 生命周期函数--监听页面初次渲染完成
  200. */
  201. onReady: function() {
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function() {
  207. var pages = getCurrentPages();
  208. var currPage = pages[pages.length - 1];
  209. if (currPage.data.selAddress == "yes") {
  210. this.setData({ //将携带的参数赋值
  211. userAddr: currPage.data.item
  212. });
  213. }
  214. //获取订单数据
  215. this.loadOrderData();
  216. },
  217. /**
  218. * 生命周期函数--监听页面隐藏
  219. */
  220. onHide: function() {
  221. },
  222. /**
  223. * 生命周期函数--监听页面卸载
  224. */
  225. onUnload: function() {
  226. },
  227. /**
  228. * 页面相关事件处理函数--监听用户下拉动作
  229. */
  230. onPullDownRefresh: function() {
  231. },
  232. /**
  233. * 页面上拉触底事件的处理函数
  234. */
  235. onReachBottom: function() {
  236. },
  237. /**
  238. * 用户点击右上角分享
  239. */
  240. onShareAppMessage: function() {
  241. },
  242. changeCouponSts: function(e) {
  243. this.setData({
  244. couponSts: e.currentTarget.dataset.sts
  245. });
  246. },
  247. // 店铺优惠券弹框
  248. showCouponPopup: function(e) {
  249. var index = e.currentTarget.dataset.index;
  250. var shopCartOrders = this.data.shopCartOrders;
  251. this.setData({
  252. coupons: shopCartOrders[index].showCoupons,
  253. popupShow: true
  254. });
  255. },
  256. closePopup: function() {
  257. this.setData({
  258. popupShow: false
  259. });
  260. },
  261. /**
  262. * 去地址页面
  263. */
  264. toAddrListPage: function() {
  265. wx.navigateTo({
  266. url: '/pages/delivery-address/delivery-address?order=0',
  267. })
  268. },
  269. /**
  270. * 确定选择好的优惠券
  271. */
  272. choosedCoupon: function() {
  273. this.loadOrderData();
  274. this.setData({
  275. popupShow: false
  276. });
  277. },
  278. /**-
  279. * 优惠券子组件发过来
  280. */
  281. checkCoupon: function(e) {
  282. var ths = this;
  283. let index = ths.data.couponIds.indexOf(e.detail.couponId);
  284. if (index === -1) {
  285. ths.data.couponIds.push(e.detail.couponId)
  286. } else {
  287. ths.data.couponIds.splice(index, 1)
  288. }
  289. },
  290. /**
  291. * 输入备注
  292. */
  293. onRemarkIpt: function(e) {
  294. // var index = e.currentTarget.dataset.index;
  295. // var shopCartOrders = this.data.shopCartOrders;
  296. this.setData({
  297. remarks: e.detail.value
  298. })
  299. // this.setData({
  300. // shopCartOrders: shopCartOrders
  301. // });
  302. console.log(this.data.remarks)
  303. }
  304. })