buy.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // pages/buy/buy.js
  2. import { goodsList } from '../../api/index'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. activeIndex: -1,
  9. goodsList: []
  10. },
  11. /**
  12. * 生命周期函数--监听页面显示
  13. */
  14. onShow() {
  15. this.getGoodsList()
  16. },
  17. //获取套餐列表
  18. getGoodsList () {
  19. wx.showLoading({
  20. title: '加载中...',
  21. mask: true
  22. })
  23. goodsList({}).then(res => {
  24. wx.hideLoading()
  25. var response = res.data
  26. response.map((item, index) => {
  27. if (item.isRecommend) {
  28. this.setData({
  29. activeIndex: index
  30. })
  31. }
  32. })
  33. this.setData({
  34. goodsList: response
  35. })
  36. }).catch(e => {
  37. wx.hideLoading()
  38. wx.showModal({
  39. content: e,
  40. confirmColor: '#333',
  41. showCancel: false
  42. })
  43. })
  44. },
  45. handlePayType (e) {
  46. var index = Number(e.currentTarget.dataset.index)
  47. this.setData({
  48. activeIndex: index
  49. })
  50. },
  51. // 调用微信支付
  52. handleWXPay () {
  53. var that = this
  54. wx.showLoading({
  55. title: '支付中...',
  56. mask: true
  57. })
  58. setTimeout(() => {
  59. wx.hideLoading({
  60. success: () => {
  61. wx.showModal({
  62. content: '支付成功,立即去预约',
  63. cancelColor: '#666',
  64. confirmText: '去预约',
  65. confirmColor: '#333',
  66. success (res) {
  67. if (res.confirm) {
  68. that.handleAppointment()
  69. }
  70. }
  71. })
  72. }
  73. })
  74. }, 1000);
  75. },
  76. handleAppointment () {
  77. wx.navigateTo({
  78. url: '/pages/appointment/appointment',
  79. })
  80. }
  81. })