| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- import I18nBehavior from "../../../../i18n/behavior";
- import { Post } from "../../../../lib/request/method";
- // module/chats/pages/consultation-record/consultation-record.ts
- Page({
- behaviors: [I18nBehavior, PageContainerBehavior],
- properties: {},
- data: {
- i18n: {
- consultChat: { _: '聊天', title: '记录' },
- },
- //有item传过来不分页
- //是否分页
- isPage: false,
- page: 1,
- pageSize: 2,
- hasMore: true,
- isLoading: false,
- consultationList: [] as Array<{
- id: number;
- startTime: string;
- endTime: string;
- manualTime: string; //转人工的时间
- items: Array<{
- id: number; //咨询记录id
- consultRecordId: number; //咨询记录id
- messageContent: string;
- sendTime: string; //发送时间
- sendType: string; // 发送类型 1-患者 2-医生 3-系统 4-AI
- messageType: string; // 消息类型 1-文本 2-图片
- isRead: string;
- }>;
- }>,
- },
- observers: {},
- onLoad(options: any) {
- console.log(options, "咨询记录数据");
- if (options.item) {
- const item = JSON.parse(decodeURIComponent(options.item));
- this.setData({
- consultationList: item,
- isPage: false,
- });
- } else {
- this.setData({
- isPage: true,
- });
- this.loadData();
- }
- },
- // 获取聊天记录的数据
- async loadData() {
- if (this.data.isLoading || !this.data.hasMore) return;
- this.setData({ isLoading: true });
- try {
- const res = await Post(
- `/consultManage/pageConsult?pageNum=${this.data.page}&pageSize=${this.data.pageSize}`,
- {}
- );
- console.log("res=咨询记录列表", res.data.data);
- if (res.data && res.data.data && res.data.data.length > 0) {
- // 追加新数据到现有列表
- const newList =
- this.data.page === 1
- ? res.data.data
- : [...this.data.consultationList, ...res.data.data];
- // 判断是否还有更多数据
- // 方式1: 如果有 total 字段,通过比较已加载数量和总数判断
- // 方式2: 如果返回的数据长度小于 pageSize,说明没有更多数据了
- let hasMoreData = false;
- if (res.data.total !== undefined && res.data.total !== null) {
- hasMoreData = newList.length < res.data.total;
- } else {
- // 如果返回的数据长度等于 pageSize,可能还有更多数据
- hasMoreData = res.data.data.length >= this.data.pageSize;
- }
- this.setData({
- consultationList: newList,
- page: this.data.page + 1,
- hasMore: hasMoreData,
- isLoading: false,
- });
- } else {
- // 没有数据时,第一页清空列表,后续页保留已有数据
- this.setData({
- ...(this.data.page === 1 && { consultationList: [] }),
- hasMore: false,
- isLoading: false,
- });
- }
- } catch (error) {
- console.error("加载咨询记录失败", error);
- this.setData({
- isLoading: false,
- });
- }
- },
- onScrollToLower() {
- console.log("onScrollToLower");
- if (this.data.isPage) {
- this.loadData();
- }
- },
- //预览图片
- previewImage(e: any) {
- const currentUrl = e.currentTarget.dataset.url;
- // 获取所有咨询记录中所有图片消息的 URL 列表
- const urls: string[] = [];
- this.data?.consultationList?.forEach((consultation) => {
- consultation?.items?.forEach((item) => {
- if (item?.messageType === "2" && item?.messageContent) {
- urls.push(item?.messageContent);
- }
- });
- });
- wx.previewImage({
- current: currentUrl, // 当前显示图片的链接
- urls: urls.length > 0 ? urls : [currentUrl], // 需要预览的图片链接列表
- fail: (err) => {
- console.error("预览图片失败", err);
- },
- });
- },
- });
|