123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // pages/pay/index.js
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- id: 106,
- info: null,
- temps: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- var that = this;
- console.log(options);
- this.setData({
- id: options.id
- })
- this.getTemps();
- this.getData();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- var that = this;
- app.ajaxReadyCallback = res => { //各个接口统一回调方法
- var apiname = res.data.apiname;
- if(apiname == 'pay'){
- console.log(res.data.data);
- that.setData({
- info: res.data.data
- })
- }else if(apiname == 'temps'){
- if(res.data.data.temps.length > 0){
- that.setData({
- temps: res.data.data.temps
- });
- wx.showModal({
- title: '温馨提示',
- content: res.data.data.tips,
- confirmText: "同意",
- cancelText: "拒绝",
- complete: (res) => {
- if (res.cancel) {
-
- }
-
- if (res.confirm) {
- that.paySubscribe();
- }
- }
- })
- }
-
- }
- };
-
-
- },
- paySubscribe(){
- let that = this;
- if(that.data.temps.length > 0){
- wx.requestSubscribeMessage({
- tmplIds: that.data.temps,
- success (res) {
- console.log('temp',res);
- },
- fail(res){
- console.log('fail',res);
- },
- complete(){
- // that.pay();
- }
- });
- }
- },
- getData:function(){
- app.ajax({
- url: app.globalData.serverUrl + 'PhOrders/pay',
- type: 'POST',
- apiname: 'pay',
- data: {
- payId: this.data.id
- }
- });
- },
- getTemps:function(){
- app.ajax({
- url: app.globalData.serverUrl + 'PhOrders/temps',
- type: 'POST',
- apiname: 'temps',
- });
- },
- pay(){
- // let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
- // wx.navigateTo({
- // url: '/pages/webview/index?url='+url
- // });
- wx.requestPayment({
- timeStamp: this.data.info.timestamp,
- nonceStr: this.data.info.noncestr,
- package: this.data.info.package,
- signType: this.data.info.signtype,
- paySign: this.data.info.paysign,
- success (res) {
- let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
- wx.navigateTo({
- url: '/pages/webview/index?url='+url
- });
- },
- fail (res) {
- wx.showToast({
- title: '支付调用失败',
- icon: 'none',
- duration: 2000
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|