index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. pay(){
  98. // let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
  99. // wx.navigateTo({
  100. // url: '/pages/webview/index?url='+url
  101. // });
  102. wx.requestPayment({
  103. timeStamp: this.data.info.timestamp,
  104. nonceStr: this.data.info.noncestr,
  105. package: this.data.info.package,
  106. signType: this.data.info.signtype,
  107. paySign: this.data.info.paysign,
  108. success (res) {
  109. let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
  110. wx.navigateTo({
  111. url: '/pages/webview/index?url='+url
  112. });
  113. },
  114. fail (res) {
  115. wx.showToast({
  116. title: '支付调用失败',
  117. icon: 'none',
  118. duration: 2000
  119. })
  120. }
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload() {
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh() {
  137. },
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom() {
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage() {
  147. }
  148. })