index.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. },
  24. attached: function () {
  25. },
  26. methods: {
  27. close:function(){
  28. this.triggerEvent('onChangeFun',{action:'pay_close'});
  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) return app.Tips({title:'请选择要支付的订单'});
  35. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.data.totalPrice)) return app.Tips({ title: '余额不足!' });
  36. wx.showLoading({ title: '支付中' });
  37. orderPay({ uni: that.data.order_id, paytype: paytype, 'from': 'routine' }).then(res => {
  38. switch (paytype){
  39. case 'weixin':
  40. if (res.data.result === undefined) return app.Tips({title:'缺少支付参数'});
  41. var jsConfig = res.data.result.jsConfig;
  42. wx.requestPayment({
  43. timeStamp: jsConfig.timestamp,
  44. nonceStr: jsConfig.nonceStr,
  45. package: jsConfig.package,
  46. signType: jsConfig.signType,
  47. paySign: jsConfig.paySign,
  48. success: function (res) {
  49. wx.hideLoading();
  50. return app.Tips({ title: res.msg, icon: 'success' }, () => {
  51. that.triggerEvent('onChangeFun', { action: 'pay_complete' });
  52. });
  53. },
  54. fail: function (e) {
  55. wx.hideLoading();
  56. return app.Tips({ title: '取消支付' }, () => {
  57. that.triggerEvent('onChangeFun', { action: 'pay_fail' });
  58. });
  59. },
  60. complete: function (e) {
  61. wx.hideLoading();
  62. if (e.errMsg == 'requestPayment:cancel') return app.Tips({ title: '取消支付' }, () => {
  63. that.triggerEvent('onChangeFun', { action: 'pay_fail' });
  64. });
  65. },
  66. });
  67. break;
  68. case 'yue':
  69. wx.hideLoading();
  70. return app.Tips({ title: res.msg, icon: 'success' }, () => {
  71. that.triggerEvent('onChangeFun', { action: 'pay_complete' });
  72. });;
  73. break;
  74. case 'offline':
  75. wx.hideLoading();
  76. return app.Tips({ title: res.msg, icon: 'success' }, () => {
  77. that.triggerEvent('onChangeFun', { action: 'pay_complete' });
  78. });;
  79. break;
  80. }
  81. }).catch(err => {
  82. wx.hideLoading();
  83. return app.Tips({ title: err }, () => {
  84. that.triggerEvent('onChangeFun', { action: 'pay_fail' });
  85. });
  86. })
  87. },
  88. }
  89. })