order.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { cancelOrder, takeOrder, delOrder, payOrder } from "@api/order";
  2. import dialog from "@utils/dialog";
  3. import { pay } from "@libs/wechat";
  4. import router from "../router";
  5. export function cancelOrderHandle(orderId) {
  6. return new Promise((resolve, reject) => {
  7. dialog.confirm({
  8. mes: "确认取消该订单?",
  9. opts() {
  10. cancelOrder(orderId)
  11. .then(res => {
  12. dialog.success("取消成功");
  13. resolve(res);
  14. })
  15. .catch(err => {
  16. dialog.error("取消失败");
  17. reject(err);
  18. });
  19. }
  20. });
  21. });
  22. }
  23. export function takeOrderHandle(orderId) {
  24. return new Promise((resolve, reject) => {
  25. takeOrder(orderId)
  26. .then(res => {
  27. resolve(res);
  28. })
  29. .catch(err => {
  30. dialog.error("收货失败");
  31. reject(err);
  32. });
  33. });
  34. }
  35. export function delOrderHandle(orderId) {
  36. return new Promise((resolve, reject) => {
  37. dialog.confirm({
  38. mes: "确认删除该订单?",
  39. opts() {
  40. delOrder(orderId)
  41. .then(res => {
  42. dialog.success("删除成功");
  43. resolve(res);
  44. })
  45. .catch(err => {
  46. dialog.error("删除失败");
  47. reject(err);
  48. });
  49. }
  50. });
  51. });
  52. }
  53. export function payOrderHandle(orderId, type, from) {
  54. return new Promise((resolve, reject) => {
  55. dialog.loading.open("");
  56. payOrder(orderId, type, from)
  57. .then(res => {
  58. const data = res.data;
  59. dialog.loading.close();
  60. switch (data.status) {
  61. case "WECHAT_H5_PAY":
  62. reject(data);
  63. setTimeout(() => {
  64. location.replace(data.result.jsConfig.mweb_url);
  65. }, 100);
  66. break;
  67. case "ORDER_EXIST":
  68. case "EXTEND_ORDER":
  69. case "PAY_ERROR":
  70. case "PAY_DEFICIENCY":
  71. dialog.toast({ mes: res.msg });
  72. reject(data);
  73. break;
  74. case "SUCCESS":
  75. dialog.success(res.msg);
  76. resolve(data);
  77. break;
  78. case "WECHAT_PAY":
  79. pay(data.result.jsConfig).then(() => {
  80. resolve(data);
  81. });
  82. }
  83. })
  84. .catch(err => {
  85. dialog.loading.close();
  86. dialog.toast({ mes: err.msg || "订单支付失败" });
  87. });
  88. });
  89. }
  90. export function goShopDetail(item) {
  91. return new Promise(resolve => {
  92. if (item.activity && item.activity.type === "1") {
  93. router.push({
  94. path:
  95. "/activity/seckill_detail/" +
  96. item.activity.id +
  97. "/" +
  98. item.activity.time +
  99. "/1"
  100. });
  101. } else if (item.activity && item.activity.type === "2") {
  102. router.push({
  103. path: "/activity/dargain_detail/" + item.activity.id
  104. });
  105. } else if (item.activity && item.activity.type === "3") {
  106. router.push({
  107. path: "/activity/group_detail/" + item.activity.id
  108. });
  109. } else {
  110. resolve(item);
  111. }
  112. });
  113. }