mixin.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // 根目录的static下创建js文件夹并创建mixin.js文件
  2. export const mixin = {
  3. data() {
  4. return {
  5. buyId:'',
  6. }
  7. },
  8. methods: {
  9. // 购买
  10. creadOrd(item){
  11. console.log(item);
  12. if(item.my_is_pay==1) return this.$api.toast('您已经购买过了')
  13. this.buyId= item.id;
  14. this.$refs['popup'].open();
  15. },
  16. onConfirm(){
  17. this.$api
  18. .request('payment/newVcPay',{
  19. cate_id:this.buyId,
  20. pay_type:1,
  21. })
  22. .then(data => {
  23. console.log(data);
  24. if (data.code && data.code != 200) {
  25. this.$api.toast(data.msg || '获取支付信息失败');
  26. return;
  27. }
  28. console.log(data);
  29. const orderInfo = data;
  30. const { timeStamp, nonceStr, paySign } = orderInfo;
  31. const payParams = {
  32. provider: 'wxpay',
  33. orderInfo: data,
  34. timeStamp,
  35. nonceStr,
  36. package: orderInfo.package,
  37. signType: 'MD5',
  38. paySign,
  39. success: e => {
  40. setTimeout(res => {
  41. this.page = 1;
  42. this.list = [];
  43. this.loadData();
  44. }, 600);
  45. },
  46. fail: err => {
  47. if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
  48. this.$api.toast('取消支付');
  49. } else {
  50. this.$api.toast('支付遇到错误,请稍候重试');
  51. console.log(err);
  52. }
  53. }
  54. };
  55. uni.requestPayment(payParams);
  56. });
  57. },
  58. }
  59. }