// pages/buy/buy.js import { goodsList } from '../../api/index' Page({ /** * 页面的初始数据 */ data: { activeIndex: -1, goodsList: [] }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getGoodsList() }, //获取套餐列表 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) this.setData({ activeIndex: index }) }, // 调用微信支付 handleWXPay () { var that = this wx.showLoading({ title: '支付中...', mask: true }) setTimeout(() => { wx.hideLoading({ success: () => { wx.showModal({ content: '支付成功,立即去预约', cancelColor: '#666', confirmText: '去预约', confirmColor: '#333', success (res) { if (res.confirm) { that.handleAppointment() } } }) } }) }, 1000); }, handleAppointment () { wx.navigateTo({ url: '/pages/appointment/appointment', }) } })