beerBoxPayment.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // pages/beerBoxPayment/beerBoxPayment.js
  2. const request = require("../../utils/request.js");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. boxId: null,
  9. beerBoxDetail: {},
  10. type: 'BeerBlindBox',
  11. outId: null,
  12. priceList_index: 0,
  13. num: 1,
  14. deviceNo: 'wxMiniApp',
  15. userAddressId: null,
  16. adress_select: {}
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. if(options.boxId) {
  23. this.setData({
  24. boxId: options.boxId
  25. })
  26. }
  27. this.geBoxtDetail();
  28. this.getAddressDefault();
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady() {
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow() {
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload() {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh() {
  54. },
  55. /**
  56. * 页面上拉触底事件的处理函数
  57. */
  58. onReachBottom() {
  59. },
  60. /**
  61. * 用户点击右上角分享
  62. */
  63. onShareAppMessage() {
  64. },
  65. //查询订单支付状态
  66. orderGet(orderId) {
  67. let that = this;
  68. request.getData(
  69. 'app/order/get',{orderId: orderId},
  70. res => {
  71. console.log(res)
  72. },
  73. res => {
  74. console.log(res)
  75. }
  76. )
  77. },
  78. //测试环境支付
  79. orderPayGet(orderId) {
  80. let that = this;
  81. request.getData(
  82. 'app/order/notify_url',{orderId: orderId},
  83. res => {
  84. console.log(res)
  85. that.orderGet(orderId)
  86. },
  87. res => {
  88. console.log(res)
  89. }
  90. )
  91. },
  92. //微信小程序统一下单
  93. wxpayOrderPay(orderId) {
  94. let that = this;
  95. request.postData(
  96. 'app/pay/wxpay/program/unified',{orderId: orderId},
  97. res => {
  98. wx.requestPayment({
  99. timeStamp: res.data.data.timeStamp,
  100. nonceStr: res.data.data.nonceStr,
  101. package: res.data.data.packageVal,
  102. signType: 'RSA',
  103. paySign: res.data.data.paySign,
  104. success (res) { },
  105. fail (res) { }
  106. })
  107. },
  108. res => {
  109. console.log(res)
  110. }
  111. )
  112. },
  113. //创建订单
  114. createOrder() {
  115. let that = this;
  116. request.postData(
  117. 'app/order/create',
  118. {
  119. deviceNo: that.data.deviceNo,
  120. type: that.data.type,
  121. userAddressId: that.data.userAddressId,
  122. num: that.data.num,
  123. outId: that.data.outId
  124. },
  125. res => {
  126. console.log(res.data.data)
  127. let orderId = res.data.data;
  128. this.wxpayOrderPay(orderId);
  129. // this.orderPayGet(orderId);
  130. }
  131. )
  132. },
  133. geBoxtDetail() {
  134. let that = this;
  135. request.getData(
  136. 'app/box/detail',{boxId: that.data.boxId},
  137. res => {
  138. that.setData({
  139. beerBoxDetail: res.data.data,
  140. outId: res.data.data.priceList[0].priceId
  141. })
  142. },
  143. res => {
  144. console.log(res)
  145. }
  146. )
  147. },
  148. backFun() {
  149. wx.navigateBack({
  150. delta: 1
  151. })
  152. },
  153. reduce() {
  154. if(this.data.num>1 && this.data.num<4) {
  155. this.setData({
  156. num: this.data.num - 1
  157. })
  158. }
  159. },
  160. add() {
  161. if(this.data.num>=1 && this.data.num<3) {
  162. this.setData({
  163. num: this.data.num + 1
  164. })
  165. }
  166. },
  167. toMineAd() {
  168. let that = this;
  169. wx.navigateTo({
  170. url: '../mineAddress/mineAddress',
  171. events: {
  172. getSelectAd: function(data) {
  173. that.setData({
  174. adress_select: data,
  175. userAddressId: data.userAddressId
  176. })
  177. }
  178. },
  179. })
  180. },
  181. bindPickerCycle(e) {
  182. // console.log('picker发送选择改变,携带值为', e.detail.value)
  183. this.setData({
  184. priceList_index: e.detail.value,
  185. outId: this.data.beerBoxDetail.priceList[e.detail.value].priceId
  186. })
  187. },
  188. //获取默认地址
  189. getAddressDefault() {
  190. let that = this;
  191. request.getData(
  192. 'app/user/address/list',{},
  193. res => {
  194. let ad_list = res.data.data;
  195. ad_list.filter(item=>{
  196. if(item.defaultAddress){
  197. that.setData({
  198. adress_select: item,
  199. userAddressId: item.userAddressId
  200. })
  201. }
  202. })
  203. }
  204. )
  205. },
  206. })