index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/pay/index.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. id: 106,
  9. info: null,
  10. temps: [],
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. var that = this;
  17. console.log(options);
  18. this.setData({
  19. id: options.id
  20. })
  21. this.getTemps();
  22. this.getData();
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady() {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow() {
  33. var that = this;
  34. app.ajaxReadyCallback = res => { //各个接口统一回调方法
  35. var apiname = res.data.apiname;
  36. if(apiname == 'pay'){
  37. console.log(res.data.data);
  38. that.setData({
  39. info: res.data.data
  40. })
  41. }else if(apiname == 'temps'){
  42. if(res.data.data.temps.length > 0){
  43. that.setData({
  44. temps: res.data.data.temps
  45. });
  46. // wx.showModal({
  47. // title: '温馨提示',
  48. // content: res.data.data.tips,
  49. // confirmText: "同意",
  50. // cancelText: "拒绝",
  51. // complete: (res) => {
  52. // if (res.cancel) {
  53. // }
  54. // if (res.confirm) {
  55. // that.paySubscribe();
  56. // }
  57. // }
  58. // })
  59. }
  60. }
  61. };
  62. },
  63. paySubscribe(){
  64. let that = this;
  65. if(that.data.temps.length > 0){
  66. wx.requestSubscribeMessage({
  67. tmplIds: that.data.temps,
  68. success (res) {
  69. console.log('temp',res);
  70. },
  71. fail(res){
  72. console.log('fail',res);
  73. },
  74. complete(){
  75. that.pay();
  76. }
  77. });
  78. }
  79. },
  80. getData:function(){
  81. app.ajax({
  82. url: app.globalData.serverUrl + 'PhOrders/pay',
  83. type: 'POST',
  84. apiname: 'pay',
  85. data: {
  86. payId: this.data.id
  87. }
  88. });
  89. },
  90. getTemps:function(){
  91. app.ajax({
  92. url: app.globalData.serverUrl + 'PhOrders/temps',
  93. type: 'POST',
  94. apiname: 'temps',
  95. });
  96. },
  97. nopay(){
  98. let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
  99. wx.reLaunch({
  100. url: '/pages/webview/index?url='+url
  101. });
  102. },
  103. pay(){
  104. // let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
  105. // wx.navigateTo({
  106. // url: '/pages/webview/index?url='+url
  107. // });
  108. wx.requestPayment({
  109. timeStamp: this.data.info.timestamp,
  110. nonceStr: this.data.info.noncestr,
  111. package: this.data.info.package,
  112. signType: this.data.info.signtype,
  113. paySign: this.data.info.paysign,
  114. success (res) {
  115. let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
  116. wx.reLaunch({
  117. url: '/pages/webview/index?url='+url
  118. });
  119. },
  120. fail (res) {
  121. // wx.showToast({
  122. // title: '支付调用失败',
  123. // icon: 'none',
  124. // duration: 2000
  125. // })
  126. }
  127. })
  128. },
  129. /**
  130. * 生命周期函数--监听页面隐藏
  131. */
  132. onHide() {
  133. },
  134. /**
  135. * 生命周期函数--监听页面卸载
  136. */
  137. onUnload() {
  138. },
  139. /**
  140. * 页面相关事件处理函数--监听用户下拉动作
  141. */
  142. onPullDownRefresh() {
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom() {
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage() {
  153. }
  154. })