| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- import { EvaluateModel } from "../../model/evaluate.model";
- import { evaluateOrderGoodsMethod } from "../../request";
- import { upload } from "../../../../lib/request/upload";
- Page({
- behaviors: [PageContainerBehavior],
- data: {
- orderId: "",
- product: {} as { name: string; image: string; description?: string, patientConditioningRecordId?: number, patientConditioningProgramId?: number },
- score: 0,
- rateColor: "#F7BA2A",
- content: "",
- evaluateInfo: {} as EvaluateModel,
- mediaList: [] as { path: string; type: "image" | "video" }[],
- canPublish: false,
- videoFullscreen: false,
- },
- onLoad(options: Record<string, string>) {
- console.log(options, "options===");
- // const orderId = options.orderId || options.id || "";
- let product: { name: string; image: string; description?: string, patientConditioningRecordId?: number, patientConditioningProgramId?: number } = {
- name: "",
- image: "",
- description: "",
- patientConditioningRecordId: 0,
- patientConditioningProgramId: 0,
- };
- if (options.goodsInfo) {
- const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
- console.log(goods, "goods===");
- product = {
- name: goods.name || "",
- image: goods.image || "",
- description: goods.description || "",
- patientConditioningRecordId: goods.patientConditioningRecordId || 0,
- patientConditioningProgramId: goods.id || 0,
- };
- }
- this.setData({
- // orderId,
- product,
- canPublish: this._checkCanPublish(0, ""),
- });
- },
- _checkCanPublish(score: number, _content: string): boolean {
- return score > 0;
- },
- onScoreChange(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
- const score = e.detail?.value ?? 0;
- this.setData({
- score,
- canPublish: this._checkCanPublish(score, this.data.content),
- });
- },
- onContentInput(e: WechatMiniprogram.Input) {
- const content = e.detail?.value ?? "";
- this.setData({
- content,
- canPublish: this._checkCanPublish(this.data.score, 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("goods-video-" + index, this);
- videoContext.requestFullScreen({});
- },
- onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
- const fullScreen = !!(e.detail && e.detail.fullScreen);
- this.setData({ videoFullscreen: fullScreen });
- },
- onRemoveProduct() {
- this.setData({
- product: { name: "", image: "", description: "", patientConditioningRecordId: 0, patientConditioningProgramId: 0 },
- });
- },
- async onPublish() {
- if (!this.data.canPublish) {
- wx.showToast({ title: "请先完成评分", icon: "none" });
- return;
- }
- console.log(this.data.product,"90000")
- const data = {
- patientConditioningProgramId: this.data.product.patientConditioningProgramId,
- patientConditioningRecordId: this.data.product.patientConditioningRecordId,
- complianceScore: this.data.score,
- depict: this.data.content,
- imageVideos: this.data.mediaList,
- };
- console.log(data,"评价数据")
- return
- // TODO: 调用评价提交接口,将 this.data.score、content、mediaList 上传
- try {
- await evaluateOrderGoodsMethod(data)
- wx.showLoading({ title: "发布中..." });
- setTimeout(() => {
- wx.hideLoading();
- wx.showToast({ title: "发布成功", icon: "success" });
- wx.redirectTo({
- url: `/module/order/pages/other-detail/other-detail`,
- });
- }, 500);
- } catch (error: any) {
- wx.showToast({ title: error.errMsg || "发布失败", icon: "none" });
- } finally {
- wx.hideLoading();
- }
- },
- });
|