offline-evaluate.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. Page({
  3. behaviors: [PageContainerBehavior],
  4. data: {
  5. orderId: "",
  6. service: {
  7. name: "穴位按摩",
  8. date: "2025-02-4",
  9. time: "15:45:12",
  10. operator: "黄医生",
  11. institution: "余杭区第一人民医院",
  12. image: "/assets/bg/bg_dialog@2x.png",
  13. } as {
  14. name: string;
  15. date: string;
  16. time: string;
  17. operator: string;
  18. institution: string;
  19. image: string;
  20. },
  21. scoreServiceQuality: 0,
  22. scoreAttitude: 0,
  23. scoreEnvironment: 0,
  24. rateColor: "#F7BA2A",
  25. content: "",
  26. mediaList: [] as { path: string; type: "image" | "video" }[],
  27. canPublish: false,
  28. videoFullscreen: false,
  29. },
  30. onLoad(options: Record<string, string>) {
  31. const orderId = options.orderId || options.id || "";
  32. let service = this.data.service;
  33. if (options.serviceInfo) {
  34. try {
  35. const info = JSON.parse(decodeURIComponent(options.serviceInfo));
  36. service = {
  37. name: info.name ?? service.name,
  38. date: info.date ?? service.date,
  39. time: info.time ?? service.time,
  40. operator: info.operator ?? service.operator,
  41. institution: info.institution ?? service.institution,
  42. image: info.image ?? service.image,
  43. };
  44. } catch (_) {}
  45. }
  46. this.setData({
  47. orderId,
  48. service,
  49. canPublish: this._checkCanPublish(
  50. this.data.scoreServiceQuality,
  51. this.data.scoreAttitude,
  52. this.data.scoreEnvironment
  53. ),
  54. });
  55. },
  56. _checkCanPublish(
  57. quality: number,
  58. attitude: number,
  59. environment: number
  60. ): boolean {
  61. return quality > 0 && attitude > 0 && environment > 0;
  62. },
  63. _updateCanPublish() {
  64. const { scoreServiceQuality, scoreAttitude, scoreEnvironment } = this.data;
  65. this.setData({
  66. canPublish: this._checkCanPublish(
  67. scoreServiceQuality,
  68. scoreAttitude,
  69. scoreEnvironment
  70. ),
  71. });
  72. },
  73. onScoreServiceQuality(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
  74. const scoreServiceQuality = e.detail?.value ?? 0;
  75. this.setData({ scoreServiceQuality }, () => this._updateCanPublish());
  76. },
  77. onScoreAttitude(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
  78. const scoreAttitude = e.detail?.value ?? 0;
  79. this.setData({ scoreAttitude }, () => this._updateCanPublish());
  80. },
  81. onScoreEnvironment(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
  82. const scoreEnvironment = e.detail?.value ?? 0;
  83. this.setData({ scoreEnvironment }, () => this._updateCanPublish());
  84. },
  85. onContentInput(e: WechatMiniprogram.Input) {
  86. const content = e.detail?.value ?? "";
  87. this.setData({ content });
  88. },
  89. onChooseMedia() {
  90. const current = this.data.mediaList.length;
  91. if (current >= 9) {
  92. wx.showToast({ title: "图片和视频总数不能超过9个", icon: "none" });
  93. return;
  94. }
  95. const remain = 9 - current;
  96. wx.chooseMedia({
  97. count: remain,
  98. mediaType: ["image", "video"],
  99. sourceType: ["album", "camera"],
  100. maxDuration: 30,
  101. camera: "back",
  102. success: (res) => {
  103. const list = res.tempFiles.map((f) => ({
  104. path: f.tempFilePath,
  105. type: (f.fileType === "video" ? "video" : "image") as "image" | "video",
  106. }));
  107. const next = [...this.data.mediaList, ...list].slice(0, 9);
  108. this.setData({ mediaList: next });
  109. },
  110. });
  111. },
  112. onRemoveMedia(e: WechatMiniprogram.TouchEvent) {
  113. const index = e.currentTarget.dataset.index as number;
  114. const mediaList = this.data.mediaList.filter((_, i) => i !== index);
  115. this.setData({ mediaList });
  116. },
  117. onPreviewImage(e: WechatMiniprogram.TouchEvent) {
  118. const url = e.currentTarget.dataset.url as string;
  119. const urls = this.data.mediaList.filter((m) => m.type === "image").map((m) => m.path);
  120. if (url && urls.length) {
  121. wx.previewImage({ current: url, urls });
  122. }
  123. },
  124. onPreviewVideo(e: WechatMiniprogram.TouchEvent) {
  125. const index = e.currentTarget.dataset.index as number;
  126. const videoContext = wx.createVideoContext("offline-video-" + index, this);
  127. videoContext.requestFullScreen({});
  128. },
  129. onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
  130. const fullScreen = !!(e.detail && e.detail.fullScreen);
  131. this.setData({ videoFullscreen: fullScreen });
  132. },
  133. onRemoveService() {
  134. this.setData({
  135. service: {
  136. name: "",
  137. date: "",
  138. time: "",
  139. operator: "",
  140. institution: "",
  141. image: "",
  142. },
  143. });
  144. },
  145. onPublish() {
  146. if (!this.data.canPublish) {
  147. wx.showToast({ title: "请完成三项评分", icon: "none" });
  148. return;
  149. }
  150. const { orderId } = this.data;
  151. wx.showLoading({ title: "发布中..." });
  152. setTimeout(() => {
  153. wx.hideLoading();
  154. wx.showToast({ title: "发布成功", icon: "success" });
  155. if (orderId) {
  156. wx.redirectTo({
  157. url: `/module/order/pages/other-detail/other-detail?id=${orderId}`,
  158. });
  159. } else {
  160. wx.navigateBack();
  161. }
  162. }, 500);
  163. },
  164. });