groupBuy.js 6.5 KB
  // pages/groupBuy/groupBuy.js
  const app = getApp()
  Page({

    /**
     * 页面的初始数据
     */
    data: {
      current: 0,
      chargenum: "2059788797",
      page: 0,
      groupList: [],
      recordList: [],
      pay_info: [],
      is_agree:false
    },

    //tab切换
    tabCharge(e) {
      var index = e.currentTarget.dataset.current
      var current = this.data.current
      if (index == current) {
        return false
      } else {
        this.setData({
          current: index
        })
      }
    },
    //同意协议按钮
    agree() {
      this.setData({
        is_agree: !this.data.is_agree
      })
    },
    //服务协议
    serviceProtocol() {
      wx.navigateTo({
        url: '../protocol/protocol',
      })
    },

    //查看详情
    listDetail(e) {
      var id = e.currentTarget.dataset.id
      wx.setStorageSync('id', id)
      wx.navigateTo({
        url: '../groupBuyDetail/groupBuyDetail?id=' + id,
      })
    },

    //畅玩卡介绍
    cardInfo() {
      wx.navigateTo({
        url: '/pages/my/cardIntroduction/cardIntroduction',
      })
    },


    // 长按复制
    copy: function(e) {
      var that = this;
      wx.setClipboardData({
        data: that.data.chargenum,
        success: function(res) {
          wx.showToast({
            title: '复制成功',
          });
        }
      });
    },

    //参与的组团
    takeGroup() {
      let url = '/portal/Group/group_list'
      let params = {
        page: this.data.page
      }
      let header = {
        "XX-Token": wx.getStorageSync('token')
      }
      app.post(url, params, header).then((res) => {
        console.log(res)
        this.setData({
          groupList: res.list
        })
      })
    },

    //成交记录
    record() {
      let url = '/portal/Group/group_complete'
      let params = {
        page: this.data.page
      }
      let header = {
        "XX-Token": wx.getStorageSync('token')
      }
      app.post(url, params, header).then((res) => {
        console.log(res)
        this.setData({
          recordList: res.list
        })
      })
    },

    //发起团购
    goPay() {
      let url = '/portal/Group/group_create'
      let params = {}
      let header = {
        "XX-Token": wx.getStorageSync('token')
      }
      app.post(url, params, header).then((res) => {
        this.setData({
          group_info: res.pay
        })
        this.wxPay(res.pay)
      })
    },
    //团购配置人数价格
    PayDetail() {
      let url = '/portal/Group/group_option'
      let params = {}
      let header = {
        "XX-Token": wx.getStorageSync('token')
      }
      app.post(url, params, header).then((res) => {
        console.log(res)
        this.setData({
          pay_info: res.info
        })
      })
    },
      //团购规则
      getRule() {
          let url = '/wxapp/public/arc_group'
          let params = {}
          let header = {
              "XX-Token": wx.getStorageSync('token')
          }
          app.post(url, {}, {}).then((res) => {
              console.log('团购规则',res)
              this.setData({
                  rule: res
              })
          })
      },
    //发起团购支付
    wxPay(data) {
        const self = this;
      if (self.data.is_agree){
        wx.requestPayment({
          'timeStamp': data.timeStamp,
          'nonceStr': data.nonceStr,
          'package': data.package,
          'signType': 'MD5',
          'paySign': data.paySign,
          'success': function (res) {
            console.log(res)
            wx.showToast({
              title: '支付成功',
              icon: 'success',
              success: function () {
                setTimeout(function () {
                    const params = {
                        rule: self.data.rule,
                        pay_info: self.data.pay_info,
                    }
                  wx.navigateTo({
                    url: '/pages/my/shareGroupBuy/shareGroupBuy?params=' + JSON.stringify(params),
                  })
                }, 500)
              }
            });
          },
          'fail': function (res) { }
        })
      }else{
        wx.showToast({
          title: '请同意服务协议',
          icon:'none'
        })
      }


    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
      this.takeGroup()
      this.record()
      this.PayDetail()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
      let that = this;
      // 设置菜单中的转发按钮触发转发事件时的转发内容
      var shareObj = {
        title: '科学队长', // 默认是小程序的名称(可以写slogan等)
        path: '/pages/eyeTest/articleDetail/articleDetail?doctorid=' + app.globalData.doctorid + '&id=' + this.data.id, // 默认是当前页面,必须是以‘/’开头的完整路径
        imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
        success: function(res) {
          if (res.errMsg == 'shareAppMessage:ok') {}
        },
        fail: function() {
          // 转发失败之后的回调
          if (res.errMsg == 'shareAppMessage:fail cancel') {
            // 用户取消转发
          } else if (res.errMsg == 'shareAppMessage:fail') {
            // 转发失败,其中 detail message 为详细失败信息
          }
        },
        complete: function() {
          // 转发结束之后的回调(转发成不成功都会执行)
        }
      }  

      // 来自页面内的按钮的转发
      // if (option.from == 'button') {
      //   // 此处可以修改 shareObj 中的内容
      //   // shareObj.imageUrl = '/pages/shareimg/share.png'
      // }   // 返回shareObj

      return shareObj;
    }
  })