index.js 4.7 KB

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