| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- import { upload } from "../../../../lib/request/upload";
- import { Post } from "../../../../lib/request/method";
- // module/chats/pages/analysis/analysis.ts
- interface IAnalysisData {
- _lastResetTime: number;
- uploadList: Array<{
- target: string;
- required: boolean;
- label: string;
- src: string;
- }>;
- thumbnail: string[];
- original: string[];
- status: boolean[];
- _queue: Record<string, any>;
- activeObj: Record<string, any>;
- followObj: Record<string, any>;
- workId: number;
- }
- interface IAnalysisProperties {
- messageType: number;
- }
- type IAnalysisInstance = WechatMiniprogram.Component.Instance<
- IAnalysisData,
- IAnalysisProperties,
- {
- handle(event: WechatMiniprogram.TouchEvent): void;
- _chooseMedia(index: number): Promise<string | null>;
- _deleteMedia(index: number): void;
- _uploadMedia(index: number, src?: string): void;
- onSubmit(): Promise<void>;
- }
- >;
- Component({
- behaviors: [PageContainerBehavior],
- options: {},
- properties: {
- messageType: { type: Number, value: 0 },
- },
- data: {
- _lastResetTime: 0,
- uploadList: [
- {
- target: "tongueImgUrl",
- required: true,
- label: "舌面图",
- src: "../../assets/tongue-1.png",
- },
- {
- target: "tongueBackImgUrl",
- required: true,
- label: "舌下图",
- src: "../../assets/tongue-2.png",
- },
- {
- target: "faceImgUrl",
- required: false,
- label: "正面面部图",
- src: "../../assets/face-1.png",
- },
- ],
- thumbnail: [] as string[],
- original: [] as string[],
- status: [false, false, false],
- _queue: {} as AnyObject,
- // 随访上传参数
- activeObj: {},
- followObj: {},
- workId: 0,
- _submitting: false,
- },
- attached() {
- // 从存储中拿到之前的对话信息
- this.setData({
- followObj: wx.getStorageSync("followObj"),
- workId: wx.getStorageSync("workId"),
- });
- },
- methods: {
- handle(event: WechatMiniprogram.TouchEvent) {
- const { handle, index } = event.mark as AnyObject;
- console.log(handle, index, handle === "upload:delete", event.mark);
- switch (handle) {
- case "preview":
- break;
- case "upload":
- this._chooseMedia(index).then(
- (src) => src && this._uploadMedia(index, src)
- );
- break;
- case "upload:delete":
- this._deleteMedia(index);
- break;
- }
- },
- _chooseMedia(index: number) {
- return wx
- .chooseMedia({
- count: 1,
- mediaType: ["image"],
- sourceType: ["album", "camera"],
- camera: "front",
- })
- .then((res) => {
- const src = res.tempFiles[0].tempFilePath;
- this.setData({ [`thumbnail.${index}`]: src });
- return src;
- })
- .catch(() => null);
- },
- _deleteMedia(index: number) {
- this.setData({
- [`thumbnail.${index}`]: "",
- [`original.${index}`]: "",
- });
- },
- _uploadMedia(index: number, src?: string) {
- this.setData({ [`_queue.${index}`]: true });
- src ??= this.data.thumbnail[index];
- upload({
- params: { name: "file", file: src! },
- transform({ data }) {
- return (<any>data).url;
- },
- })
- .then(
- (src) => {
- this.setData({ [`original.${index}`]: src });
- },
- (error) => {
- wx.showToast({ title: error?.errMsg ?? "上传失败", icon: "error" });
- this.setData({
- [`thumbnail.${index}`]: "",
- [`original.${index}`]: "",
- });
- }
- )
- .then(() => {
- this.setData({ [`_queue.${index}`]: false });
- });
- },
- async onSubmit() {
- const submitBtn = this.selectComponent('#submitBtn');
- if (this.data._submitting) return;
- this.setData({ _submitting: true });
- const data = {
- thumbnail: [] as any,
- source: [] as any,
- };
- for (let index = 0; index < this.data.uploadList.length; index++) {
- const item = this.data.uploadList[index];
- if (this.data._queue[index]) {
- console.log('[Analysis] Upload in progress, resetting button');
- wx.showToast({ title: `请等待图片上传完毕`, icon: "none" });
- submitBtn?.resetState();
- this.setData({ _submitting: false });
- return;
- } else if (item.required && !this.data.original[index]) {
- console.log('[Analysis] Missing required image, resetting button');
- wx.showToast({ title: `请上传${item.label}`, icon: "none" });
- submitBtn?.resetState();
- this.setData({ _submitting: false });
- return;
- }
- if (this.data.original[index])
- data.source.push({
- target: item.target,
- src: this.data.original[index],
- });
- if (this.data.thumbnail[index])
- data.thumbnail.push({
- target: item.target,
- src: this.data.thumbnail[index],
- });
- }
- let imageObj: any = {
- upImg: this.data.original[0],
- downImg: this.data.original[1],
- faceImg: this.data.original[2],
- };
-
- // console.log(this.data.followObj, "this.data.followObj");
- this.setData({
- activeObj: { ...imageObj, ...this.data.followObj },
- });
- // console.log({ ...this.data.activeObj }, "activeObj");
- let isAnalysis: number;
- if (this.data.messageType === 2) {
- isAnalysis = wx.getStorageSync("isAnalysis");
- }
- // console.log(this.data, "messageType", isAnalysis);
- if (isAnalysis === 2) {
- // 提交随访提醒
- try {
- const res = await Post(
- `/followupTaskManage/updateFollowupTaskFillin/${this.data?.workId}`,
- { ...this.data.activeObj },
- {
- transform({ data }: any) {
- return data;
- },
- }
- );
- // 存储舌面象分析报告id,用于跳转页面时最后产生结果查看
- wx.setStorageSync(
- "tonguefaceAnalysisReportId",
- res.tonguefaceAnalysisReportId
- );
- this.getOpenerEventChannel().emit("update", data);
- wx.navigateBack();
- } catch (error) {
- console.log('[Analysis] Submit failed, resetting button');
- wx.showToast({ title: error?.errMsg ?? "提交失败", icon: "none" });
- submitBtn?.resetState();
- this.setData({ _submitting: false });
- }
- } else {
- // console.log("对话管家",data)
- // 对话管家
- this.getOpenerEventChannel().emit("update", data);
- wx.navigateBack();
- }
- },
- },
- });
|