integralSubmitOrder.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. if(res.nextPay){
  144. this.calWeixinPay(res.orderNumbers);
  145. }else{
  146. wx.redirectTo({
  147. url: `/pages/pay-result/pay-result?sts=1&orderNumbers=${res.orderNumbers}&orderType=${this.data.orderType}`,
  148. })
  149. }
  150. }
  151. };
  152. http.request(params);
  153. },
  154. /**
  155. * 唤起微信支付
  156. */
  157. calWeixinPay: function(orderNumbers) {
  158. if (this.data.actualTotal == 0) {
  159. this.setData({
  160. isPurePoints: true
  161. })
  162. }
  163. wx.showLoading({
  164. mask: true
  165. });
  166. var params = {
  167. url: "/p/order/pay",
  168. method: "POST",
  169. data: {
  170. payType: 1,
  171. orderNumbers: orderNumbers
  172. },
  173. callBack: res => {
  174. wx.hideLoading();
  175. if (this.data.isPurePoints) {
  176. wx.navigateTo({
  177. url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + orderNumbers + "&orderType=" + this.data.orderType,
  178. })
  179. } else {
  180. wx.requestPayment({
  181. timeStamp: res.timeStamp,
  182. nonceStr: res.nonceStr,
  183. package: res.package,
  184. signType: res.signType,
  185. paySign: res.paySign,
  186. success: e => {
  187. console.log('积分+钱')
  188. wx.navigateTo({
  189. url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + orderNumbers + "&orderType=" + this.data.orderType,
  190. })
  191. },
  192. fail: err => {
  193. console.log('积分+钱')
  194. wx.navigateTo({
  195. url: '/pages/pay-result/pay-result?sts=0&orderNumbers=' + orderNumbers + "&orderType=" + this.data.orderType,
  196. })
  197. }
  198. })
  199. }
  200. }
  201. };
  202. http.request(params);
  203. },
  204. /**
  205. * 生命周期函数--监听页面初次渲染完成
  206. */
  207. onReady: function() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面显示
  211. */
  212. onShow: function() {
  213. var pages = getCurrentPages();
  214. var currPage = pages[pages.length - 1];
  215. if (currPage.data.selAddress == "yes") {
  216. this.setData({ //将携带的参数赋值
  217. userAddr: currPage.data.item
  218. });
  219. }
  220. //获取订单数据
  221. this.loadOrderData();
  222. },
  223. /**
  224. * 生命周期函数--监听页面隐藏
  225. */
  226. onHide: function() {
  227. },
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function() {
  232. },
  233. /**
  234. * 页面相关事件处理函数--监听用户下拉动作
  235. */
  236. onPullDownRefresh: function() {
  237. },
  238. /**
  239. * 页面上拉触底事件的处理函数
  240. */
  241. onReachBottom: function() {
  242. },
  243. /**
  244. * 用户点击右上角分享
  245. */
  246. onShareAppMessage: function() {
  247. },
  248. changeCouponSts: function(e) {
  249. this.setData({
  250. couponSts: e.currentTarget.dataset.sts
  251. });
  252. },
  253. // 店铺优惠券弹框
  254. showCouponPopup: function(e) {
  255. var index = e.currentTarget.dataset.index;
  256. var shopCartOrders = this.data.shopCartOrders;
  257. this.setData({
  258. coupons: shopCartOrders[index].showCoupons,
  259. popupShow: true
  260. });
  261. },
  262. closePopup: function() {
  263. this.setData({
  264. popupShow: false
  265. });
  266. },
  267. /**
  268. * 去地址页面
  269. */
  270. toAddrListPage: function() {
  271. wx.navigateTo({
  272. url: '/pages/delivery-address/delivery-address?order=0',
  273. })
  274. },
  275. /**
  276. * 确定选择好的优惠券
  277. */
  278. choosedCoupon: function() {
  279. this.loadOrderData();
  280. this.setData({
  281. popupShow: false
  282. });
  283. },
  284. /**-
  285. * 优惠券子组件发过来
  286. */
  287. checkCoupon: function(e) {
  288. var ths = this;
  289. let index = ths.data.couponIds.indexOf(e.detail.couponId);
  290. if (index === -1) {
  291. ths.data.couponIds.push(e.detail.couponId)
  292. } else {
  293. ths.data.couponIds.splice(index, 1)
  294. }
  295. },
  296. /**
  297. * 输入备注
  298. */
  299. onRemarkIpt: function(e) {
  300. // var index = e.currentTarget.dataset.index;
  301. // var shopCartOrders = this.data.shopCartOrders;
  302. this.setData({
  303. remarks: e.detail.value
  304. })
  305. // this.setData({
  306. // shopCartOrders: shopCartOrders
  307. // });
  308. console.log(this.data.remarks)
  309. }
  310. })