You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
6.0 KiB

  1. const config = require('../../../config/config.js')
  2. const util = require('../../../utils/util.js')
  3. const Http = require('../../../utils/http.js')
  4. const Common = require('../../../common/common.js')
  5. const qrCodeJS = require('../../../utils/qrcode.js')
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. billTypeValue: "",
  13. billId: "",
  14. disabled: true,
  15. detailData: {},
  16. tempFilePath: '',
  17. codeShow: false
  18. },
  19. qrcode(url) {
  20. let that = this;
  21. qrCodeJS.qrApi.draw(url, 'logoQRCode', wx.getSystemInfoSync().windowWidth * (260 / 375), wx.getSystemInfoSync().windowWidth * (260 / 375), function (res) {
  22. that.setData({
  23. tempFilePath: res
  24. })
  25. })
  26. },
  27. /**
  28. * 取消
  29. */
  30. goBack() {
  31. wx.navigateBack({
  32. delta: 1
  33. })
  34. },
  35. submit() {
  36. let that = this
  37. Http.getRequest(config.api.payChannel, app.globalData.token, '', {}, (res) => {
  38. if(res.code === 200) {
  39. if (res.data.payChannel === 1) {
  40. wx.login({
  41. success: res => {
  42. Common.getOpenId(res.code, app.globalData.bUserId, false)
  43. .then(res => {
  44. if (res.data && res.data.data && res.data.data.openId) {
  45. Http.postRequest(config.api.payBill, app.globalData.token, '', {
  46. billTypeValue: that.data.billTypeValue, billId: that.data.billId,payMoney: that.data.detailData.billAllNeedPay, openId: res.data.data.openId
  47. }, (el) => {
  48. debugger
  49. wx.requestPayment({
  50. timeStamp: el.data.timeStamp,
  51. nonceStr: el.data.nonceStr,
  52. package: el.data.package,
  53. signType: (el.data.signType) ? el.data.signType : "MD5",
  54. paySign: el.data.paySign,
  55. success: res => {
  56. wx.showLoading({
  57. title: '订单正在处理中...',
  58. })
  59. // that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  60. if (res.errMsg == "requestPayment:ok") {
  61. /**
  62. * 用户支付成功以后跳转到券包列表
  63. */
  64. wx.navigateTo({
  65. url: `/pages/bill/billdetail/index?billTypeValue=${that.data.billTypeValue}&billId=${that.data.billId}`,
  66. })
  67. // if (that.data.cardType == 100) {
  68. // wx.setStorage({
  69. // key: 'couponNum2',
  70. // data: "couponNum2"
  71. // })
  72. // } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  73. // wx.setStorage({
  74. // key: 'couponNum',
  75. // data: "couponNum"
  76. // })
  77. // }
  78. }
  79. },
  80. fail: res => {
  81. wx.hideLoading();
  82. wx.showToast({
  83. title: '支付失败',
  84. icon: 'none',
  85. })
  86. /**
  87. * 支付失败,需要更新订单的状态
  88. */
  89. // that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  90. // that.setData({
  91. // showbutton: false
  92. // })
  93. return;
  94. },
  95. complete: res => { }
  96. });
  97. // if(el.code === 200) {
  98. // wx.navigateTo({
  99. // url: `/pages/bill/billdetail/index?billTypeValue=${el.data.billTypeValue}&billId=${el.data.billId}`,
  100. // })
  101. // }
  102. })
  103. }
  104. })
  105. .catch(error => {
  106. wx.showToast({
  107. title: error.data.message,
  108. icon: 'none',
  109. })
  110. })
  111. }
  112. })
  113. } else {
  114. Http.postRequest(config.api.payBill, app.globalData.token, '', {
  115. billTypeValue: that.data.billTypeValue, billId: that.data.billId,payMoney: that.data.detailData.billAllNeedPay
  116. }, (el) => {
  117. if(el.code === 200) {
  118. that.setData({
  119. codeShow: true
  120. })
  121. that.qrcode(el.data)
  122. }
  123. })
  124. }
  125. }
  126. })
  127. },
  128. /**
  129. * 生命周期函数--监听页面加载
  130. */
  131. onLoad: function(options) {
  132. let that = this;
  133. that.setData({
  134. billTypeValue: options.billTypeValue,
  135. billId: options.billId
  136. })
  137. this.getData()
  138. },
  139. getData() {
  140. Http.getRequest(config.api.billDetail, app.globalData.token, '', {
  141. billId: this.data.billId,
  142. billTypeValue: this.data.billTypeValue,
  143. }, (res) => {
  144. if(res.code === 200) {
  145. this.setData({
  146. detailData: res.data
  147. })
  148. }
  149. })
  150. },
  151. /**
  152. * 生命周期函数--监听页面初次渲染完成
  153. */
  154. onReady: function() {
  155. },
  156. /**
  157. * 生命周期函数--监听页面显示
  158. */
  159. onShow: function() {
  160. },
  161. /**
  162. * 生命周期函数--监听页面隐藏
  163. */
  164. onHide: function() {
  165. },
  166. /**
  167. * 生命周期函数--监听页面卸载
  168. */
  169. onUnload: function() {
  170. },
  171. /**
  172. * 页面相关事件处理函数--监听用户下拉动作
  173. */
  174. onPullDownRefresh: function() {
  175. },
  176. /**
  177. * 页面上拉触底事件的处理函数
  178. */
  179. onReachBottom: function() {
  180. },
  181. /**
  182. * 用户点击右上角分享
  183. */
  184. onShareAppMessage: function() {
  185. }
  186. })