GroupConfirm.js 8.2 KB

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