confirmOrder.js 4.4 KB

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