Просмотр исходного кода

修复健康分析无变化按钮可点击

张田田 7 месяцев назад
Родитель
Сommit
be30792438

+ 1 - 1
miniprogram/module/article/pages/order-detail/order-detail.scss

@@ -178,7 +178,7 @@
   justify-content: flex-end;
   align-items: center;
   font-size: 28rpx;
-  margin: 24rpx 0 0 0;
+  margin: 24rpx 0 32rpx 0;
 }
 
 .order-amount-value {

+ 79 - 7
miniprogram/module/chats/components/message-select/message-select.ts

@@ -32,6 +32,8 @@ Component({
     hasSelected: false,
     leftTitle: "都没有",
     rightTitle: "提交",
+    initialOptions: [] as Option[], // 保存初始状态
+    hasChanged: false, // 记录是否发生了变化
   },
   lifetimes: {
     attached() {
@@ -50,18 +52,66 @@ Component({
     },
   },
   observers: {
-    "payload.options"(options) {
+    "payload.options"(options: any) {
       this.setData({ options });
+      // 保存初始状态(深拷贝)
+      const initialOptions = JSON.parse(JSON.stringify(options));
+      this.setData({ initialOptions });
     },
     options(options: AnyArray) {
+      console.log("options", options);
+      const hasSelected = options
+        .filter((option: any) => !option.hide)
+        .some((option: any) => option.checked);
+      
+      // 检测是否与初始状态不同
+      const hasChanged = this._checkOptionsChanged(options, this.data.initialOptions);
+      
       this.setData({
-        hasSelected: options
-          .filter((option) => !option.hide)
-          .some((option) => option.checked),
+        hasSelected,
+        hasChanged,
       });
     },
   },
   methods: {
+    // 检测选项是否发生变化
+    _checkOptionsChanged(currentOptions: Option[], initialOptions: Option[]): boolean {
+      if (!initialOptions || initialOptions.length === 0) {
+        return false;
+      }
+      
+      // 比较主选项的选中状态
+      for (let i = 0; i < currentOptions.length; i++) {
+        const current = currentOptions[i];
+        const initial = initialOptions[i];
+        
+        if (!initial) continue;
+        
+        // 比较主选项的checked状态
+        if (current.checked !== initial.checked) {
+          return true;
+        }
+        
+        // 如果有子选项,比较子选项的选中状态
+        if (current.options && initial.options) {
+          for (let j = 0; j < current.options.length; j++) {
+            const currentSub = current.options[j];
+            const initialSub = initial.options[j];
+            
+            if (!initialSub) continue;
+            
+            if (currentSub.checked !== initialSub.checked) {
+              return true;
+            }
+          }
+        }
+      }
+      
+      return false;
+    },
+
+
+    
     handleTop(event: HandleEvent) {
       const {
         mark: { item },
@@ -80,6 +130,7 @@ Component({
       const hasAnySubChecked = itemInState?.options?.some(
         (o: any) => o?.checked
       );
+      console.log("itemInState", itemInState, hasSubOptions, hasAnySubChecked);
       if (itemInState?.checked && hasSubOptions && hasAnySubChecked) {
         this.setData({
           subTitle: itemInState.name,
@@ -113,6 +164,8 @@ Component({
         this.onSubmit();
       }
     },
+
+
     handleSub(event: HandleEvent) {
       const {
         mark: { item },
@@ -218,6 +271,7 @@ Component({
     onCancel() {},
     onConfirm() {},
     onSubmit() {
+      console.log("onSubmit", this.data.result, this.data.hasSelected);
       if (this.data.result) return;
       if (!this.data.hasSelected) {
         wx.showToast({ title: "请至少选择一项", icon: "error" });
@@ -233,14 +287,32 @@ Component({
             return [option.name, sub].filter(Boolean).join(": ");
           })
           .join("; ");
+        console.log("result", result);
         this.setData({ result });
         this.triggerEvent("next", { options: this.data.options });
       }
     },
     onSkip() {
-      if (this.data.result || this.data.hasSelected) return;
-      if (!this.data.payload.required) {
-        this.setData({ result: "都没有" });
+      console.log("onSkip", this.data.result, this.data.hasSelected);
+      if (this.data.result) return;
+      
+      // 如果是新用户(belongNew为true),使用原来的逻辑
+      if (this.data.payload.belongNew) {
+        if (this.data.hasSelected) return;
+        if (!this.data.payload.required) {
+          this.setData({ result: "都没有" });
+          this.triggerEvent("next", { options: this.data.options });
+        }
+      } else {
+        // 如果是老用户(belongNew为false),检查是否发生了变化
+        if (this.data.hasChanged) {
+          // 如果发生了变化,不允许点击"无变化"
+          // wx.showToast({ title: "症状已发生变化,请重新选择", icon: "none" });
+          return;
+        }
+        
+        // 如果没有变化,允许点击"无变化"
+        this.setData({ result: "无变化" });
         this.triggerEvent("next", { options: this.data.options });
       }
     },

+ 1 - 1
miniprogram/module/chats/components/message-select/message-select.wxml

@@ -38,7 +38,7 @@
       </grid-builder>
     </scroll-view>
     <view wx:if="{{payload.multiple || !payload.required}}" class="chat-card__handle {{active ? '' : 'disabled'}}">
-      <view wx:if="{{!payload.required}}" class="item {{hasSelected ? 'disabled': ''}}" bind:tap="onSkip">
+      <view wx:if="{{!payload.required}}" class="item {{(payload.belongNew ? hasSelected : hasChanged) ? 'disabled': ''}}" bind:tap="onSkip">
         <view class="not-change">{{leftTitle}}</view>
       </view>
       <view wx:if="{{payload.multiple}}" class="item" bind:tap="onSubmit">

+ 5 - 0
miniprogram/module/chats/components/questionnaire/questionnaire.ts

@@ -156,11 +156,13 @@ Component({
         [`_next.dialogId`]: "",
         [`_next.questions`]: [],
       });
+      this.triggerEvent("to", "bottom");
       this.triggerEvent("next", { component: "guide", scroll: true });
     },
     async _next() {
       let isAnalysis: number;
       isAnalysis = wx.getStorageSync("isAnalysis");
+      console.log("isAnalysis", isAnalysis, this.data._next);
       if (isAnalysis === 3 || isAnalysis === 4) {
         // 对话管家
         if (this.data._next.classify === "tongue") {
@@ -269,6 +271,7 @@ Component({
               }
             }
           });
+          console.log("最后一个问题", data,isAnalysis);
           // 对话管家
           if (
             (isAnalysis === 3 && data.classify === "report") ||
@@ -294,6 +297,8 @@ Component({
             [`_next.dialogId`]: data.dialogId,
             [`_next.questions`]: data.nextQuestions,
           });
+
+          console.log("页面向上移动", data,isAnalysis);
           this.triggerEvent("to");
         }
       } catch (error) {

+ 29 - 11
miniprogram/module/chats/pages/index/index.ts

@@ -107,18 +107,36 @@ Component({
     scrollIntoView(event?: ScrollIntoViewEvent) {
       clearTimeout(getScrollcontext.call(this).timer);
       const id = event?.detail ?? this.data.lastId;
-      getScrollcontext.call(this).timer = setTimeout(() => {
-        const scroll = getScrollcontext
-          .call(this)
-          .scroll;
+      const doScroll = (scroll: WechatMiniprogram.ScrollViewContext | undefined) => {
+        if (!scroll) return;
+        if (id === "bottom") {
+          scroll.scrollTo({ top: Number.MAX_SAFE_INTEGER, animated: true });
+        } else if (id) {
+          scroll.scrollIntoView(`#${id}`, { alignment: "end" });
+        }
+        setTimeout(() => {
+          if (id === "bottom") {
+            // scroll.scrollTo({ top: Number.MAX_SAFE_INTEGER, animated: true });
+            scroll.scrollIntoView(`#${id}`, { alignment: "end", animated: false as any });
+          } else if (id) {
+            scroll.scrollIntoView(`#${id}`, { alignment: "end", animated: false as any });
+          }
+        }, 200);
+      };
 
-        if(id === "bottom"){
-          scroll?.scrollTo({
-            top: Number.MAX_SAFE_INTEGER,
-            animated: true
-           })
-        }else{
-          scroll?.scrollIntoView(`#${id}`, { alignment: "end" });
+      getScrollcontext.call(this).timer = setTimeout(() => {
+        let scroll = getScrollcontext.call(this).scroll;
+        if (!scroll) {
+          // 若还未拿到scroll上下文,立即尝试获取后再滚动
+          wx.createSelectorQuery()
+            .select("#scrollview")
+            .node()
+            .exec((res) => {
+              getScrollcontext.call(this).scroll = res?.[0]?.node;
+              doScroll(getScrollcontext.call(this).scroll);
+            });
+        } else {
+          doScroll(scroll);
         }
       }, 300);
     },

+ 2 - 2
miniprogram/module/chats/pages/index/index.wxml

@@ -16,8 +16,6 @@
     scroll-y 
     enhanced="{{true}}" 
     enable-passive 
-    scroll-into-view="{{lastId}}" 
-    scroll-into-view-alignment="end" 
     style="height: calc(100vh - 180rpx); padding-bottom:{{paddingBottom}}rpx;"
   >
     <view class="system-wrapper">
@@ -30,6 +28,8 @@
       <chat-questionnaire wx:if="{{_.show(item, 'questionnaire') && messageType}}" id="{{item.id}}" active="{{_.active(lastId, item.id)}}" bind:next="handle" 
       bind:to="scrollIntoView" bind:nextType="nextType" messageType="{{messageType}}" workId="{{id}}" bind:boxBottom="boxBottom" />
     </block>
+    <!-- 固定底部锚点,便于 lastId='bottom' 时稳定滚动到最底部 -->
+    <view id="bottom" style="height: 1rpx;"></view>
   </scroll-view>
 
   <view class="tabbar-container">

+ 1 - 1
miniprogram/pages/home/home.scss

@@ -57,7 +57,7 @@
     background-color: #ffefef;
     border-radius: 6px;
     padding: 10rpx 30rpx 10rpx 10rpx;
-    height: 60px;
+    // height: 60px;
     font-weight: bold;
     border: 2px solid white;
     box-shadow: inset 0 0 3px rgb(255, 90, 30, 0.2);

+ 0 - 4
miniprogram/pages/home/home.ts

@@ -448,14 +448,11 @@ Page({
   },
 
   async _getHealthReport() {
-    console.log(1111);
     wx.showLoading({ title: "加载中" });
     this.setData({ "healthReport.loading": true });
     try {
-      console.log(2222);
       const data = await healthReportMethod();
 
-      console.log(data, "data===",!data);
       if (!data ) {
         this.setData({
           isShowComplete: true,
@@ -512,7 +509,6 @@ Page({
       //   });
       // }
     } catch (error: any) {
-      console.log(error, "error===");
       wx.showToast({
         title: error.errMsg || "加载失败",
         icon: "none",