123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- // pages/add/add.js
- const app = getApp()
- const cell = [0, 288, 100, 1000, 10000]
- var lock = require('../../utils/lock.js')
- var net = require('../../utils/net.js')
- var url = require('../../utils/url.js')
- var common = require('../../utils/common.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- getPhoneCell: '200万',
- canPay: true,
- canNotPay: '',
- options: [],
- selected: '',
- contact: {
- sessionFrom: ''
- }
- },
- buyAction: function () {
- // app.log(this.data.selected)
- wx.showLoading({
- title: '正在打赏',
- })
- this.getOrder({
- url: url.host + url.recharge,
- data: {
- cellProductId: this.data.selected
- },
- success: res => {
- wx.hideLoading()
- // app.globalData.user.cell += cell[Number(this.data.selected)]
- var len = this.data.options.length || 0
- for (var i = 0; i < len; i++) {
- if (this.data.options[i].cellProductId == this.data.selected) {
- var title = '+' + common.unit(this.data.options[i].cell)
- if (this.data.options[i].type == 1) {
- this.data.options.splice(i, 1)
- this.data.options[0].selected = true
- var selected = this.data.options[0].cellProductId || 0
- this.setData({
- selected: selected,
- options: this.data.options
- })
- }
- break
- }
- }
-
- wx.showToast({
- duration: 2000,
- icon: 'none',
- title: title
- })
- }
- })
- },
- //获取订单接口
- getOrder: function (obj) {
- net.connect({
- url: obj.url,
- data: obj.data,
- method: 'POST',
- success: res => {
- this.order(obj, res.data.data)
- }
- })
- },
- //微信支付统一调用接口
- order: function (obj, order) {
- if (app.globalData.debug) {
- net.connect({
- url: url.host + url.testPay,
- data: { out_trade_no: order },
- success: res => {
- obj.success(res)
- }
- })
- return
- }
- net.connect({
- url: url.host + url.unified,
- data: { out_trade_no: order },
- method: 'POST',
- success: res => {
- this.pay(obj, order, res.data.data)
- }
- })
- },
- //微信支付
- pay: function (obj, no, order) {
- wx.requestPayment({
- timeStamp: order.timeStamp,
- nonceStr: order.nonceStr,
- package: order.package,
- signType: 'MD5',
- paySign: order.paySign,
- success: res => {
- obj.success(res)
- },
- fail: e => {
- wx.hideLoading()
- wx.showModal({
- title: '',
- content: '支付失败',
- })
- }
- })
- },
- selectAction: function (o) {
- app.log(o.currentTarget.id)
- var id = o.currentTarget.id
- var len = this.data.options.length || 0
- for (var i = 0; i < len; i++) {
- if (this.data.options[i].cellProductId == id) {
- var selected = id
- this.data.options[i].selected = true
- } else {
- this.data.options[i].selected = false
- }
- }
- this.setData({
- options: this.data.options,
- selected: selected
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.log(app.globalData.user)
- var options = app.globalData.user.cellProductList
- var len = options.length || 0
- for (var i = 0; i < len; i++) {
- if (i == 0) {
- options[i].selected = true
- } else {
- options[i].selected = false
- }
- }
- var selected = options[0].cellProductId || 0
- if (app.server.config.cellBindPhone) {
- this.data.getPhoneCell = common.unit(app.server.config.cellBindPhone)
- }
- if (app.server.messageRuleMap.buy && app.server.messageRuleMap.buy.sessionFrom) {
- this.data.contact = common.messageRuleMapToObject(app.server.messageRuleMap.buy)
- }
- this.setData({
- contact: this.data.contact,
- getPhoneCell: this.data.getPhoneCell,
- canPay: !app.globalData.isIOS,
- canNotPay: app.server.config.noSupportPayMsg,
- options: options,
- selected: selected
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- // onShareAppMessage: function () {
- // }
- })
|