123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // pages/buy/buy.js
- import { goodsList } from '../../api/index'
- import { submitOrder } from '../../api/pay'
- import itt from '../../utils/util'
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- activeIndex: -1,
- goodsList: [],
- goodsId: '',
- orderAmount: '',
- num: '',
- appusername: '',
- appuserheadimg: ''
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.getGoodsList()
- this.setData({
- appusername: app.globalData.userInfo.userName.length > 4 ? app.globalData.userInfo.userName.substring(0,4) : app.globalData.userInfo.userName,
- appuserheadimg: app.globalData.userInfo.headImg
- })
- },
- //获取套餐列表
- getGoodsList () {
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- goodsList({}).then(res => {
- wx.hideLoading()
- var response = res.data
- response.map((item, index) => {
- if (item.isRecommend) {
- this.setData({
- activeIndex: index
- })
- }
- })
- this.setData({
- goodsList: response
- })
- }).catch(e => {
- wx.hideLoading()
- wx.showModal({
- content: e,
- confirmColor: '#333',
- showCancel: false
- })
- })
- },
- handlePayType (e) {
- var index = Number(e.currentTarget.dataset.index)
- var goodsInfo = e.currentTarget.dataset.goodsinfo
- console.log(goodsInfo, 'goodsInfo');
- this.setData({
- activeIndex: index,
- goodsId: goodsInfo.goodsId,
- orderAmount: goodsInfo.salePrice,
- num: goodsInfo.donateNumber + goodsInfo.useNumber
- })
- },
- // 调用微信支付
- handleWXPay () {
- var data = {
- goodsId: this.data.goodsId,
- orderAmount: this.data.orderAmount,
- num: this.data.num
- }
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- submitOrder(data).then(res => {
- wx.hideLoading()
- // 拉起微信支付
- wx.requestPayment({
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.packageStr,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success (res) {
- wx.showToast({
- title: '支付成功',
- icon: 'success'
- })
- },
- fail (res) {
- console.log('weixin pay fail', res);
- }
- })
- }).catch(e => {
- wx.hideLoading()
- wx.showModal({
- content: e,
- confirmColor: '#333',
- showCancel: false
- })
- })
- },
- handleAppointment () {
- wx.navigateTo({
- url: '/pages/appointment/appointment',
- })
- }
- })
|