Orders-dev.5c571709.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { a as axios } from "./utils-dev.be08a1a2.js";
  2. import { a as ElMessage } from "./element-dev.26a170ea.js";
  3. import { v as defineComponent, r as ref, c as computed, l as onMounted, B as createElementBlock, E as createBaseVNode, C as createVNode, D as withCtx, ak as resolveComponent, aq as resolveDirective, y as openBlock, M as createTextVNode, J as withDirectives, O as toDisplayString, z as createBlock, L as createCommentVNode } from "./vue-dev.7a51ac2d.js";
  4. import { _ as _export_sfc } from "./_plugin-vue_export-helper-dev.cc2b3d55.js";
  5. const _hoisted_1 = { class: "orders-page" };
  6. const _hoisted_2 = { class: "card-header" };
  7. const _hoisted_3 = {
  8. key: 0,
  9. class: "empty-state"
  10. };
  11. const _hoisted_4 = { class: "stats-grid" };
  12. const _hoisted_5 = { class: "stats-content" };
  13. const _hoisted_6 = { class: "stats-number" };
  14. const _hoisted_7 = { class: "stats-content" };
  15. const _hoisted_8 = { class: "stats-number" };
  16. const _hoisted_9 = { class: "stats-content" };
  17. const _hoisted_10 = { class: "stats-number" };
  18. const _hoisted_11 = { class: "stats-content" };
  19. const _hoisted_12 = { class: "stats-number" };
  20. const _sfc_main = /* @__PURE__ */ defineComponent({
  21. __name: "Orders",
  22. setup(__props) {
  23. const loading = ref(false);
  24. const orders = ref([]);
  25. const completedOrders = computed(
  26. () => orders.value.filter((order) => order.status === "已完成").length
  27. );
  28. const processingOrders = computed(
  29. () => orders.value.filter((order) => order.status === "处理中").length
  30. );
  31. const totalAmount = computed(
  32. () => orders.value.reduce((sum, order) => sum + order.total_price, 0)
  33. );
  34. const loadOrders = async () => {
  35. loading.value = true;
  36. try {
  37. const response = await axios.get("/api/orders");
  38. if (response.data.code === 0) {
  39. orders.value = response.data.data.orders;
  40. ElMessage.success("订单列表加载成功");
  41. } else {
  42. ElMessage.error(response.data.message || "加载失败");
  43. }
  44. } catch (error) {
  45. console.error("加载订单列表失败:", error);
  46. ElMessage.error("加载订单列表失败");
  47. } finally {
  48. loading.value = false;
  49. }
  50. };
  51. const getStatusType = (status) => {
  52. switch (status) {
  53. case "已完成":
  54. return "success";
  55. case "处理中":
  56. return "warning";
  57. case "已取消":
  58. return "danger";
  59. default:
  60. return "info";
  61. }
  62. };
  63. const viewOrder = (order) => {
  64. ElMessage.info(`查看订单详情: ${order.id}`);
  65. };
  66. const cancelOrder = (order) => {
  67. ElMessage.info(`取消订单: ${order.id}`);
  68. };
  69. onMounted(() => {
  70. loadOrders();
  71. });
  72. return (_ctx, _cache) => {
  73. const _component_Refresh = resolveComponent("Refresh");
  74. const _component_el_icon = resolveComponent("el-icon");
  75. const _component_el_button = resolveComponent("el-button");
  76. const _component_el_table_column = resolveComponent("el-table-column");
  77. const _component_el_tag = resolveComponent("el-tag");
  78. const _component_el_table = resolveComponent("el-table");
  79. const _component_el_empty = resolveComponent("el-empty");
  80. const _component_el_card = resolveComponent("el-card");
  81. const _directive_loading = resolveDirective("loading");
  82. return openBlock(), createElementBlock("div", _hoisted_1, [
  83. _cache[8] || (_cache[8] = createBaseVNode("div", { class: "page-header" }, [
  84. createBaseVNode("h2", null, "订单管理"),
  85. createBaseVNode("p", null, "查看和管理用户订单信息")
  86. ], -1)),
  87. createVNode(_component_el_card, null, {
  88. header: withCtx(() => [
  89. createBaseVNode("div", _hoisted_2, [
  90. _cache[1] || (_cache[1] = createBaseVNode("span", null, "订单列表", -1)),
  91. createVNode(_component_el_button, {
  92. type: "primary",
  93. onClick: loadOrders
  94. }, {
  95. default: withCtx(() => [
  96. createVNode(_component_el_icon, null, {
  97. default: withCtx(() => [
  98. createVNode(_component_Refresh)
  99. ]),
  100. _: 1
  101. }),
  102. _cache[0] || (_cache[0] = createTextVNode(" 刷新 ", -1))
  103. ]),
  104. _: 1
  105. })
  106. ])
  107. ]),
  108. default: withCtx(() => [
  109. withDirectives((openBlock(), createElementBlock("div", null, [
  110. createVNode(_component_el_table, {
  111. data: orders.value,
  112. style: { "width": "100%" }
  113. }, {
  114. default: withCtx(() => [
  115. createVNode(_component_el_table_column, {
  116. prop: "id",
  117. label: "订单ID",
  118. width: "100"
  119. }),
  120. createVNode(_component_el_table_column, {
  121. prop: "product_name",
  122. label: "产品名称"
  123. }),
  124. createVNode(_component_el_table_column, {
  125. prop: "quantity",
  126. label: "数量",
  127. width: "100"
  128. }),
  129. createVNode(_component_el_table_column, {
  130. prop: "total_price",
  131. label: "总价",
  132. width: "120"
  133. }, {
  134. default: withCtx(({ row }) => [
  135. createTextVNode(" ¥" + toDisplayString(row.total_price.toFixed(2)), 1)
  136. ]),
  137. _: 1
  138. }),
  139. createVNode(_component_el_table_column, {
  140. prop: "status",
  141. label: "状态",
  142. width: "100"
  143. }, {
  144. default: withCtx(({ row }) => [
  145. createVNode(_component_el_tag, {
  146. type: getStatusType(row.status)
  147. }, {
  148. default: withCtx(() => [
  149. createTextVNode(toDisplayString(row.status), 1)
  150. ]),
  151. _: 2
  152. }, 1032, ["type"])
  153. ]),
  154. _: 1
  155. }),
  156. createVNode(_component_el_table_column, {
  157. prop: "created_at",
  158. label: "创建时间",
  159. width: "180"
  160. }),
  161. createVNode(_component_el_table_column, {
  162. label: "操作",
  163. width: "200"
  164. }, {
  165. default: withCtx(({ row }) => [
  166. createVNode(_component_el_button, {
  167. size: "small",
  168. onClick: ($event) => viewOrder(row)
  169. }, {
  170. default: withCtx(() => [..._cache[2] || (_cache[2] = [
  171. createTextVNode(" 查看详情 ", -1)
  172. ])]),
  173. _: 1
  174. }, 8, ["onClick"]),
  175. row.status === "处理中" ? (openBlock(), createBlock(_component_el_button, {
  176. key: 0,
  177. size: "small",
  178. type: "warning",
  179. onClick: ($event) => cancelOrder(row)
  180. }, {
  181. default: withCtx(() => [..._cache[3] || (_cache[3] = [
  182. createTextVNode(" 取消 ", -1)
  183. ])]),
  184. _: 1
  185. }, 8, ["onClick"])) : createCommentVNode("", true)
  186. ]),
  187. _: 1
  188. })
  189. ]),
  190. _: 1
  191. }, 8, ["data"]),
  192. !loading.value && orders.value.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_3, [
  193. createVNode(_component_el_empty, { description: "暂无订单数据" })
  194. ])) : createCommentVNode("", true)
  195. ])), [
  196. [_directive_loading, loading.value]
  197. ])
  198. ]),
  199. _: 1
  200. }),
  201. createBaseVNode("div", _hoisted_4, [
  202. createVNode(_component_el_card, { class: "stats-card" }, {
  203. default: withCtx(() => [
  204. createBaseVNode("div", _hoisted_5, [
  205. createBaseVNode("div", _hoisted_6, toDisplayString(orders.value.length), 1),
  206. _cache[4] || (_cache[4] = createBaseVNode("div", { class: "stats-label" }, "总订单数", -1))
  207. ])
  208. ]),
  209. _: 1
  210. }),
  211. createVNode(_component_el_card, { class: "stats-card" }, {
  212. default: withCtx(() => [
  213. createBaseVNode("div", _hoisted_7, [
  214. createBaseVNode("div", _hoisted_8, toDisplayString(completedOrders.value), 1),
  215. _cache[5] || (_cache[5] = createBaseVNode("div", { class: "stats-label" }, "已完成", -1))
  216. ])
  217. ]),
  218. _: 1
  219. }),
  220. createVNode(_component_el_card, { class: "stats-card" }, {
  221. default: withCtx(() => [
  222. createBaseVNode("div", _hoisted_9, [
  223. createBaseVNode("div", _hoisted_10, toDisplayString(processingOrders.value), 1),
  224. _cache[6] || (_cache[6] = createBaseVNode("div", { class: "stats-label" }, "处理中", -1))
  225. ])
  226. ]),
  227. _: 1
  228. }),
  229. createVNode(_component_el_card, { class: "stats-card" }, {
  230. default: withCtx(() => [
  231. createBaseVNode("div", _hoisted_11, [
  232. createBaseVNode("div", _hoisted_12, "¥" + toDisplayString(totalAmount.value.toFixed(2)), 1),
  233. _cache[7] || (_cache[7] = createBaseVNode("div", { class: "stats-label" }, "总金额", -1))
  234. ])
  235. ]),
  236. _: 1
  237. })
  238. ])
  239. ]);
  240. };
  241. }
  242. });
  243. const Orders_vue_vue_type_style_index_0_scoped_2b83f005_lang = "";
  244. const Orders = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-2b83f005"]]);
  245. export {
  246. Orders as default
  247. };
  248. //# sourceMappingURL=Orders-dev.5c571709.js.map