123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- // subPackagesB/pages/GroupConfirm/GroupConfirm.js
- import {
- get,
- post
- } from '../../../utils/http'
- var timer;
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- storeName: '', //店铺名称
- seckillDetail: '', //美妆产品详情
- store_id: '', //店铺ID
- goods_id: '', //美妆产品ID
- payNow: false, //控制提交订单弹出框
- inserllAmount: '', // 我的储值
- pay_methon: 1, //支付方式 1微信2储值
- orderId: '', //订单ID
- seckill_id:"",//秒杀ID
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 禁用分享
- wx.hideShareMenu()
- this.setData({
- goods_id: options.goods_id,
- store_id: options.store_id || wx.getStorageSync('store_id'),
- seckill_id:options.seckill_id
- })
- // 获取我的储值
- this.getAmount()
- // 获取秒杀产品详情
- this.getSeckillDetail()
- // 获取店铺信息
- this.getStoreInfo()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- // 获取秒杀商品详情
- getSeckillDetail() {
- get('v2/api/spike/info', {
- id: this.data.goods_id,
- seckill_id:this.data.seckill_id
- }, (res => {
- if (res.code == 200) {
- this.setData({
- seckillDetail: res.data
- })
- }
- }))
- },
- // 获取店铺信息
- getStoreInfo() {
- get('api/store/info', {
- store_id: this.data.store_id
- }, (res => {
- if (res.code == 200) {
- this.setData({
- storeName: res.data.store_name
- })
- }
- }))
- },
- // 提交订单
- ongoodsPay() {
- let params = {
- goods_id: this.data.goods_id.toString(),
- store_id: this.data.store_id.toString(),
- seckill_id: this.data.seckillDetail.seckill_id.toString()
- }
- post('v2/api/spike/buy', params, res => {
- if (res.code == 200) {
- if (res.data.pay_status == 1) {
- wx.showToast({
- title: '支付成功',
- icon: 'success'
- })
- // 只有项目购买,需要订阅消息
- wx.reLaunch({
- url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${res.data.order_id}`
- })
- } else {
- this.setData({
- payNow: true,
- orderId: res.data.order_id
- })
- }
- }
- })
- },
- /**
- * 订单支付
- */
- payOrder() {
- let that = this
- let url = 'v2/api/order/goods/pay'
- post(
- url, {
- pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
- order_id: this.data.orderId
- },
- (res) => {
- that.setData({
- payNow: false
- })
- if (that.data.pay_methon == 2) {
- that.goToOrder('支付成功')
- return
- }
- wx.requestPayment({
- timeStamp: res.data.pay_data.timeStamp,
- nonceStr: res.data.pay_data.nonceStr,
- package: res.data.pay_data.package,
- signType: res.data.pay_data.signType,
- paySign: res.data.pay_data.paySign,
- success(res) {
- if (res.errMsg == 'requestPayment:ok') {
- that.goToOrder('支付成功')
- }
- },
- fail(res) {
- that.goToOrder('支付失败')
- }
- })
- }
- )
- },
- /**
- * 跳转订单列表
- */
- goToOrder(text) {
- let that = this
- wx.showToast({
- title: text,
- icon: text == '支付成功' ? 'success' : 'error'
- })
- if (text == '支付成功') {
- // 只有项目购买,需要订阅消息
- if (this.data.isGrouping) {
- this.checkOrder()
- } else {
- wx.reLaunch({
- url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${that.data.orderId}`
- })
- }
- return
- } else {
- let failUrl = `/pages/goods/orderList/orderList?current=0`
- setTimeout(() => {
- wx.reLaunch({
- url: failUrl
- })
- }, 1000)
- }
- },
- // 关闭提交订单框
- onClosePay() {
- this.setData({
- payNow: false
- })
- },
- // 选择微信支付
- pay_methonw() {
- this.setData({
- pay_methon: 1
- })
- },
- // 选择储值支付
- pay_methonc() {
- this.setData({
- pay_methon: 2
- })
- },
- /**
- * 获取我的储值
- * api/user
- */
- getAmount() {
- get('api/user/amount', {}, (res) => {
- if (res.data) {
- this.setData({
- inserllAmount: res.data.amount
- })
- }
- })
- },
- })
|