goods-evaluate.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import { EvaluateModel } from "../../model/evaluate.model";
  3. import { evaluateOrderGoodsMethod } from "../../request";
  4. import { upload } from "../../../../lib/request/upload";
  5. Page({
  6. behaviors: [PageContainerBehavior],
  7. data: {
  8. orderId: "",
  9. product: {} as { name: string; image: string; description?: string, patientConditioningRecordId?: number, patientConditioningProgramId?: number },
  10. score: 0,
  11. rateColor: "#F7BA2A",
  12. content: "",
  13. evaluateInfo: {} as EvaluateModel,
  14. mediaList: [] as { path: string; type: "image" | "video" }[],
  15. canPublish: false,
  16. videoFullscreen: false,
  17. },
  18. onLoad(options: Record<string, string>) {
  19. console.log(options, "options===");
  20. // const orderId = options.orderId || options.id || "";
  21. let product: { name: string; image: string; description?: string, patientConditioningRecordId?: number, patientConditioningProgramId?: number } = {
  22. name: "",
  23. image: "",
  24. description: "",
  25. patientConditioningRecordId: 0,
  26. patientConditioningProgramId: 0,
  27. };
  28. if (options.goodsInfo) {
  29. const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
  30. console.log(goods, "goods===");
  31. product = {
  32. name: goods.name || "",
  33. image: goods.image || "",
  34. description: goods.description || "",
  35. patientConditioningRecordId: goods.patientConditioningRecordId || 0,
  36. patientConditioningProgramId: goods.id || 0,
  37. };
  38. }
  39. this.setData({
  40. // orderId,
  41. product,
  42. canPublish: this._checkCanPublish(0, ""),
  43. });
  44. },
  45. _checkCanPublish(score: number, _content: string): boolean {
  46. return score > 0;
  47. },
  48. onScoreChange(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
  49. const score = e.detail?.value ?? 0;
  50. this.setData({
  51. score,
  52. canPublish: this._checkCanPublish(score, this.data.content),
  53. });
  54. },
  55. onContentInput(e: WechatMiniprogram.Input) {
  56. const content = e.detail?.value ?? "";
  57. this.setData({
  58. content,
  59. canPublish: this._checkCanPublish(this.data.score, content),
  60. });
  61. },
  62. onChooseMedia() {
  63. const current = this.data.mediaList.length;
  64. if (current >= 9) {
  65. wx.showToast({ title: "图片和视频总数不能超过9个", icon: "none" });
  66. return;
  67. }
  68. const remain = 9 - current;
  69. wx.chooseMedia({
  70. count: remain,
  71. mediaType: ["image", "video"],
  72. sourceType: ["album", "camera"],
  73. maxDuration: 30,
  74. camera: "back",
  75. success: (res) => {
  76. const list = res.tempFiles.map((f) => ({
  77. path: f.tempFilePath,
  78. type: (f.fileType === "video" ? "video" : "image") as "image" | "video",
  79. }));
  80. const next = [...this.data.mediaList, ...list].slice(0, 9);
  81. this.setData({ mediaList: next });
  82. },
  83. });
  84. },
  85. onRemoveMedia(e: WechatMiniprogram.TouchEvent) {
  86. const index = e.currentTarget.dataset.index as number;
  87. const mediaList = this.data.mediaList.filter((_, i) => i !== index);
  88. this.setData({ mediaList });
  89. },
  90. onPreviewImage(e: WechatMiniprogram.TouchEvent) {
  91. const url = e.currentTarget.dataset.url as string;
  92. const urls = this.data.mediaList.filter((m) => m.type === "image").map((m) => m.path);
  93. if (url && urls.length) {
  94. wx.previewImage({ current: url, urls });
  95. }
  96. },
  97. onPreviewVideo(e: WechatMiniprogram.TouchEvent) {
  98. const index = e.currentTarget.dataset.index as number;
  99. const videoContext = wx.createVideoContext("goods-video-" + index, this);
  100. videoContext.requestFullScreen({});
  101. },
  102. onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
  103. const fullScreen = !!(e.detail && e.detail.fullScreen);
  104. this.setData({ videoFullscreen: fullScreen });
  105. },
  106. onRemoveProduct() {
  107. this.setData({
  108. product: { name: "", image: "", description: "", patientConditioningRecordId: 0, patientConditioningProgramId: 0 },
  109. });
  110. },
  111. async onPublish() {
  112. if (!this.data.canPublish) {
  113. wx.showToast({ title: "请先完成评分", icon: "none" });
  114. return;
  115. }
  116. console.log(this.data.product,"90000")
  117. const data = {
  118. patientConditioningProgramId: this.data.product.patientConditioningProgramId,
  119. patientConditioningRecordId: this.data.product.patientConditioningRecordId,
  120. complianceScore: this.data.score,
  121. depict: this.data.content,
  122. imageVideos: this.data.mediaList,
  123. };
  124. console.log(data,"评价数据")
  125. return
  126. // TODO: 调用评价提交接口,将 this.data.score、content、mediaList 上传
  127. try {
  128. await evaluateOrderGoodsMethod(data)
  129. wx.showLoading({ title: "发布中..." });
  130. setTimeout(() => {
  131. wx.hideLoading();
  132. wx.showToast({ title: "发布成功", icon: "success" });
  133. wx.redirectTo({
  134. url: `/module/order/pages/other-detail/other-detail`,
  135. });
  136. }, 500);
  137. } catch (error: any) {
  138. wx.showToast({ title: error.errMsg || "发布失败", icon: "none" });
  139. } finally {
  140. wx.hideLoading();
  141. }
  142. },
  143. });