confirmOrder.js 4.3 KB

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