|
|
@@ -37,7 +37,6 @@ Component({
|
|
|
},
|
|
|
lifetimes: {
|
|
|
attached() {
|
|
|
- console.log("attached", this.data.payload.belongNew,this.data.payload);
|
|
|
if (this.data.payload.belongNew) {
|
|
|
this.setData({
|
|
|
leftTitle: "都没有",
|
|
|
@@ -59,14 +58,16 @@ Component({
|
|
|
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);
|
|
|
-
|
|
|
+ const hasChanged = this._checkOptionsChanged(
|
|
|
+ options,
|
|
|
+ this.data.initialOptions
|
|
|
+ );
|
|
|
+
|
|
|
this.setData({
|
|
|
hasSelected,
|
|
|
hasChanged,
|
|
|
@@ -75,50 +76,49 @@ Component({
|
|
|
},
|
|
|
methods: {
|
|
|
// 检测选项是否发生变化
|
|
|
- _checkOptionsChanged(currentOptions: Option[], initialOptions: Option[]): boolean {
|
|
|
+ _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 },
|
|
|
} = event;
|
|
|
- console.log("handleTop", item, this.data.active);
|
|
|
if (!item || !this.data.active) return;
|
|
|
- console.log("handleTop", this.data.subOptions);
|
|
|
const index = this.data.options.findIndex(
|
|
|
(option) => option.id === item.id
|
|
|
);
|
|
|
@@ -130,7 +130,6 @@ 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,
|
|
|
@@ -165,18 +164,14 @@ Component({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
-
|
|
|
handleSub(event: HandleEvent) {
|
|
|
const {
|
|
|
mark: { item },
|
|
|
} = event;
|
|
|
- console.log("handleSub", item, this.data.active);
|
|
|
if (!item || !this.data.active) return;
|
|
|
- console.log("this.data.subOptions", this.data.subOptions);
|
|
|
const index = this.data.subOptions.findIndex(
|
|
|
(option) => option.id === item.id
|
|
|
);
|
|
|
- console.log("index", index);
|
|
|
const multiple = this.data.subMultiple;
|
|
|
const checked = !item.checked;
|
|
|
const subOptions = this._handle(
|
|
|
@@ -186,8 +181,6 @@ Component({
|
|
|
multiple
|
|
|
);
|
|
|
this.setData({ subOptions });
|
|
|
- console.log(this.data.subOptions, "suboptions111");
|
|
|
-
|
|
|
// 检查是否所有症状程度都被取消选中
|
|
|
const hasAnySubChecked = subOptions.some((option) => option.checked);
|
|
|
if (!hasAnySubChecked) {
|
|
|
@@ -271,12 +264,10 @@ 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" });
|
|
|
} else {
|
|
|
- console.log(this.data.options);
|
|
|
const result = this.data.options
|
|
|
.filter((item: any) => item?.checked && !item?.hide)
|
|
|
.map((option: any) => {
|
|
|
@@ -287,15 +278,13 @@ Component({
|
|
|
return [option.name, sub].filter(Boolean).join(": ");
|
|
|
})
|
|
|
.join("; ");
|
|
|
- console.log("result", result);
|
|
|
this.setData({ result });
|
|
|
this.triggerEvent("next", { options: this.data.options });
|
|
|
}
|
|
|
},
|
|
|
onSkip() {
|
|
|
- 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;
|
|
|
@@ -310,7 +299,7 @@ Component({
|
|
|
// wx.showToast({ title: "症状已发生变化,请重新选择", icon: "none" });
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 如果没有变化,允许点击"无变化"
|
|
|
this.setData({ result: "无变化" });
|
|
|
this.triggerEvent("next", { options: this.data.options });
|