|
|
@@ -0,0 +1,165 @@
|
|
|
+import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
|
|
|
+
|
|
|
+Page({
|
|
|
+ behaviors: [PageContainerBehavior],
|
|
|
+ data: {
|
|
|
+ orderId: "",
|
|
|
+ service: {
|
|
|
+ name: "穴位按摩",
|
|
|
+ date: "2025-02-4",
|
|
|
+ time: "15:45:12",
|
|
|
+ operator: "黄医生",
|
|
|
+ institution: "余杭区第一人民医院",
|
|
|
+ image: "/assets/bg/bg_dialog@2x.png",
|
|
|
+ } as {
|
|
|
+ name: string;
|
|
|
+ date: string;
|
|
|
+ time: string;
|
|
|
+ operator: string;
|
|
|
+ institution: string;
|
|
|
+ image: string;
|
|
|
+ },
|
|
|
+ scoreServiceQuality: 0,
|
|
|
+ scoreAttitude: 0,
|
|
|
+ scoreEnvironment: 0,
|
|
|
+ rateColor: "#F7BA2A",
|
|
|
+ content: "",
|
|
|
+ mediaList: [] as { path: string; type: "image" | "video" }[],
|
|
|
+ canPublish: false,
|
|
|
+ videoFullscreen: false,
|
|
|
+ },
|
|
|
+ onLoad(options: Record<string, string>) {
|
|
|
+ const orderId = options.orderId || options.id || "";
|
|
|
+ let service = this.data.service;
|
|
|
+ if (options.serviceInfo) {
|
|
|
+ try {
|
|
|
+ const info = JSON.parse(decodeURIComponent(options.serviceInfo));
|
|
|
+ service = {
|
|
|
+ name: info.name ?? service.name,
|
|
|
+ date: info.date ?? service.date,
|
|
|
+ time: info.time ?? service.time,
|
|
|
+ operator: info.operator ?? service.operator,
|
|
|
+ institution: info.institution ?? service.institution,
|
|
|
+ image: info.image ?? service.image,
|
|
|
+ };
|
|
|
+ } catch (_) {}
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ orderId,
|
|
|
+ service,
|
|
|
+ canPublish: this._checkCanPublish(
|
|
|
+ this.data.scoreServiceQuality,
|
|
|
+ this.data.scoreAttitude,
|
|
|
+ this.data.scoreEnvironment
|
|
|
+ ),
|
|
|
+ });
|
|
|
+ },
|
|
|
+ _checkCanPublish(
|
|
|
+ quality: number,
|
|
|
+ attitude: number,
|
|
|
+ environment: number
|
|
|
+ ): boolean {
|
|
|
+ return quality > 0 && attitude > 0 && environment > 0;
|
|
|
+ },
|
|
|
+ _updateCanPublish() {
|
|
|
+ const { scoreServiceQuality, scoreAttitude, scoreEnvironment } = this.data;
|
|
|
+ this.setData({
|
|
|
+ canPublish: this._checkCanPublish(
|
|
|
+ scoreServiceQuality,
|
|
|
+ scoreAttitude,
|
|
|
+ scoreEnvironment
|
|
|
+ ),
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onScoreServiceQuality(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
|
|
|
+ const scoreServiceQuality = e.detail?.value ?? 0;
|
|
|
+ this.setData({ scoreServiceQuality }, () => this._updateCanPublish());
|
|
|
+ },
|
|
|
+ onScoreAttitude(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
|
|
|
+ const scoreAttitude = e.detail?.value ?? 0;
|
|
|
+ this.setData({ scoreAttitude }, () => this._updateCanPublish());
|
|
|
+ },
|
|
|
+ onScoreEnvironment(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
|
|
|
+ const scoreEnvironment = e.detail?.value ?? 0;
|
|
|
+ this.setData({ scoreEnvironment }, () => this._updateCanPublish());
|
|
|
+ },
|
|
|
+ onContentInput(e: WechatMiniprogram.Input) {
|
|
|
+ const content = e.detail?.value ?? "";
|
|
|
+ this.setData({ content });
|
|
|
+ },
|
|
|
+ onChooseMedia() {
|
|
|
+ const current = this.data.mediaList.length;
|
|
|
+ if (current >= 9) {
|
|
|
+ wx.showToast({ title: "图片和视频总数不能超过9个", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const remain = 9 - current;
|
|
|
+ wx.chooseMedia({
|
|
|
+ count: remain,
|
|
|
+ mediaType: ["image", "video"],
|
|
|
+ sourceType: ["album", "camera"],
|
|
|
+ maxDuration: 30,
|
|
|
+ camera: "back",
|
|
|
+ success: (res) => {
|
|
|
+ const list = res.tempFiles.map((f) => ({
|
|
|
+ path: f.tempFilePath,
|
|
|
+ type: (f.fileType === "video" ? "video" : "image") as "image" | "video",
|
|
|
+ }));
|
|
|
+ const next = [...this.data.mediaList, ...list].slice(0, 9);
|
|
|
+ this.setData({ mediaList: next });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onRemoveMedia(e: WechatMiniprogram.TouchEvent) {
|
|
|
+ const index = e.currentTarget.dataset.index as number;
|
|
|
+ const mediaList = this.data.mediaList.filter((_, i) => i !== index);
|
|
|
+ this.setData({ mediaList });
|
|
|
+ },
|
|
|
+ onPreviewImage(e: WechatMiniprogram.TouchEvent) {
|
|
|
+ const url = e.currentTarget.dataset.url as string;
|
|
|
+ const urls = this.data.mediaList.filter((m) => m.type === "image").map((m) => m.path);
|
|
|
+ if (url && urls.length) {
|
|
|
+ wx.previewImage({ current: url, urls });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onPreviewVideo(e: WechatMiniprogram.TouchEvent) {
|
|
|
+ const index = e.currentTarget.dataset.index as number;
|
|
|
+ const videoContext = wx.createVideoContext("offline-video-" + index, this);
|
|
|
+ videoContext.requestFullScreen({});
|
|
|
+ },
|
|
|
+ onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
|
|
|
+ const fullScreen = !!(e.detail && e.detail.fullScreen);
|
|
|
+ this.setData({ videoFullscreen: fullScreen });
|
|
|
+ },
|
|
|
+ onRemoveService() {
|
|
|
+ this.setData({
|
|
|
+ service: {
|
|
|
+ name: "",
|
|
|
+ date: "",
|
|
|
+ time: "",
|
|
|
+ operator: "",
|
|
|
+ institution: "",
|
|
|
+ image: "",
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onPublish() {
|
|
|
+ if (!this.data.canPublish) {
|
|
|
+ wx.showToast({ title: "请完成三项评分", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const { orderId } = this.data;
|
|
|
+ wx.showLoading({ title: "发布中..." });
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showToast({ title: "发布成功", icon: "success" });
|
|
|
+ if (orderId) {
|
|
|
+ wx.redirectTo({
|
|
|
+ url: `/module/order/pages/other-detail/other-detail?id=${orderId}`,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.navigateBack();
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ },
|
|
|
+});
|