wxpay.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {
  2. mapMutations,
  3. mapActions
  4. } from 'vuex';
  5. import {
  6. getOptions,
  7. getPayInfo
  8. } from "@/common/apis/recharge.js"
  9. import {
  10. getUserInfo
  11. } from "@/common/apis/my.js";
  12. export default {
  13. data() {
  14. return {
  15. pay_select_id: 0,
  16. user_info: {},
  17. payVideoInfo: {},
  18. payOptions: []
  19. }
  20. },
  21. created() {
  22. // mixin的created生命周期钩子
  23. console.log('mixin created');
  24. },
  25. methods: {
  26. getPayInfo(originIndex) {
  27. getUserInfo().then(res => {
  28. this.user_info = res.data
  29. });
  30. getOptions().then(res => {
  31. this.payOptions = res.data;
  32. console.log(res, 'getPayInfogetPayInfogetPayInfogetPayInfo')
  33. this.payOptions.forEach((item, index) => {
  34. if (item.is_default == 1) {
  35. this.pay_select_id = item.id;
  36. }
  37. })
  38. this.payVideoInfo = {
  39. video_id: this.video_id,
  40. video_series_sequence: originIndex
  41. };
  42. });
  43. },
  44. selectPayItem(item) {
  45. this.pay_select_id = item.id;
  46. let params = {
  47. video_id: this.payVideoInfo.video_id,
  48. video_series_sequence: this.payVideoInfo.video_series_sequence,
  49. pay_proudct_id: item.id,
  50. is_first_pay: item.is_first_pay,
  51. }
  52. getPayInfo(params).then(res => {
  53. if (res.data) {
  54. // #ifdef MP-WEIXIN
  55. this.wxMinPay(res.data);
  56. // #endif
  57. }
  58. });
  59. },
  60. wxMinPay(param) {
  61. wx.requestPayment({
  62. timeStamp: param.timeStamp,
  63. nonceStr: param.nonceStr,
  64. package: param.package,
  65. signType: param.signType,
  66. paySign: param.paySign,
  67. success(res) {
  68. this.pay_success = true;
  69. uni.showToast({
  70. title: '支付成功',
  71. icon: "none"
  72. });
  73. // console.log('success:' + JSON.stringify(res));
  74. },
  75. fail(e) {
  76. if (e.errMsg == "requestPayment:fail cancel") {
  77. uni.showToast({
  78. title: '取消支付',
  79. icon: "none"
  80. });
  81. } else {
  82. uni.showToast({
  83. title: '支付失败',
  84. icon: "none"
  85. });
  86. }
  87. }
  88. })
  89. }
  90. },
  91. }