goods-evaluateDetail.ts 4.8 KB

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