confirmVOrder.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // pages/confirmVOrder.js
  2. const getReq = require('../../config.js').getReq
  3. import recordSource from '../../utils/recordSource';
  4. import Bundle from '../../utils/Bundle'
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. goods_id: '',
  12. ifcart: '0',
  13. num: '1',
  14. datas: {},
  15. goods_list: [],
  16. firstLoad: true,
  17. cart_id: '',
  18. n_goods_list: [],
  19. fromSource: '',
  20. available_pred: 0,
  21. room_bonus: 0,
  22. full_discount: 0,
  23. opgoods_discount: 0
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. // let goods_id = options.goods_id || ''
  30. // let iscart = options.iscart || ''
  31. // let num = options.num || ''
  32. // let cart_id = options.cart_id || ''
  33. let goods_id = '6217'
  34. let iscart = '0'
  35. let num = '1'
  36. let cart_id = ''
  37. this.setData({
  38. goods_id,
  39. ifcart: iscart,
  40. num,
  41. cart_id
  42. })
  43. this.getDatas(goods_id, iscart, num, cart_id)
  44. },
  45. getDatas(goods_id, ifcart, num, cart_id) {
  46. wx.showLoading({
  47. title: '加载中',
  48. })
  49. var self = this
  50. let goods_datas = '';
  51. if (ifcart == 0) {
  52. goods_datas = goods_id + '|' + num;
  53. }
  54. else {
  55. goods_datas = cart_id;
  56. }
  57. let fromSource = recordSource(app, `act=member_buy&op=step_first&curpage=1&cart_id=${goods_datas}&ifcart=${ifcart}&client_type=mini`)
  58. let params = {
  59. act: 'member_buy',
  60. op: 'step_first',
  61. curpage: 1,
  62. cart_id: goods_datas,
  63. ifcart,
  64. from: fromSource
  65. }
  66. // this.setData({
  67. // fromSource: app.globalData.fromSource
  68. // }),
  69. getReq(app,params, function (res) {
  70. wx.hideLoading()
  71. if (res.code == 200) {
  72. let datas = res.datas
  73. console.log(res.datas.toString())
  74. let { goods_list, summary, bundling, vpayinfo } = res.datas
  75. let { goods_amount,consignee } = vpayinfo
  76. let totalPrice = parseFloat(goods_amount + '0.0').toFixed(2)
  77. let n_goods_list = self.getNewGoodsList(goods_list, summary, bundling)
  78. self.setData({
  79. datas,
  80. n_goods_list,
  81. totalPrice,
  82. firstLoad: false,
  83. })
  84. }
  85. else {
  86. wx.showToast({
  87. icon: 'none',
  88. title: res.message,
  89. duration: 2000
  90. })
  91. app.globalData.fcodeErr = res.message
  92. wx.navigateBack()
  93. }
  94. })
  95. },
  96. toPay() {
  97. let goods_id = this.data.goods_id
  98. let goods_num = this.data.num
  99. let iscart = this.data.ifcart
  100. let cart_id = this.data.cart_id
  101. let ifcart = cart_id ? 1 : 0
  102. let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
  103. let params = {
  104. act: 'member_buy',
  105. op: 'step_vsecond',
  106. payment: 'minipay',
  107. usebonus: 1,
  108. ifcart,
  109. cart_id: cartids,
  110. invoice_id: 0
  111. }
  112. params = Object.assign({}, params);
  113. getReq(app,params, function (res) {
  114. wx.hideLoading()
  115. if (res.code == 200) {
  116. let param = res.datas.param.data
  117. let pay_sn = res.datas.pay_sn
  118. wx.requestPayment({
  119. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  120. nonceStr: param.nonceStr, //随机串
  121. package: param.package,
  122. signType: param.signType, //微信签名方式:
  123. paySign: param.paySign, //微信签名
  124. success: function (res) {
  125. wx.reLaunch({
  126. url: "/pages/index/index"
  127. })
  128. },
  129. fail: function (res) {
  130. wx.redirectTo({
  131. url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  132. })
  133. }
  134. });
  135. }
  136. else {
  137. wx.showToast({
  138. icon: 'none',
  139. title: res.message,
  140. duration: 2000
  141. })
  142. app.globalData.fcodeErr = res.message
  143. setTimeout(() => {
  144. wx.navigateBack()
  145. }, 2000);
  146. }
  147. })
  148. },
  149. getNewGoodsList(goods_list, summary, bundling) {
  150. let summaryMap = new Map()
  151. let bundlingMap = new Map()
  152. summary.map(item => {
  153. summaryMap.set(item['goods_id'], item)
  154. })
  155. if (bundling.length) {
  156. bundling.map(item => {
  157. bundlingMap.set(item['bl_id'], item)
  158. })
  159. }
  160. let n_goods_list = new Bundle(goods_list, summaryMap, bundlingMap).createOrders()
  161. return n_goods_list
  162. },
  163. /**
  164. * 生命周期函数--监听页面初次渲染完成
  165. */
  166. onReady: function () {
  167. },
  168. /**
  169. * 生命周期函数--监听页面显示
  170. */
  171. onShow: function () {
  172. // if (!this.data.firstLoad) {
  173. // app.setFromSource(this.data.fromSource)
  174. // let self = this
  175. // let defaultAddress = app.globalData.defaultAddress
  176. // if (!defaultAddress) return
  177. // let { city_id, area_id } = defaultAddress
  178. // let { freight_hash } = self.data
  179. // let params = {
  180. // act: 'member_buy',
  181. // op: 'change_addrex',
  182. // city_id,
  183. // area_id,
  184. // freight_hash
  185. // }
  186. // getReq(params, function(res) {
  187. // if (res.code == 200) {
  188. // let { freight } = res.datas
  189. // let prev_freight = self.data.freight
  190. // let totalPrice = parseFloat((self.data.totalPrice - prev_freight + freight).toFixed(2))
  191. // self.setData({
  192. // totalPrice
  193. // })
  194. // }
  195. // })
  196. // }
  197. },
  198. /**
  199. * 生命周期函数--监听页面隐藏
  200. */
  201. onHide: function () {
  202. },
  203. /**
  204. * 生命周期函数--监听页面卸载
  205. */
  206. onUnload: function () {
  207. },
  208. /**
  209. * 页面相关事件处理函数--监听用户下拉动作
  210. */
  211. onPullDownRefresh: function () {
  212. },
  213. /**
  214. * 页面上拉触底事件的处理函数
  215. */
  216. onReachBottom: function () {
  217. },
  218. /**
  219. * 用户点击右上角分享
  220. */
  221. onShareAppMessage: function () {
  222. }
  223. })