index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { orderPay } from '../../api/order.js'
  2. const app = getApp()
  3. Component({
  4. properties: {
  5. payMode: {
  6. type: Array,
  7. value: []
  8. },
  9. pay_close: {
  10. type: Boolean,
  11. value: false
  12. },
  13. order_id: {
  14. type: String,
  15. value: ''
  16. },
  17. totalPrice: {
  18. type: String,
  19. value: '0'
  20. }
  21. },
  22. data: {},
  23. attached: function () {},
  24. methods: {
  25. close: function () {
  26. this.triggerEvent('onChangeFun', {
  27. action: 'pay_close'
  28. })
  29. },
  30. goPay: function (e) {
  31. let that = this
  32. let paytype = e.currentTarget.dataset.value
  33. let number = e.currentTarget.dataset.number
  34. if (!that.data.order_id)
  35. return app.Tips({
  36. title: '请选择要支付的订单'
  37. })
  38. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.data.totalPrice))
  39. return app.Tips({
  40. title: '余额不足!'
  41. })
  42. wx.showLoading({
  43. title: '支付中'
  44. })
  45. orderPay({
  46. uni: that.data.order_id,
  47. paytype: paytype,
  48. from: 'routine'
  49. })
  50. .then(res => {
  51. switch (paytype) {
  52. case 'weixin':
  53. if (res.data.result === undefined)
  54. return app.Tips({
  55. title: '缺少支付参数'
  56. })
  57. var jsConfig = res.data.result.jsConfig
  58. wx.requestPayment({
  59. timeStamp: jsConfig.timestamp,
  60. nonceStr: jsConfig.nonceStr,
  61. package: jsConfig.package,
  62. signType: jsConfig.signType,
  63. paySign: jsConfig.paySign,
  64. success: function (res) {
  65. wx.hideLoading()
  66. return app.Tips(
  67. {
  68. title: res.msg,
  69. icon: 'success'
  70. },
  71. () => {
  72. that.triggerEvent('onChangeFun', {
  73. action: 'pay_complete'
  74. })
  75. }
  76. )
  77. },
  78. fail: function (e) {
  79. wx.hideLoading()
  80. return app.Tips(
  81. {
  82. title: '取消支付'
  83. },
  84. () => {
  85. that.triggerEvent('onChangeFun', {
  86. action: 'pay_fail'
  87. })
  88. }
  89. )
  90. },
  91. complete: function (e) {
  92. wx.hideLoading()
  93. if (e.errMsg == 'requestPayment:cancel')
  94. return app.Tips(
  95. {
  96. title: '取消支付'
  97. },
  98. () => {
  99. that.triggerEvent('onChangeFun', {
  100. action: 'pay_fail'
  101. })
  102. }
  103. )
  104. }
  105. })
  106. break
  107. case 'yue':
  108. wx.hideLoading()
  109. return app.Tips(
  110. {
  111. title: res.msg,
  112. icon: 'success'
  113. },
  114. () => {
  115. that.triggerEvent('onChangeFun', {
  116. action: 'pay_complete'
  117. })
  118. }
  119. )
  120. break
  121. case 'offline':
  122. wx.hideLoading()
  123. return app.Tips(
  124. {
  125. title: res.msg,
  126. icon: 'success'
  127. },
  128. () => {
  129. that.triggerEvent('onChangeFun', {
  130. action: 'pay_complete'
  131. })
  132. }
  133. )
  134. break
  135. }
  136. })
  137. .catch(err => {
  138. wx.hideLoading()
  139. return app.Tips(
  140. {
  141. title: err
  142. },
  143. () => {
  144. that.triggerEvent('onChangeFun', {
  145. action: 'pay_fail'
  146. })
  147. }
  148. )
  149. })
  150. }
  151. }
  152. })