confirmOrder.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. // console.log(goods_id, iscart, num, cart_id);
  33. this.getDatas(goods_id, iscart, num, cart_id)
  34. // this.getDatas(4807, 0, 1, '')
  35. },
  36. getDatas(goods_id, ifcart, num, cart_id) {
  37. wx.showLoading({
  38. title: '加载中',
  39. })
  40. var self = this
  41. let goods_datas = '';
  42. if (ifcart == 0) {
  43. goods_datas = goods_id + '|' + num;
  44. }
  45. else {
  46. goods_datas = cart_id;
  47. }
  48. getReq({
  49. act: 'member_buy',
  50. op: 'step_first',
  51. curpage: 1,
  52. cart_id: goods_datas,
  53. ifcart,
  54. }, function (res) {
  55. wx.hideLoading()
  56. if (res.code == 200) {
  57. console.log(res);
  58. let datas = res.datas
  59. let goods_list = self.getGoodsList(datas.summary, datas.goods_list)
  60. console.log('goods_list', goods_list);
  61. if (datas.address) {
  62. let { true_name, mob_phone, area_info, address, address_id } = datas.address;
  63. appInstance.checkDefaultAddress({
  64. true_name,
  65. mob_phone,
  66. area_info,
  67. address,
  68. address_id
  69. })
  70. }
  71. self.setData({
  72. datas,
  73. goods_list,
  74. firstLoad: false,
  75. defaultAddress: datas.address
  76. })
  77. }
  78. else {
  79. wx.showToast({
  80. icon: 'none',
  81. title: res.message,
  82. duration: 2000
  83. })
  84. appInstance.globalData.fcodeErr = res.message
  85. wx.navigateBack()
  86. }
  87. })
  88. },
  89. getGoodsList(summary, goods_list) {
  90. console.log('summary', summary);
  91. console.log('goods_list', goods_list);
  92. let newGoodsList = []
  93. goods_list.map((item, index) => {
  94. summary.find((list, key) => {
  95. if (item.goods_id == list.goods_id) {
  96. let goods_item = list
  97. goods_item.goods_num = item.goods_num
  98. newGoodsList.push(goods_item)
  99. return true
  100. }
  101. })
  102. })
  103. return newGoodsList
  104. },
  105. toPay() {
  106. if (!this.data.defaultAddress) {
  107. wx.showToast({
  108. icon: 'none',
  109. title: '请填写收货地址',
  110. duration: 1500
  111. })
  112. return
  113. }
  114. let goods_id = this.data.goods_id
  115. let goods_num = this.data.num
  116. let iscart = this.data.ifcart
  117. let cart_id = this.data.cart_id
  118. let vat_hash = this.data.datas['payinfo'].vat_hash
  119. let offpay_hash = this.data.datas['payinfo'].offpay_hash
  120. let offpay_hash_batch = this.data.datas['payinfo'].offpay_hash_batch
  121. let address_id = this.data.defaultAddress.address_id ? this.data.defaultAddress.address_id : this.data.datas['address'].address_id
  122. let ifcart = cart_id ? 1 : 0
  123. let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
  124. getReq({
  125. act: 'member_buy',
  126. op: 'step_second',
  127. payment: 'jspay',
  128. usebonus: 1,
  129. ifcart,
  130. cart_id: cartids,
  131. address_id,
  132. invoice_id: 0,
  133. vat_hash,
  134. offpay_hash,
  135. offpay_hash_batch
  136. }, function (res) {
  137. wx.hideLoading()
  138. if (res.code == 200) {
  139. let param = res.datas.param.data;
  140. wx.requestPayment({
  141. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  142. nonceStr: param.nonceStr, //随机串
  143. package: param.package,
  144. signType: param.signType, //微信签名方式:
  145. paySign: param.paySign, //微信签名
  146. success:function(res){
  147. wx.showToast({
  148. icon: 'none',
  149. title: res,
  150. duration: 2000
  151. })
  152. console.log("成功:"+res);
  153. console.log('支付成功')
  154. },
  155. fail:function(res){
  156. wx.showToast({
  157. icon: 'none',
  158. title: res,
  159. duration: 2000
  160. })
  161. console.log("失败:" + res);
  162. }
  163. });
  164. }
  165. else {
  166. wx.showToast({
  167. icon: 'none',
  168. title: res.message,
  169. duration: 2000
  170. })
  171. appInstance.globalData.fcodeErr = res.message
  172. wx.navigateBack()
  173. }
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady: function () {
  180. },
  181. /**
  182. * 生命周期函数--监听页面显示
  183. */
  184. onShow: function () {
  185. if (!this.data.firstLoad) {
  186. let defaultAddress = appInstance.globalData.defaultAddress
  187. this.setData({
  188. defaultAddress
  189. })
  190. }
  191. },
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload: function () {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh: function () {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom: function () {
  211. }
  212. })