all-pay.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. let that = null;
  2. const allPay = function(data, sign, _this, item) {
  3. that = _this;
  4. switch (sign) {
  5. case 'advance':
  6. let body = {
  7. goods_id: data.goods_id,
  8. goods_attr_id: data.id,
  9. goods_num: data.number,
  10. };
  11. that.$request({
  12. url: that.$api.advance.order_submit,
  13. method: 'post',
  14. data: {
  15. ...body,
  16. }
  17. }).then(res => {
  18. if (res.code === 0) {
  19. get_token(res.data);
  20. }
  21. });
  22. break;
  23. case 'gift':
  24. let select_data = {
  25. name: item.name,
  26. price: data.price,
  27. attr: {
  28. id: data.id,
  29. attr_list: data.attr_list,
  30. stock: data.stock,
  31. goods_id: data.goods_id,
  32. },
  33. attr_str: '',
  34. pic_url: data.pic_url ? data.pic_url : item.cover_pic,
  35. number: data.number,
  36. };
  37. for (let i = 0; i < data.attr_list.length; i++) {
  38. select_data.attr_str += `${data.attr_list[i].attr_group_name}:${data.attr_list[i].attr_name} `
  39. }
  40. if (that.$storage.getStorageSync('GIFT_CART')) {
  41. let again = 0;
  42. let storage = that.$storage.getStorageSync('GIFT_CART');
  43. for (let i = 0; i < storage.length; i++) {
  44. if (storage[i].attr.id === data.id) {
  45. storage[i].number += data.number;
  46. } else {
  47. again += 1;
  48. }
  49. }
  50. if (again === storage.length) {
  51. storage.push(select_data);
  52. }
  53. that.$storage.setStorageSync('GIFT_CART', storage);
  54. } else {
  55. that.$storage.setStorageSync('GIFT_CART', [select_data]);
  56. }
  57. uni.showToast({
  58. title: '加入成功',
  59. icon: 'none'
  60. });
  61. break;
  62. case "pintuan":
  63. // that.$jump({
  64. // open_type: 'navigate',
  65. // url: `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}&preview_url=${encodeURIComponent(that.$api.pt.order_preview)}&submit_url=${encodeURIComponent(that.$api.pt.order_submit)}&order_page_url=/plugins/pt/order/order&plugin=pt`
  66. // });
  67. break;
  68. default:
  69. break;
  70. }
  71. };
  72. function get_token(data) {
  73. that.$request({
  74. url: that.$api.advance.pay_data,
  75. method: 'post',
  76. data: {
  77. ...data
  78. },
  79. }).then(res => {
  80. if (res.code === 0) {
  81. if (res.data.hasOwnProperty('id')) {
  82. that.$payment.pay(res.data.id).then(() => {
  83. // 支付成功
  84. uni.navigateTo({
  85. url: `/plugins/advance/order/order`
  86. })
  87. }).catch(() => {
  88. // 支付失败
  89. uni.navigateTo({
  90. url: `/plugins/advance/order/order`
  91. })
  92. });
  93. } else {
  94. setTimeout(() => {
  95. get_token(data);
  96. }, 1000);
  97. }
  98. } else {
  99. uni.showModal({
  100. title: '提示',
  101. content: res.msg,
  102. })
  103. }
  104. });
  105. }
  106. export default allPay;