refundOrder.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_order = require("../api/order.js");
  4. const common_assets = require("../common/assets.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. orderId: null,
  9. order: null,
  10. orderCode: null,
  11. items: [],
  12. type: null,
  13. reasonsList: [],
  14. reasons: "请选择",
  15. explains: "",
  16. refundAmount: 0
  17. };
  18. },
  19. onLoad(option) {
  20. this.type = option.type;
  21. this.orderCode = option.orderCode;
  22. this.orderId = option.orderId;
  23. console.log(this.orderId);
  24. this.getStoreOrder();
  25. this.getDicts();
  26. },
  27. methods: {
  28. getDicts() {
  29. var data = {
  30. key: "store_after_sales_reasons"
  31. };
  32. api_order.Dicts(data).then((res) => {
  33. if (res.code == 200) {
  34. this.reasonsList = res.data;
  35. } else {
  36. common_vendor.index.showToast({
  37. icon: "none",
  38. title: "请求失败"
  39. });
  40. }
  41. });
  42. },
  43. getStoreOrder() {
  44. var data = {
  45. orderId: this.orderId
  46. };
  47. api_order.getStoreOrderItems(data).then((res) => {
  48. if (res.code == 200) {
  49. this.order = res.order;
  50. this.items = res.items;
  51. if (this.order.isPayRemain == 0) {
  52. this.refundAmount = this.order.totalPrice.toFixed(2);
  53. } else {
  54. this.refundAmount = this.order.totalPrice.toFixed(2);
  55. }
  56. } else {
  57. common_vendor.index.showToast({
  58. icon: "none",
  59. title: "请求失败"
  60. });
  61. }
  62. });
  63. },
  64. reasonsChange(e) {
  65. console.log(e.detail.value);
  66. this.reasons = this.reasonsList[e.detail.value].dictLabel;
  67. },
  68. submit() {
  69. if (this.reasons == "请选择") {
  70. common_vendor.index.showToast({
  71. icon: "none",
  72. title: "请选择原因"
  73. });
  74. return;
  75. }
  76. if (this.refundAmount < 0) {
  77. common_vendor.index.showToast({
  78. icon: "none",
  79. title: "请输入退款金额"
  80. });
  81. return;
  82. }
  83. var productIds = this.items.map((item2) => item2.productId);
  84. var products = [];
  85. for (var i = 0; i < productIds.length; i++) {
  86. var item = {
  87. productId: productIds[i]
  88. };
  89. products.push(item);
  90. }
  91. var data = {
  92. orderId: this.orderId,
  93. refundType: this.type,
  94. //0仅退款1退货退款
  95. refundAmount: this.refundAmount,
  96. orderCode: this.orderCode,
  97. reasons: this.reasons,
  98. explains: this.explains,
  99. productList: products
  100. };
  101. api_order.applyAfterSales(data).then((res) => {
  102. if (res.code == 200) {
  103. common_vendor.index.showToast({
  104. icon: "success",
  105. title: "提交成功"
  106. });
  107. setTimeout(function() {
  108. common_vendor.index.redirectTo({
  109. url: "./order"
  110. });
  111. }, 500);
  112. } else {
  113. common_vendor.index.showToast({
  114. icon: "none",
  115. title: res.msg
  116. });
  117. }
  118. });
  119. }
  120. }
  121. };
  122. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  123. return common_vendor.e({
  124. a: $data.order != null && $data.order.isPackage != 1
  125. }, $data.order != null && $data.order.isPackage != 1 ? {
  126. b: common_vendor.f($data.items, (item, index, i0) => {
  127. return {
  128. a: JSON.parse(item.jsonInfo).image,
  129. b: common_vendor.t(JSON.parse(item.jsonInfo).productName),
  130. c: common_vendor.t(JSON.parse(item.jsonInfo).sku),
  131. d: common_vendor.t(JSON.parse(item.jsonInfo).price.toFixed(2)),
  132. e: common_vendor.t(JSON.parse(item.jsonInfo).num),
  133. f: index
  134. };
  135. })
  136. } : {}, {
  137. c: $data.order != null && $data.order.isPackage == 1 && $data.order.packageJson != null
  138. }, $data.order != null && $data.order.isPackage == 1 && $data.order.packageJson != null ? {
  139. d: JSON.parse($data.order.packageJson).imgUrl,
  140. e: common_vendor.t(JSON.parse($data.order.packageJson).title),
  141. f: common_vendor.t(JSON.parse($data.order.packageJson).descs)
  142. } : {}, {
  143. g: $data.refundAmount,
  144. h: common_vendor.o(($event) => $data.refundAmount = $event.detail.value),
  145. i: common_vendor.t($data.reasons),
  146. j: common_assets._imports_0$10,
  147. k: common_vendor.o((...args) => $options.reasonsChange && $options.reasonsChange(...args)),
  148. l: $data.reasons,
  149. m: $data.reasonsList,
  150. n: $data.explains,
  151. o: common_vendor.o(($event) => $data.explains = $event.detail.value),
  152. p: common_vendor.o(($event) => $options.submit())
  153. });
  154. }
  155. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  156. wx.createPage(MiniProgramPage);