GroupConfirm.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. // subPackagesB/pages/GroupConfirm/GroupConfirm.js
  2. import {
  3. get,
  4. post
  5. } from '../../../utils/http'
  6. var timer;
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. store_name: '', //店铺名称
  13. goodsDetailsList: '', //美妆产品详情
  14. cardDetailList: '', //次卡产品详情
  15. source: '', //产品类型
  16. store_id: '', //店铺ID
  17. goods_id: '', //美妆产品ID
  18. payNow: false, //控制提交订单弹出框
  19. inserllAmount: '', // 我的储值
  20. pay_methon: 1, //支付方式 1微信2储值
  21. orderId: '', //订单ID
  22. groupPrice: '', //拼团价格
  23. isGrouping: '', //是否是拼团购买
  24. original_price: '', //原价
  25. groupID: '', //拼团活动ID
  26. isSuccess: '', //是否是去拼团进入
  27. grouping_id: '', //拼团记录ID
  28. isCheckOrder: true, //判断支付后是否成功
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad(options) {
  34. // 禁用分享
  35. wx.hideShareMenu()
  36. // 获取美妆产品Id&&产品类型&&店铺ID
  37. console.log(options);
  38. let isSuccess = false
  39. if (options.isSuccess) {
  40. isSuccess = true
  41. }
  42. this.setData({
  43. goods_id: options.productId,
  44. source: options.source,
  45. store_id: options.store_id || wx.getStorageSync('store_id'),
  46. groupPrice: options.groupPrice,
  47. isGrouping: JSON.parse(options.isGrouping),
  48. original_price: options.original_price,
  49. groupID: options.groupID,
  50. isSuccess,
  51. grouping_id: options.grouping_id
  52. })
  53. if (options.source == 'goods') {
  54. // 获取美妆产品详情
  55. this.getGoodsDetail()
  56. } else {
  57. // 获取次卡详情
  58. this.getCardDetail()
  59. }
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady() {
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow() {
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide() {
  75. clearTimeout(timer)
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload() {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh() {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom() {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage() {
  96. },
  97. // 获取美妆产品详情
  98. getGoodsDetail() {
  99. let params = {
  100. goods_ids: this.data.goods_id,
  101. store_id: this.data.store_id,
  102. type: 2
  103. }
  104. post('v2/api/goods_order/confirm', params, (res) => {
  105. if (res.code == 200) {
  106. console.log(res);
  107. this.setData({
  108. store_name: res.data.store_name,
  109. goodsDetailsList: res.data.list
  110. })
  111. }
  112. })
  113. },
  114. // 获取次卡详情
  115. getCardDetail() {
  116. get('v2/api/card/info', {
  117. id: this.data.goods_id,
  118. store_id: this.data.store_id || wx.getStorageSync('store_id')
  119. }, (res) => {
  120. this.setData({
  121. cardDetailList: res.data
  122. })
  123. })
  124. },
  125. // 单独购买提交订单
  126. onCardgoodsPay() {
  127. // 判断是美妆还是次卡下单
  128. let url = this.data.source == 'goods' ? 'v2/api/car/closing' : 'v2/api/order/card/add'
  129. let params = this.data.source == 'goods' ? {
  130. goods_ids: this.data.goods_id,
  131. store_id: this.data.store_id || wx.getStorageSync('store_id'),
  132. type: 2,
  133. } : {
  134. store_id: this.data.store_id || wx.getStorageSync('store_id'),
  135. id: this.data.goods_id,
  136. group_type: 1,
  137. group: '',
  138. }
  139. post(url, params, res => {
  140. if (res.code == 200) {
  141. if (res.data.pay_status == 1) {
  142. wx.showToast({
  143. title: '支付成功',
  144. icon: 'success'
  145. })
  146. // 只有项目购买,需要订阅消息
  147. wx.reLaunch({
  148. url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${res.data.order_id}`
  149. })
  150. } else {
  151. this.setData({
  152. payNow: true,
  153. orderId: res.data.order_id
  154. })
  155. this.getAmount()
  156. }
  157. }
  158. })
  159. },
  160. // 拼团购买提交订单
  161. onNewPay() {
  162. post('v2/api/grouping/buy', {
  163. id: this.data.groupID,
  164. store_id: this.data.store_id,
  165. grouping_id: this.data.grouping_id || ''
  166. }, res => {
  167. this.setData({
  168. payNow: true,
  169. orderId: res.data.order_id
  170. })
  171. this.getAmount()
  172. })
  173. },
  174. // 获取拼团记录ID
  175. getGroupRecordID(order_id, goods_type) {
  176. get('v2/api/grouping/get_grouping_id', {
  177. order_id,
  178. goods_type
  179. }, (res) => {
  180. if (res.data.grouping_id != '') {
  181. this.setData({
  182. isCheckOrder: false
  183. })
  184. }
  185. // 判断是否是去拼团 进入购买 是就跳转到拼团成功页面
  186. if (this.data.isCheckOrder) {
  187. return
  188. }
  189. if (this.data.isSuccess) {
  190. // 拼团成功返回首页
  191. wx.reLaunch({
  192. url: `/subPackagesB/pages/groupOrder/groupOrder?groupStatus=1&&userGroupId=${this.data.grouping_id}`
  193. })
  194. } else {
  195. wx.reLaunch({
  196. url: `/subPackagesB/pages/successOrder/successOrder?goods_id=${this.data.goods_id}&&original_price=${this.data.original_price}&&source=${this.data.source}&&grouping_id=${res.data.grouping_id}&&groupID=${this.data.groupID}`
  197. })
  198. }
  199. })
  200. },
  201. /**
  202. * 订单支付
  203. */
  204. payOrder() {
  205. let that = this
  206. let url = this.data.source == 'goods' ? 'v2/api/order/goods/pay' : 'v2/api/order/card/pay'
  207. post(
  208. url, {
  209. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  210. order_id: this.data.orderId
  211. },
  212. (res) => {
  213. that.setData({
  214. payNow: false
  215. })
  216. if (that.data.pay_methon == 2) {
  217. that.goToOrder('支付成功')
  218. return
  219. }
  220. wx.requestPayment({
  221. timeStamp: res.data.pay_data.timeStamp,
  222. nonceStr: res.data.pay_data.nonceStr,
  223. package: res.data.pay_data.package,
  224. signType: res.data.pay_data.signType,
  225. paySign: res.data.pay_data.paySign,
  226. success(res) {
  227. if (res.errMsg == 'requestPayment:ok') {
  228. that.goToOrder('支付成功')
  229. }
  230. },
  231. fail(res) {
  232. that.goToOrder('支付失败')
  233. }
  234. })
  235. }
  236. )
  237. },
  238. // 判断是否完成订单支付
  239. checkOrder() {
  240. timer = setTimeout(res => {
  241. if (!this.data.isCheckOrder) {
  242. clearTimeout(timer)
  243. return
  244. }
  245. this.getGroupRecordID(this.data.orderId, this.data.source == 'goods' ? 1 : 2)
  246. this.checkOrder()
  247. }, 1000)
  248. },
  249. /**
  250. * 跳转订单列表
  251. */
  252. goToOrder(text) {
  253. let that = this
  254. wx.showToast({
  255. title: text,
  256. icon: text == '支付成功' ? 'success' : 'error'
  257. })
  258. if (text == '支付成功') {
  259. // 只有项目购买,需要订阅消息
  260. if (this.data.isGrouping) {
  261. this.checkOrder()
  262. } else {
  263. wx.reLaunch({
  264. url: `/pages/paySuccess/paySuccess?current=1&source=${this.data.source}&order_id=${that.data.orderId}`
  265. })
  266. }
  267. return
  268. } else if(this.data.isGrouping){
  269. setTimeout(() => {
  270. wx.reLaunch({
  271. url: '/subPackagesB/pages/joinGroup/joinGroup'
  272. })
  273. }, 1000)
  274. }else if(!this.data.isGrouping&&this.data.source=='secondaryCard'){
  275. setTimeout(() => {
  276. wx.reLaunch({
  277. url: '/subPackagesB/pages/joinGroup/joinGroup'
  278. })
  279. }, 1000)
  280. }else{
  281. let failUrl = `/pages/goods/orderList/orderList?current=0`
  282. setTimeout(() => {
  283. wx.reLaunch({
  284. url: failUrl
  285. })
  286. }, 1000)
  287. }
  288. },
  289. // 关闭提交订单框
  290. onClosePay() {
  291. this.setData({
  292. payNow: false
  293. })
  294. },
  295. // 选择微信支付
  296. pay_methonw() {
  297. this.setData({
  298. pay_methon: 1
  299. })
  300. },
  301. // 选择储值支付
  302. pay_methonc() {
  303. this.setData({
  304. pay_methon: 2
  305. })
  306. },
  307. /**
  308. * 获取我的储值
  309. * api/user
  310. */
  311. getAmount() {
  312. get('api/user/amount', {}, (res) => {
  313. if (res.data) {
  314. this.setData({
  315. inserllAmount: res.data.amount
  316. })
  317. }
  318. })
  319. },
  320. })