confirmOrder.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. let goods_list = self.getGoodsList(datas.summary, datas.goods_list)
  57. let { true_name, mob_phone, area_info, address, address_id } = datas.address
  58. appInstance.checkDefaultAddress({
  59. true_name,
  60. mob_phone,
  61. area_info,
  62. address,
  63. address_id
  64. })
  65. self.setData({
  66. datas,
  67. goods_list,
  68. firstLoad: false,
  69. defaultAddress: datas.address
  70. })
  71. }
  72. else {
  73. wx.showToast({
  74. icon: 'none',
  75. title: res.message,
  76. duration: 2000
  77. })
  78. wx.navigateBack()
  79. }
  80. }, function () {
  81. wx.navigateBack()
  82. })
  83. },
  84. getGoodsList(summary, goods_list) {
  85. let newGoodsList = []
  86. goods_list.map((item, index) => {
  87. summary.filter((list, key) => {
  88. if (item.goods_id == list.goods_id) {
  89. let goods_item = list
  90. goods_item.goods_num = item.goods_num
  91. newGoodsList.push(goods_item)
  92. return true
  93. }
  94. })
  95. })
  96. return newGoodsList
  97. },
  98. toPay() {
  99. let goods_id = this.data.goods_id
  100. let goods_num = this.data.num
  101. let iscart = this.data.ifcart
  102. let cart_id = this.data.cart_id
  103. let vat_hash = this.data.datas['payinfo'].vat_hash
  104. let offpay_hash = this.data.datas['payinfo'].offpay_hash
  105. let offpay_hash_batch = this.data.datas['payinfo'].offpay_hash_batch
  106. let address_id = this.data.defaultAddress.address_id ? this.data.defaultAddress.address_id : this.data.datas['address'].address_id
  107. let ifcart = cart_id ? 1 : 0
  108. let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
  109. getReq({
  110. act: 'member_buy',
  111. op: 'step_second',
  112. payment: 'jspay',
  113. usebonus: 1,
  114. ifcart,
  115. cart_id: cartids,
  116. address_id,
  117. invoice_id: 0,
  118. vat_hash,
  119. offpay_hash,
  120. offpay_hash_batch
  121. }, function (res) {
  122. wx.hideLoading()
  123. console.log(res)
  124. if (res.code == 200) {
  125. }
  126. else {
  127. wx.showToast({
  128. icon: 'none',
  129. title: res.message,
  130. duration: 2000
  131. })
  132. wx.navigateBack()
  133. }
  134. }, function (err) {
  135. wx.navigateBack()
  136. })
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow: function () {
  147. if (!this.data.firstLoad) {
  148. let defaultAddress = appInstance.globalData.defaultAddress
  149. console.log(defaultAddress)
  150. this.setData({
  151. defaultAddress
  152. })
  153. }
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload: function () {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh: function () {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom: function () {
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage: function () {
  179. }
  180. })