confirmOrder.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // pages/confirmOrder/confirmOrder.js
  2. const getReq = require('./../../config.js').getReq
  3. import Bundle from '../../utils/Bundle'
  4. let appInstance = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. goods_id: '',
  11. ifcart: '',
  12. num: '',
  13. datas: {},
  14. goods_list: [],
  15. firstLoad: true,
  16. defaultAddress: null,
  17. cart_id: '',
  18. n_goods_list: [],
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. let goods_id = options.goods_id || ''
  25. let iscart = options.iscart || ''
  26. let num = options.num || ''
  27. let cart_id = options.cart_id || ''
  28. this.setData({
  29. goods_id,
  30. ifcart: iscart,
  31. num,
  32. cart_id
  33. })
  34. this.getDatas(goods_id, iscart, num, cart_id)
  35. // 测试套装数据
  36. // this.getDatas(goods_id, 1, num, '16403,16406')
  37. // act:member_buy
  38. // cart_id:16403,16406
  39. // op:step_first
  40. // from:YWN0PWNhcnQmb3A9ZXhnb29kcyZjdXJwYWdlPTE%3D
  41. // ifcart:1
  42. },
  43. getDatas(goods_id, ifcart, num, cart_id) {
  44. wx.showLoading({
  45. title: '加载中',
  46. })
  47. var self = this
  48. let goods_datas = '';
  49. if (ifcart == 0) {
  50. goods_datas = goods_id + '|' + num;
  51. }
  52. else {
  53. goods_datas = cart_id;
  54. }
  55. // let bundleParams = {
  56. // act: 'member_buy',
  57. // op: 'step_first',
  58. // cart_id: '16407,16408',
  59. // ifcart: 1
  60. // }
  61. // let defaultParams = {
  62. // act: 'member_buy',
  63. // cart_id: '4807|1',
  64. // op: 'step_first',
  65. // ifcart: 0
  66. // }
  67. let params = {
  68. act: 'member_buy',
  69. op: 'step_first',
  70. curpage: 1,
  71. cart_id: goods_datas,
  72. ifcart,
  73. }
  74. getReq(params, function (res) {
  75. wx.hideLoading()
  76. if (res.code == 200) {
  77. let datas = res.datas
  78. console.log('datas:', datas);
  79. let { goods_list, summary, bundling } = res.datas
  80. let n_goods_list = self.getNewGoodsList(goods_list, summary, bundling)
  81. if (datas.address) {
  82. let { true_name, mob_phone, area_info, address, address_id } = datas.address;
  83. appInstance.checkDefaultAddress({
  84. true_name,
  85. mob_phone,
  86. area_info,
  87. address,
  88. address_id
  89. })
  90. }
  91. self.setData({
  92. datas,
  93. n_goods_list,
  94. firstLoad: false,
  95. defaultAddress: datas.address
  96. })
  97. }
  98. else {
  99. wx.showToast({
  100. icon: 'none',
  101. title: res.message,
  102. duration: 2000
  103. })
  104. appInstance.globalData.fcodeErr = res.message
  105. wx.navigateBack()
  106. }
  107. })
  108. },
  109. // getGoodsList(summary, goods_list) {
  110. // console.log('summary', summary);
  111. // console.log('goods_list', goods_list);
  112. // let newGoodsList = []
  113. // goods_list.map((item, index) => {
  114. // summary.find((list, key) => {
  115. // if (item.goods_id == list.goods_id) {
  116. // let goods_item = list
  117. // goods_item.goods_num = item.goods_num
  118. // newGoodsList.push(goods_item)
  119. // return true
  120. // }
  121. // })
  122. // })
  123. // return newGoodsList
  124. // },
  125. toPay() {
  126. if (!this.data.defaultAddress) {
  127. wx.showToast({
  128. icon: 'none',
  129. title: '请填写收货地址',
  130. duration: 1500
  131. })
  132. return
  133. }
  134. let goods_id = this.data.goods_id
  135. let goods_num = this.data.num
  136. let iscart = this.data.ifcart
  137. let cart_id = this.data.cart_id
  138. let vat_hash = this.data.datas['payinfo'].vat_hash
  139. let offpay_hash = this.data.datas['payinfo'].offpay_hash
  140. let offpay_hash_batch = this.data.datas['payinfo'].offpay_hash_batch
  141. let address_id = this.data.defaultAddress.address_id ? this.data.defaultAddress.address_id : this.data.datas['address'].address_id
  142. let ifcart = cart_id ? 1 : 0
  143. let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
  144. getReq({
  145. act: 'member_buy',
  146. op: 'step_second',
  147. // payment: 'jspay',
  148. payment: 'minipay',
  149. usebonus: 1,
  150. ifcart,
  151. cart_id: cartids,
  152. address_id,
  153. invoice_id: 0,
  154. vat_hash,
  155. offpay_hash,
  156. offpay_hash_batch
  157. }, function (res) {
  158. wx.hideLoading()
  159. if (res.code == 200) {
  160. let param = res.datas.param.data
  161. let pay_sn = res.datas.pay_sn
  162. console.log(res);
  163. wx.requestPayment({
  164. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  165. nonceStr: param.nonceStr, //随机串
  166. package: param.package,
  167. signType: param.signType, //微信签名方式:
  168. paySign: param.paySign, //微信签名
  169. success: function (res) {
  170. wx.reLaunch({
  171. url: "/pages/index/index"
  172. })
  173. },
  174. fail: function (res) {
  175. wx.redirectTo({
  176. url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  177. })
  178. }
  179. });
  180. }
  181. else {
  182. wx.showToast({
  183. icon: 'none',
  184. title: res.message,
  185. duration: 2000
  186. })
  187. appInstance.globalData.fcodeErr = res.message
  188. wx.navigateBack()
  189. }
  190. })
  191. },
  192. getNewGoodsList(goods_list, summary, bundling) {
  193. let summaryMap = new Map()
  194. let bundlingMap = new Map()
  195. summary.map(item => {
  196. summaryMap.set(item['goods_id'], item)
  197. })
  198. if (bundling.length) {
  199. bundling.map(item => {
  200. bundlingMap.set(item['bl_id'], item)
  201. })
  202. }
  203. let n_goods_list = new Bundle(goods_list, summaryMap, bundlingMap).createOrders()
  204. return n_goods_list
  205. },
  206. // testBundle() {
  207. // let bundleParams = {
  208. // act: 'member_buy',
  209. // op: 'step_first',
  210. // cart_id: '16407,16408',
  211. // ifcart: 1
  212. // }
  213. // let defaultParams = {
  214. // act: 'member_buy',
  215. // cart_id: '4807|1',
  216. // op: 'step_first',
  217. // ifcart: 0
  218. // }
  219. // let self = this
  220. // getReq(bundleParams, function (res) {
  221. // console.log('Bundle', res);
  222. // if (res.code == 200) {
  223. // let { goods_list, summary, bundling } = res.datas
  224. // let summaryMap = new Map()
  225. // let bundlingMap = new Map()
  226. // summary.map(item => {
  227. // summaryMap.set(item['goods_id'], item)
  228. // })
  229. // if (bundling.length) {
  230. // bundling.map(item => {
  231. // bundlingMap.set(item['bl_id'], item)
  232. // })
  233. // }
  234. // let n_goods_list = new Bundle(goods_list, summaryMap, bundlingMap).createOrders()
  235. // console.log('n_goods_list: ', n_goods_list);
  236. // self.setData({
  237. // n_goods_list
  238. // })
  239. // }
  240. // })
  241. // },
  242. /**
  243. * 生命周期函数--监听页面初次渲染完成
  244. */
  245. onReady: function () {
  246. },
  247. /**
  248. * 生命周期函数--监听页面显示
  249. */
  250. onShow: function () {
  251. if (!this.data.firstLoad) {
  252. let defaultAddress = appInstance.globalData.defaultAddress
  253. this.setData({
  254. defaultAddress
  255. })
  256. }
  257. },
  258. /**
  259. * 生命周期函数--监听页面隐藏
  260. */
  261. onHide: function () {
  262. },
  263. /**
  264. * 生命周期函数--监听页面卸载
  265. */
  266. onUnload: function () {
  267. },
  268. /**
  269. * 页面相关事件处理函数--监听用户下拉动作
  270. */
  271. onPullDownRefresh: function () {
  272. },
  273. /**
  274. * 页面上拉触底事件的处理函数
  275. */
  276. onReachBottom: function () {
  277. }
  278. })