detail.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. course: {},
  8. comments: [],
  9. catalog: [],
  10. tabIndex: 0,
  11. defaultCover: "/static/default-course.png",
  12. defaultAvatar: "/static/1.jpg",
  13. lockIcon: "/static/lock.png"
  14. };
  15. },
  16. computed: {
  17. parsedImages() {
  18. try {
  19. if (this.course.images) {
  20. return JSON.parse(this.course.images);
  21. }
  22. return [];
  23. } catch (e) {
  24. common_vendor.index.__f__("error", "at pages/course/detail.vue:108", "解析图片数据失败:", e);
  25. return [];
  26. }
  27. }
  28. },
  29. onLoad(options) {
  30. this.fetchDetail(options.id);
  31. },
  32. methods: {
  33. async fetchDetail(id) {
  34. try {
  35. const res = await common_vendor.index.request({
  36. url: `http://localhost:9527/product/findOne?productId=${id}`,
  37. method: "GET"
  38. });
  39. if (res.statusCode === 200) {
  40. this.course = res.data.data;
  41. this.comments = res.data.data.comments || [];
  42. this.catalog = res.data.data.catalog || [];
  43. } else {
  44. throw new Error(res.data.message || "获取数据失败");
  45. }
  46. } catch (err) {
  47. common_vendor.index.showToast({
  48. title: err.message || "加载失败",
  49. icon: "none"
  50. });
  51. }
  52. }
  53. }
  54. };
  55. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  56. var _a, _b;
  57. return common_vendor.e({
  58. a: common_vendor.f($options.parsedImages, (image, index, i0) => {
  59. return {
  60. a: image.imageUrl,
  61. b: index
  62. };
  63. }),
  64. b: common_vendor.t($data.course.name),
  65. c: common_vendor.t($data.course.subtitle),
  66. d: common_vendor.t((_a = $data.course.price) == null ? void 0 : _a.toFixed(2)),
  67. e: common_vendor.t((_b = $data.course.originalPrice) == null ? void 0 : _b.toFixed(2)),
  68. f: common_vendor.t($data.course.stock),
  69. g: common_vendor.t($data.comments.length),
  70. h: $data.comments.length === 0
  71. }, $data.comments.length === 0 ? {} : {
  72. i: common_vendor.f($data.comments, (item, k0, i0) => {
  73. return {
  74. a: item.avatar || $data.defaultAvatar,
  75. b: common_vendor.t(item.user),
  76. c: common_vendor.f(5, (n, k1, i1) => {
  77. return {
  78. a: n,
  79. b: n <= item.star ? 1 : ""
  80. };
  81. }),
  82. d: common_vendor.t(item.content || "此用户没有填写评价"),
  83. e: item.id
  84. };
  85. })
  86. }, {
  87. j: common_vendor.n($data.tabIndex === 0 ? "active" : ""),
  88. k: common_vendor.o(($event) => $data.tabIndex = 0),
  89. l: common_vendor.n($data.tabIndex === 1 ? "active" : ""),
  90. m: common_vendor.o(($event) => $data.tabIndex = 1),
  91. n: common_vendor.n($data.tabIndex === 2 ? "active" : ""),
  92. o: common_vendor.o(($event) => $data.tabIndex = 2),
  93. p: $data.tabIndex === 0
  94. }, $data.tabIndex === 0 ? {
  95. q: common_vendor.f($options.parsedImages, (image, index, i0) => {
  96. return {
  97. a: image.imageUrl,
  98. b: common_vendor.t(image.courseTitle),
  99. c: common_vendor.t(image.courseDesc),
  100. d: index
  101. };
  102. })
  103. } : $data.tabIndex === 1 ? {
  104. s: common_vendor.f($data.catalog, (item, k0, i0) => {
  105. return common_vendor.e({
  106. a: item.icon || $data.lockIcon,
  107. b: common_vendor.t(item.title),
  108. c: common_vendor.t(item.type),
  109. d: common_vendor.t(item.date),
  110. e: common_vendor.t(item.count),
  111. f: item.trial
  112. }, item.trial ? {} : {}, {
  113. g: item.id
  114. });
  115. })
  116. } : {
  117. t: common_assets._imports_0$5
  118. }, {
  119. r: $data.tabIndex === 1
  120. });
  121. }
  122. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-3d21314d"]]);
  123. wx.createPage(MiniProgramPage);
  124. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/course/detail.js.map