offline-evaluateDetail.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. Page({
  3. behaviors: [PageContainerBehavior],
  4. data: {
  5. orderId: "",
  6. service: {} as { name: string; image: string; description?: string; date?: string; time?: string; operator?: string; institution?: string },
  7. scoreServiceQuality: 5,
  8. scoreAttitude: 5,
  9. scoreEnvironment: 5,
  10. rateColor: "#F7BA2A",
  11. content: "描述相符,商品质量很好,包装完整,会回购。",
  12. mediaList: [] as { path: string; type: "image" | "video" }[],
  13. showMediaCarousel: false,
  14. mediaCarouselCurrent: 0,
  15. },
  16. onLoad(options: Record<string, string>) {
  17. const orderId = options.orderId || options.id || "";
  18. let service: { name: string; image: string; description?: string } = {
  19. name: "",
  20. image: "",
  21. description: "",
  22. date: "",
  23. time: "",
  24. operator: "",
  25. institution: "",
  26. };
  27. console.log(options, "options.goodsInfo===");
  28. if (options.goodsInfo) {
  29. try {
  30. const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
  31. service = {
  32. name: goods.name || "",
  33. image: goods.image || "",
  34. description: goods.description || "",
  35. date: "2026-03-05",
  36. time: "10:00:00",
  37. operator: "张三",
  38. institution: "杭州第一人民医院",
  39. };
  40. } catch (_) {}
  41. }
  42. console.log(service, "service===");
  43. // 若传入评价详情数据则使用,否则用默认展示内容(含示例图片)
  44. let scoreServiceQuality = 2;
  45. let scoreAttitude = 4;
  46. let scoreEnvironment = 3;
  47. let content = "描述相符,商品质量很好,包装完整,会回购。";
  48. let mediaList: { path: string; type: "image" | "video" }[] = [
  49. { path: "/assets/bg/bg_dialog@2x.png", type: "image" },
  50. ];
  51. if (options.evaluateInfo) {
  52. try {
  53. const info = JSON.parse(decodeURIComponent(options.evaluateInfo));
  54. if (info.scoreServiceQuality != null) scoreServiceQuality = Number(info.scoreServiceQuality);
  55. if (info.scoreAttitude != null) scoreAttitude = Number(info.scoreAttitude);
  56. if (info.scoreEnvironment != null) scoreEnvironment = Number(info.scoreEnvironment);
  57. if (info.content != null) content = info.content;
  58. if (Array.isArray(info.mediaList) && info.mediaList.length > 0) mediaList = info.mediaList;
  59. } catch (_) {}
  60. }
  61. this.setData({
  62. orderId,
  63. service,
  64. scoreServiceQuality,
  65. scoreAttitude,
  66. scoreEnvironment,
  67. content,
  68. mediaList,
  69. });
  70. },
  71. onBack() {
  72. wx.navigateBack();
  73. },
  74. /** 打开图片/视频统一轮播,从指定下标开始;轮播到视频时自动播放 */
  75. onPreviewMedia(e: WechatMiniprogram.TouchEvent) {
  76. const index = e.currentTarget.dataset.index as number;
  77. const { mediaList } = this.data;
  78. if (index < 0 || index >= mediaList.length) return;
  79. this.setData(
  80. { showMediaCarousel: true, mediaCarouselCurrent: index },
  81. () => {
  82. this._playVideoAtCarouselIndex(index);
  83. }
  84. );
  85. },
  86. /** 轮播切换:暂停所有视频,若当前项是视频则播放 */
  87. onMediaCarouselChange(e: WechatMiniprogram.SwiperChange) {
  88. const current = e.detail?.current ?? 0;
  89. this.setData({ mediaCarouselCurrent: current });
  90. this._pauseAllCarouselVideos();
  91. this._playVideoAtCarouselIndex(current);
  92. },
  93. onCloseMediaCarousel() {
  94. this._pauseAllCarouselVideos();
  95. this.setData({ showMediaCarousel: false });
  96. },
  97. _playVideoAtCarouselIndex(index: number) {
  98. const list = this.data.mediaList;
  99. if (index < 0 || index >= list.length || list[index].type !== "video") return;
  100. const ctx = wx.createVideoContext("preview-video-" + index, this);
  101. ctx.play();
  102. },
  103. _pauseAllCarouselVideos() {
  104. this.data.mediaList.forEach((item, i) => {
  105. if (item.type === "video") {
  106. const ctx = wx.createVideoContext("preview-video-" + i, this);
  107. ctx.pause();
  108. }
  109. });
  110. },
  111. });