|
|
@@ -1,8 +1,5 @@
|
|
|
// module/chats/components/message-select/message-select.ts
|
|
|
-import { Message } from "tdesign-miniprogram";
|
|
|
-import { getTickleContext } from "../../../../core/behavior/tickle.behavior";
|
|
|
import { Get, Post } from "../../../../lib/request/method";
|
|
|
-import Input from "../../../../miniprogram_npm/tdesign-miniprogram/input/input";
|
|
|
interface Option {
|
|
|
id: string;
|
|
|
name: string;
|
|
|
@@ -16,7 +13,6 @@ interface HandleEvent {
|
|
|
item: Option;
|
|
|
};
|
|
|
}
|
|
|
-const app = getApp();
|
|
|
Component({
|
|
|
properties: {
|
|
|
payload: {
|
|
|
@@ -28,11 +24,12 @@ Component({
|
|
|
workId: { type: Number, value: 0 },
|
|
|
},
|
|
|
data: {
|
|
|
+ placeholder: "请输入",
|
|
|
+ safeBottomRpx: 0,
|
|
|
// 键盘逻辑
|
|
|
- inputBoxBottom: 0,
|
|
|
+ inputBoxBottom: 0, //初始华底部的值
|
|
|
inputText: "",
|
|
|
messages: [],
|
|
|
- scrollTop: 0, // 滚动位置
|
|
|
showrePlenish: false,
|
|
|
inputFocus: false,
|
|
|
// end
|
|
|
@@ -65,39 +62,25 @@ Component({
|
|
|
symptomsList: [],
|
|
|
isHaveNewSyndrome: "",
|
|
|
isAnalysis: 0,
|
|
|
- shows: false,
|
|
|
+ InputHeight:0,
|
|
|
},
|
|
|
- attached(options: any) {
|
|
|
+ attached() {
|
|
|
this.setData({
|
|
|
isAnalysis: wx.getStorageSync("isAnalysis"),
|
|
|
});
|
|
|
- if (wx.getSystemInfoSync().platform === "ios") {
|
|
|
- this.setData({
|
|
|
- inputBoxBottom: 10,
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.setData({
|
|
|
- inputBoxBottom: 0,
|
|
|
- });
|
|
|
- }
|
|
|
- // 键盘===========================
|
|
|
- wx.onKeyboardHeightChange((res) => {
|
|
|
- console.log(res, "res1111111111111");
|
|
|
- const height = res.height;
|
|
|
- if (height > 0) {
|
|
|
- this.setData({
|
|
|
- // 某些机型需要在此处也设置键盘高度
|
|
|
- inputBoxBottom: height,
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.setData({
|
|
|
- // 某些机型需要在此处也设置键盘高度
|
|
|
- inputBoxBottom: 0,
|
|
|
- });
|
|
|
- }
|
|
|
+ const systemInfo = wx.getSystemInfoSync();
|
|
|
+ const windowHeight = systemInfo.windowHeight;
|
|
|
+ const safeAreaBottom = systemInfo.safeArea?.bottom ?? windowHeight; // 没有safeArea时,bottom等于windowHeight
|
|
|
+ const safeBottom = windowHeight - safeAreaBottom; // 安全区底部距离(px)
|
|
|
+ const tabBarHeight = 100; // 底部tabbar的高度
|
|
|
+ const safeBottomRpx = (750 / systemInfo.windowWidth) * safeBottom; // rpx
|
|
|
+ // 初始的底部bottom 底部安全区的高度+tabbar的高度
|
|
|
+ this.setData({
|
|
|
+ inputBoxBottom: safeBottomRpx + tabBarHeight,
|
|
|
+ safeBottomRpx: safeBottomRpx,
|
|
|
+ InputHeight:safeBottomRpx + tabBarHeight,
|
|
|
});
|
|
|
- console.log(this.data.inputBoxBottom, "刚进页面的高度");
|
|
|
- // end======================
|
|
|
+
|
|
|
this.setData({
|
|
|
hasSelected: this.data.options
|
|
|
.filter((option) => !option.hide)
|
|
|
@@ -114,36 +97,23 @@ Component({
|
|
|
.some((option) => option.checked),
|
|
|
});
|
|
|
},
|
|
|
- // 'messages':function(value: any) {
|
|
|
- // console.log(value, "messages11111");
|
|
|
- // if(value.length>0){
|
|
|
-
|
|
|
- // }
|
|
|
- // },
|
|
|
},
|
|
|
+
|
|
|
methods: {
|
|
|
- // 滚动到底部
|
|
|
- // scrollToBottom() {
|
|
|
- // // 创建一个选择器获取消息容器高度
|
|
|
- // const query = wx.createSelectorQuery();
|
|
|
- // query.select(".messages").boundingClientRect();
|
|
|
- // query.exec((res) => {
|
|
|
- // if (res && res[0]) {
|
|
|
- // this.setData({
|
|
|
- // scrollTop: res[0].height,
|
|
|
- // });
|
|
|
- // }
|
|
|
- // });
|
|
|
- // },
|
|
|
handleInput(e: any) {
|
|
|
- // console.log(e, "输入框输入内容");
|
|
|
this.setData({ inputText: e.detail.value });
|
|
|
},
|
|
|
// 发送信息
|
|
|
send() {
|
|
|
const text = this.data.inputText.trim();
|
|
|
+ // 如果输入框内容为空,则不发送信息
|
|
|
if (!text) {
|
|
|
wx.showToast({ title: "发送的信息不能为空", icon: "none" });
|
|
|
+ if (this.data.inputFocus) {
|
|
|
+ this.setData({
|
|
|
+ inputFocus: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
const userMessage = {
|
|
|
@@ -154,22 +124,15 @@ Component({
|
|
|
status: "sending",
|
|
|
};
|
|
|
this.setData({
|
|
|
- inputBoxBottom: 0,
|
|
|
messages: [...this.data.messages, userMessage],
|
|
|
- inputText: "",
|
|
|
- });
|
|
|
- this.triggerEvent("boxBottom", {
|
|
|
- inputBoxBottom: this.data.inputBoxBottom,
|
|
|
});
|
|
|
- // 保持键盘打开状态
|
|
|
- this.setData({ inputFocus: true });
|
|
|
if (this.data.messages.length === 2 && this.data.symptomResult === "有") {
|
|
|
this.setData({
|
|
|
showrePlenish: false,
|
|
|
});
|
|
|
this.triggerEvent("nextType", { MessageType: 2 });
|
|
|
this.triggerEvent("boxBottom", {
|
|
|
- inputBoxBottom: this.data.inputBoxBottom - 50,
|
|
|
+ inputBoxBottom: this.data.InputHeight - 60,
|
|
|
});
|
|
|
} else if (
|
|
|
this.data.messages.length === 1 &&
|
|
|
@@ -179,32 +142,52 @@ Component({
|
|
|
showrePlenish: false,
|
|
|
});
|
|
|
this.triggerEvent("nextType", { MessageType: 2 });
|
|
|
+ this.triggerEvent("boxBottom", {
|
|
|
+ inputBoxBottom: this.data.InputHeight - 60,
|
|
|
+ });
|
|
|
+ } else if (
|
|
|
+ this.data.messages.length === 1 &&
|
|
|
+ this.data.symptomResult === "有"
|
|
|
+ ) {
|
|
|
+ this.setData({
|
|
|
+ placeholder: "请问还有其他要补充的吗?",
|
|
|
+ inputBoxBottom: this.data.InputHeight,
|
|
|
+ });
|
|
|
+ this.triggerEvent("boxBottom", {
|
|
|
+ inputBoxBottom: this.data.InputHeight,
|
|
|
+ });
|
|
|
}
|
|
|
- // 滚动到底部
|
|
|
- // this.scrollToBottom();
|
|
|
+ this.triggerEvent("scroll", { id: "bottom" });
|
|
|
+ // 发送信息之后 输入框内容清空
|
|
|
+ this.setData({
|
|
|
+ inputText: "",
|
|
|
+ });
|
|
|
},
|
|
|
// 键盘聚焦
|
|
|
- onInputFocus(e) {
|
|
|
+ onInputFocus(e: any) {
|
|
|
+ const systemInfo = wx.getSystemInfoSync();
|
|
|
+ const height = (750 / systemInfo.windowWidth) * e.detail.height; // 转为rpx
|
|
|
this.setData({
|
|
|
- inputFocus: false,
|
|
|
- // 某些机型需要在此处也设置键盘高度
|
|
|
- inputBoxBottom: e.detail.height || this.data.inputBoxBottom,
|
|
|
+ inputFocus: true,
|
|
|
+ inputBoxBottom: height,
|
|
|
});
|
|
|
this.triggerEvent("boxBottom", {
|
|
|
- inputBoxBottom: this.data.inputBoxBottom,
|
|
|
+ inputBoxBottom: height,
|
|
|
});
|
|
|
+ this.triggerEvent("scroll", { id: "bottom" });
|
|
|
},
|
|
|
// 键盘失焦
|
|
|
- onInputBlur() {
|
|
|
+ onInputBlur(e: any) {
|
|
|
+ // 输入框失焦之后 底部高度是tabbar高度+安全区的高度
|
|
|
this.setData({
|
|
|
inputFocus: false,
|
|
|
- inputBoxBottom: 0,
|
|
|
+ inputBoxBottom: this.data.InputHeight,
|
|
|
});
|
|
|
this.triggerEvent("boxBottom", {
|
|
|
- inputBoxBottom: this.data.inputBoxBottom,
|
|
|
+ inputBoxBottom: this.data.InputHeight,
|
|
|
});
|
|
|
+ this.triggerEvent("scroll", { id: "bottom" });
|
|
|
},
|
|
|
- // end ============================
|
|
|
// 在字典中取症状的状态
|
|
|
async getStatus() {
|
|
|
const dict = await Get("/dict/getDicts", {
|
|
|
@@ -263,29 +246,36 @@ Component({
|
|
|
wx.showToast({ title: error.errMsg, icon: "error" });
|
|
|
}
|
|
|
},
|
|
|
- onChangeValue(e) {
|
|
|
+ // 选择有或没有
|
|
|
+ onChangeValue(e: any) {
|
|
|
this.setData({ value1: e.detail.value });
|
|
|
+ // 输入框底部的bottom也还是最初的inputBoxBottom就可以了
|
|
|
this.triggerEvent("boxBottom", {
|
|
|
inputBoxBottom: this.data.inputBoxBottom,
|
|
|
});
|
|
|
this.setData({
|
|
|
symptomResult: this.data.radioList.find(
|
|
|
- (item) => item.value === e.detail.value
|
|
|
+ (item: any) => item.value === e.detail.value
|
|
|
)?.label,
|
|
|
isHaveNewSyndrome: this.data.radioList.find(
|
|
|
- (item) => item.value === e.detail.value
|
|
|
+ (item: any) => item.value === e.detail.value
|
|
|
)?.id,
|
|
|
});
|
|
|
let followObj: any = {
|
|
|
isHaveNewSyndrome: this.data.isHaveNewSyndrome,
|
|
|
- symptomList: this.data.symptomsList,
|
|
|
+ symptomsList: this.data.symptomsList,
|
|
|
};
|
|
|
- // console.log(this.data.isHaveNewSyndrome, "this.data.isHaveNewSyndrome");
|
|
|
+ if (this.data.isHaveNewSyndrome === "N") {
|
|
|
+ this.setData({ placeholder: "请问还有其他要补充的吗?" });
|
|
|
+ } else {
|
|
|
+ this.setData({ placeholder: "请描述新的症状?" });
|
|
|
+ }
|
|
|
this.setData({ btnDisabled: true });
|
|
|
wx.setStorageSync("followObj", followObj);
|
|
|
this.setData({
|
|
|
showrePlenish: true,
|
|
|
});
|
|
|
+ this.triggerEvent("scroll", { id: "bottom" });
|
|
|
},
|
|
|
handleTop(event: HandleEvent) {
|
|
|
if (this.data.result) return;
|
|
|
@@ -340,7 +330,6 @@ Component({
|
|
|
multiple?: boolean
|
|
|
) {
|
|
|
const checked = !item.checked;
|
|
|
- console.log(checked, multiple, "_handle");
|
|
|
if (checked) {
|
|
|
const fn = () => {
|
|
|
if (multiple) {
|
|
|
@@ -358,12 +347,10 @@ Component({
|
|
|
subOptions: item.options,
|
|
|
subMultiple: true,
|
|
|
});
|
|
|
- // console.log(this.data.subMultiple, "subOptions", item.css);
|
|
|
this.onCancel = () => {
|
|
|
this.setData({ subOptions: [] });
|
|
|
};
|
|
|
this.onConfirm = () => {
|
|
|
- // console.log(this.data.subOptions, "subOptions", item.css);
|
|
|
if (!this.data.subOptions.some((option) => option.checked)) {
|
|
|
wx.showToast({ title: "请至少选择一项", icon: "error" });
|
|
|
} else {
|
|
|
@@ -418,15 +405,21 @@ Component({
|
|
|
}
|
|
|
});
|
|
|
this.setData({ symptomsList });
|
|
|
- this.triggerEvent("next", { options: this.data.options });
|
|
|
+ this.triggerEvent("scroll", { id: "bottom" });
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
onSkip() {
|
|
|
if (this.data.result || this.data.hasSelected) return;
|
|
|
if (!this.data.payload.required) {
|
|
|
this.setData({ result: "无变化" });
|
|
|
this.triggerEvent("next", { options: this.data.options });
|
|
|
}
|
|
|
+ this.triggerEvent("scroll", { id: "bottom" });
|
|
|
+ this.setData({ placeholder: "请问还有其他要补充的吗?" });
|
|
|
},
|
|
|
},
|
|
|
+ onUnload() {
|
|
|
+ wx.offKeyboardHeightChange(); // 解绑键盘高度变化监听
|
|
|
+ },
|
|
|
});
|