seckillOrder.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // subPackagesB/pages/GroupConfirm/GroupConfirm.js
  2. import {
  3. get,
  4. post
  5. } from '../../../utils/http'
  6. var timer;
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. storeName: '', //店铺名称
  14. seckillDetail: '', //美妆产品详情
  15. store_id: '', //店铺ID
  16. goods_id: '', //美妆产品ID
  17. payNow: false, //控制提交订单弹出框
  18. inserllAmount: '', // 我的储值
  19. pay_methon: 1, //支付方式 1微信2储值
  20. orderId: '', //订单ID
  21. seckill_id:"",//秒杀ID
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. // 禁用分享
  28. wx.hideShareMenu()
  29. this.setData({
  30. goods_id: options.goods_id,
  31. store_id: options.store_id || wx.getStorageSync('store_id'),
  32. seckill_id:options.seckill_id
  33. })
  34. // 获取我的储值
  35. this.getAmount()
  36. // 获取秒杀产品详情
  37. this.getSeckillDetail()
  38. // 获取店铺信息
  39. this.getStoreInfo()
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide() {},
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload() {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh() {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom() {
  69. },
  70. /**
  71. * 用户点击右上角分享
  72. */
  73. onShareAppMessage() {
  74. },
  75. // 获取秒杀商品详情
  76. getSeckillDetail() {
  77. get('v2/api/spike/info', {
  78. id: this.data.goods_id,
  79. seckill_id:this.data.seckill_id
  80. }, (res => {
  81. if (res.code == 200) {
  82. this.setData({
  83. seckillDetail: res.data
  84. })
  85. }
  86. }))
  87. },
  88. // 获取店铺信息
  89. getStoreInfo() {
  90. get('api/store/info', {
  91. store_id: this.data.store_id
  92. }, (res => {
  93. if (res.code == 200) {
  94. this.setData({
  95. storeName: res.data.store_name
  96. })
  97. }
  98. }))
  99. },
  100. // 提交订单
  101. ongoodsPay() {
  102. let params = {
  103. goods_id: this.data.goods_id.toString(),
  104. store_id: this.data.store_id.toString(),
  105. seckill_id: this.data.seckillDetail.seckill_id.toString()
  106. }
  107. post('v2/api/spike/buy', params, res => {
  108. if (res.code == 200) {
  109. if (res.data.pay_status == 1) {
  110. wx.showToast({
  111. title: '支付成功',
  112. icon: 'success'
  113. })
  114. // 只有项目购买,需要订阅消息
  115. wx.reLaunch({
  116. url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${res.data.order_id}`
  117. })
  118. } else {
  119. this.setData({
  120. payNow: true,
  121. orderId: res.data.order_id
  122. })
  123. }
  124. }
  125. })
  126. },
  127. /**
  128. * 订单支付
  129. */
  130. payOrder() {
  131. let that = this
  132. let url = 'v2/api/order/goods/pay'
  133. post(
  134. url, {
  135. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  136. order_id: this.data.orderId
  137. },
  138. (res) => {
  139. that.setData({
  140. payNow: false
  141. })
  142. if (that.data.pay_methon == 2) {
  143. that.goToOrder('支付成功')
  144. return
  145. }
  146. wx.requestPayment({
  147. timeStamp: res.data.pay_data.timeStamp,
  148. nonceStr: res.data.pay_data.nonceStr,
  149. package: res.data.pay_data.package,
  150. signType: res.data.pay_data.signType,
  151. paySign: res.data.pay_data.paySign,
  152. success(res) {
  153. if (res.errMsg == 'requestPayment:ok') {
  154. that.goToOrder('支付成功')
  155. }
  156. },
  157. fail(res) {
  158. that.goToOrder('支付失败')
  159. }
  160. })
  161. }
  162. )
  163. },
  164. /**
  165. * 跳转订单列表
  166. */
  167. goToOrder(text) {
  168. let that = this
  169. wx.showToast({
  170. title: text,
  171. icon: text == '支付成功' ? 'success' : 'error'
  172. })
  173. if (text == '支付成功') {
  174. // 只有项目购买,需要订阅消息
  175. if (this.data.isGrouping) {
  176. this.checkOrder()
  177. } else {
  178. wx.reLaunch({
  179. url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${that.data.orderId}`
  180. })
  181. }
  182. return
  183. } else {
  184. let failUrl = `/pages/goods/orderList/orderList?current=0`
  185. setTimeout(() => {
  186. wx.reLaunch({
  187. url: failUrl
  188. })
  189. }, 1000)
  190. }
  191. },
  192. // 关闭提交订单框
  193. onClosePay() {
  194. this.setData({
  195. payNow: false
  196. })
  197. },
  198. // 选择微信支付
  199. pay_methonw() {
  200. this.setData({
  201. pay_methon: 1
  202. })
  203. },
  204. // 选择储值支付
  205. pay_methonc() {
  206. this.setData({
  207. pay_methon: 2
  208. })
  209. },
  210. /**
  211. * 获取我的储值
  212. * api/user
  213. */
  214. getAmount() {
  215. get('api/user/amount', {}, (res) => {
  216. if (res.data) {
  217. this.setData({
  218. inserllAmount: res.data.amount
  219. })
  220. }
  221. })
  222. },
  223. })