offline-evaluateDetail.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import { OfflineEvaluateModel } from "../../model/evaluate.model";
  3. import { getOrderGoodsEvaluationMethod } from "../../request";
  4. function parseMediaType(url: string): "image" | "video" {
  5. if (!url) return "image";
  6. const match = /[?&]type=(image|video)\b/i.exec(url);
  7. if (match) return match[1].toLowerCase() as "image" | "video";
  8. const lower = url.toLowerCase();
  9. if (/\.(mp4|mov|avi|rmvb|flv|mkv|webm)$/.test(lower)) return "video";
  10. return "image";
  11. }
  12. Page({
  13. behaviors: [PageContainerBehavior],
  14. data: {
  15. orderId: "",
  16. service: {} as OfflineEvaluateModel,
  17. scoreServiceQuality: 0,
  18. scoreAttitude: 0,
  19. scoreEnvironment: 0,
  20. rateColor: "#F7BA2A",
  21. content: "",
  22. mediaList: [] as { path: string; type: "image" | "video" }[],
  23. videoFullscreen: false,
  24. },
  25. async onLoad(options: Record<string, string>) {
  26. let service = {} as OfflineEvaluateModel;
  27. if (options.goodsInfo) {
  28. const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
  29. service = {
  30. lineId: goods.id || 0,
  31. patientConditioningRecordId: goods.patientConditioningRecordId || 0,
  32. patientConditioningProgramId: goods.patientConditioningProgramId || 0,
  33. operateTime: goods.operateTime || "",
  34. operateBy: goods.operateBy || "",
  35. conditioningProgramSupplierName: goods.conditioningProgramSupplierName || "",
  36. image: goods.conditioningProgramPhoto || "",
  37. name: goods.conditioningProgramName
  38. };
  39. }
  40. this.setData({
  41. service,
  42. });
  43. if (service.patientConditioningRecordId) {
  44. try {
  45. const res = await getOrderGoodsEvaluationMethod("2", service.lineId);
  46. const mediaList: { path: string; type: "image" | "video" }[] = [];
  47. if (res && res.data) {
  48. if (Array.isArray(res.data.imageVideos)) {
  49. res.data.imageVideos.forEach((url: string) => {
  50. if (!url) return;
  51. mediaList.push({
  52. path: url,
  53. type: parseMediaType(url),
  54. });
  55. });
  56. }
  57. this.setData({
  58. evaluateInfo: res.data,
  59. scoreServiceQuality: Number(res.data.complianceScore ?? 0),
  60. scoreAttitude: Number(res.data.attitudeScore ?? 0),
  61. scoreEnvironment: Number(res.data.environmentScore ?? 0),
  62. content: res.data.depict || "",
  63. mediaList,
  64. });
  65. }
  66. } catch (error: any) {
  67. wx.showToast({
  68. title: error?.errMsg || "获取评价详情失败",
  69. icon: "none",
  70. });
  71. }
  72. }
  73. },
  74. onBack() {
  75. wx.navigateBack();
  76. },
  77. onPreviewImage(e: WechatMiniprogram.TouchEvent) {
  78. const url = e.currentTarget.dataset.url as string;
  79. const urls = this.data.mediaList
  80. .filter((m) => m.type === "image")
  81. .map((m) => m.path);
  82. if (url && urls.length) {
  83. wx.previewImage({ current: url, urls });
  84. }
  85. },
  86. onPreviewVideo(e: WechatMiniprogram.TouchEvent) {
  87. const index = e.currentTarget.dataset.index as number;
  88. const ctx = wx.createVideoContext("offline-detail-video-" + index, this);
  89. ctx.requestFullScreen({});
  90. },
  91. /** 点击图片/视频:原生全屏预览(类似 test 页) */
  92. onPreviewMedia(e: WechatMiniprogram.TouchEvent) {
  93. const index = e.currentTarget.dataset.index as number;
  94. const { mediaList } = this.data;
  95. if (index < 0 || index >= mediaList.length) return;
  96. const sources = mediaList.map((m) => ({
  97. url: m.path,
  98. type: m.type as "image" | "video",
  99. }));
  100. const previewMedia = (wx as any).previewMedia as
  101. | ((option: { sources: { url: string; type: "image" | "video" }[]; current: number }) => void)
  102. | undefined;
  103. if (typeof previewMedia === "function") {
  104. previewMedia({ sources, current: index });
  105. return;
  106. }
  107. // 低版本兜底:图片用 previewImage,视频用 requestFullScreen
  108. const current = mediaList[index];
  109. if (current.type === "image") {
  110. const urls = mediaList.filter((m) => m.type === "image").map((m) => m.path);
  111. wx.previewImage({ current: current.path, urls });
  112. return;
  113. }
  114. const ctx = wx.createVideoContext("offline-detail-video-" + index, this);
  115. ctx.requestFullScreen({});
  116. },
  117. onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
  118. const fullScreen = !!(e.detail && e.detail.fullScreen);
  119. this.setData({ videoFullscreen: fullScreen });
  120. },
  121. });