| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- Page({
- behaviors: [PageContainerBehavior],
- data: {
- orderId: "",
- service: {} as { name: string; image: string; description?: string; date?: string; time?: string; operator?: string; institution?: string },
- scoreServiceQuality: 5,
- scoreAttitude: 5,
- scoreEnvironment: 5,
- rateColor: "#F7BA2A",
- content: "描述相符,商品质量很好,包装完整,会回购。",
- mediaList: [] as { path: string; type: "image" | "video" }[],
- showMediaCarousel: false,
- mediaCarouselCurrent: 0,
- },
- onLoad(options: Record<string, string>) {
- const orderId = options.orderId || options.id || "";
- let service: { name: string; image: string; description?: string } = {
- name: "",
- image: "",
- description: "",
- date: "",
- time: "",
- operator: "",
- institution: "",
- };
- console.log(options, "options.goodsInfo===");
- if (options.goodsInfo) {
- try {
- const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
- service = {
- name: goods.name || "",
- image: goods.image || "",
- description: goods.description || "",
- date: "2026-03-05",
- time: "10:00:00",
- operator: "张三",
- institution: "杭州第一人民医院",
- };
- } catch (_) {}
- }
- console.log(service, "service===");
- // 若传入评价详情数据则使用,否则用默认展示内容(含示例图片)
- let scoreServiceQuality = 2;
- let scoreAttitude = 4;
- let scoreEnvironment = 3;
- let content = "描述相符,商品质量很好,包装完整,会回购。";
- let mediaList: { path: string; type: "image" | "video" }[] = [
- { path: "/assets/bg/bg_dialog@2x.png", type: "image" },
- ];
- if (options.evaluateInfo) {
- try {
- const info = JSON.parse(decodeURIComponent(options.evaluateInfo));
- if (info.scoreServiceQuality != null) scoreServiceQuality = Number(info.scoreServiceQuality);
- if (info.scoreAttitude != null) scoreAttitude = Number(info.scoreAttitude);
- if (info.scoreEnvironment != null) scoreEnvironment = Number(info.scoreEnvironment);
- if (info.content != null) content = info.content;
- if (Array.isArray(info.mediaList) && info.mediaList.length > 0) mediaList = info.mediaList;
- } catch (_) {}
- }
- this.setData({
- orderId,
- service,
- scoreServiceQuality,
- scoreAttitude,
- scoreEnvironment,
- content,
- mediaList,
- });
- },
- onBack() {
- wx.navigateBack();
- },
- /** 打开图片/视频统一轮播,从指定下标开始;轮播到视频时自动播放 */
- onPreviewMedia(e: WechatMiniprogram.TouchEvent) {
- const index = e.currentTarget.dataset.index as number;
- const { mediaList } = this.data;
- if (index < 0 || index >= mediaList.length) return;
- this.setData(
- { showMediaCarousel: true, mediaCarouselCurrent: index },
- () => {
- this._playVideoAtCarouselIndex(index);
- }
- );
- },
- /** 轮播切换:暂停所有视频,若当前项是视频则播放 */
- onMediaCarouselChange(e: WechatMiniprogram.SwiperChange) {
- const current = e.detail?.current ?? 0;
- this.setData({ mediaCarouselCurrent: current });
- this._pauseAllCarouselVideos();
- this._playVideoAtCarouselIndex(current);
- },
- onCloseMediaCarousel() {
- this._pauseAllCarouselVideos();
- this.setData({ showMediaCarousel: false });
- },
- _playVideoAtCarouselIndex(index: number) {
- const list = this.data.mediaList;
- if (index < 0 || index >= list.length || list[index].type !== "video") return;
- const ctx = wx.createVideoContext("preview-video-" + index, this);
- ctx.play();
- },
- _pauseAllCarouselVideos() {
- this.data.mediaList.forEach((item, i) => {
- if (item.type === "video") {
- const ctx = wx.createVideoContext("preview-video-" + i, this);
- ctx.pause();
- }
- });
- },
- });
|