confirmOrder.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // pages/confirmOrder/confirmOrder.js
  2. const getReq = require('./../../config.js').getReq
  3. let appInstance = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. goods_id: '',
  10. ifcart: '',
  11. num: '',
  12. datas: {},
  13. goods_list: [],
  14. firstLoad: true,
  15. defaultAddress: null,
  16. cart_id: ''
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. let goods_id = options.goods_id || ''
  23. let iscart = options.iscart || ''
  24. let num = options.num || ''
  25. let cart_id = options.cart_id || ''
  26. this.setData({
  27. goods_id,
  28. ifcart: iscart,
  29. num,
  30. cart_id
  31. })
  32. this.getDatas(goods_id, iscart, num, cart_id)
  33. },
  34. getDatas(goods_id, ifcart, num, cart_id) {
  35. wx.showLoading({
  36. title: '加载中',
  37. })
  38. var self = this
  39. let goods_datas = '';
  40. if (ifcart == 0) {
  41. goods_datas = goods_id + '|' + num;
  42. }
  43. else {
  44. goods_datas = cart_id;
  45. }
  46. getReq({
  47. act: 'member_buy',
  48. op: 'step_first',
  49. curpage: 1,
  50. cart_id: goods_datas,
  51. ifcart,
  52. }, function (res) {
  53. wx.hideLoading()
  54. if (res.code == 200) {
  55. let datas = res.datas
  56. console.log('datas')
  57. console.log(datas)
  58. let goods_list = self.getGoodsList(datas.summary, datas.goods_list)
  59. self.setData({
  60. datas,
  61. goods_list,
  62. firstLoad: false,
  63. defaultAddress: datas.address
  64. })
  65. }
  66. else {
  67. wx.showToast({
  68. icon: 'none',
  69. title: res.message,
  70. duration: 2000
  71. })
  72. wx.navigateBack()
  73. }
  74. }, function () {
  75. wx.navigateBack()
  76. })
  77. },
  78. getGoodsList(summary, goods_list) {
  79. let newGoodsList = []
  80. goods_list.map((item, index) => {
  81. summary.filter((list, key) => {
  82. if (item.goods_id == list.goods_id) {
  83. let goods_item = list
  84. goods_item.goods_num = item.goods_num
  85. newGoodsList.push(goods_item)
  86. return true
  87. }
  88. })
  89. })
  90. return newGoodsList
  91. },
  92. toPay() {
  93. let goods_id = this.data.goods_id
  94. let goods_num = this.data.num
  95. let iscart = this.data.ifcart
  96. let cart_id = this.data.cart_id
  97. let vat_hash = this.data.datas['payinfo'].vat_hash
  98. let offpay_hash = this.data.datas['payinfo'].offpay_hash
  99. let offpay_hash_batch = this.data.datas['payinfo'].offpay_hash_batch
  100. let address_id = this.data.defaultAddress.address_id ? this.data.defaultAddress.address_id : this.data.datas['address'].address_id
  101. let ifcart = cart_id ? 1 : 0
  102. let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
  103. getReq({
  104. act: 'member_buy',
  105. op: 'step_second',
  106. payment: 'jspay',
  107. usebonus: 1,
  108. ifcart,
  109. cart_id: cartids,
  110. address_id,
  111. invoice_id: 0,
  112. vat_hash,
  113. offpay_hash,
  114. offpay_hash_batch
  115. }, function (res) {
  116. wx.hideLoading()
  117. console.log(res)
  118. if (res.code == 200) {
  119. }
  120. else {
  121. wx.showToast({
  122. icon: 'none',
  123. title: res.message,
  124. duration: 2000
  125. })
  126. wx.navigateBack()
  127. }
  128. }, function (err) {
  129. console.log(err)
  130. wx.navigateBack()
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. console.log('show')
  143. if (!this.data.firstLoad) {
  144. let defaultAddress = appInstance.globalData.defaultAddress
  145. console.log(defaultAddress)
  146. this.setData({
  147. defaultAddress
  148. })
  149. }
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom: function () {
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function () {
  175. }
  176. })