offline-evaluateDetail.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. console.log(options, "options.goodsInfo===");
  28. if (options.goodsInfo) {
  29. const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
  30. service = {
  31. lineId: goods.id || 0,
  32. patientConditioningRecordId: goods.patientConditioningRecordId || 0,
  33. patientConditioningProgramId: goods.patientConditioningProgramId || 0,
  34. operateTime: goods.operateTime || "",
  35. operateBy: goods.operateBy || "",
  36. conditioningProgramSupplierName: goods.conditioningProgramSupplierName || "",
  37. image: goods.image || "",
  38. };
  39. }
  40. console.log(service, "service===");
  41. this.setData({
  42. service,
  43. });
  44. if (service.patientConditioningRecordId) {
  45. try {
  46. const res = await getOrderGoodsEvaluationMethod("2", service.lineId);
  47. console.log(res, "res===");
  48. const mediaList: { path: string; type: "image" | "video" }[] = [];
  49. if (res && res.data) {
  50. if (Array.isArray(res.data.imageVideos)) {
  51. res.data.imageVideos.forEach((url: string) => {
  52. if (!url) return;
  53. mediaList.push({
  54. path: url,
  55. type: parseMediaType(url),
  56. });
  57. });
  58. }
  59. this.setData({
  60. evaluateInfo: res.data,
  61. scoreServiceQuality: Number(res.data.complianceScore ?? 0),
  62. scoreAttitude: Number(res.data.attitudeScore ?? 0),
  63. scoreEnvironment: Number(res.data.environmentScore ?? 0),
  64. content: res.data.depict || "",
  65. mediaList,
  66. });
  67. }
  68. } catch (error: any) {
  69. console.log(error, "error===");
  70. wx.showToast({
  71. title: error?.errMsg || "获取评价详情失败",
  72. icon: "none",
  73. });
  74. }
  75. }
  76. },
  77. onBack() {
  78. wx.navigateBack();
  79. },
  80. onPreviewImage(e: WechatMiniprogram.TouchEvent) {
  81. const url = e.currentTarget.dataset.url as string;
  82. const urls = this.data.mediaList
  83. .filter((m) => m.type === "image")
  84. .map((m) => m.path);
  85. if (url && urls.length) {
  86. wx.previewImage({ current: url, urls });
  87. }
  88. },
  89. onPreviewVideo(e: WechatMiniprogram.TouchEvent) {
  90. const index = e.currentTarget.dataset.index as number;
  91. const ctx = wx.createVideoContext("offline-detail-video-" + index, this);
  92. ctx.requestFullScreen({});
  93. },
  94. onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
  95. const fullScreen = !!(e.detail && e.detail.fullScreen);
  96. this.setData({ videoFullscreen: fullScreen });
  97. },
  98. });