Commit 729f2a23 by chenwq

fix(FilterBar): 修复日期选择器最小/最大日期限制及选择器初始值问题

- 为月份选择器添加 minDate 配置支持,避免用户选择过早日期
- 修复日期选择器初始化时未正确设置 pickerViewValue 导致显示异常
- 修复选择器选项更新时序问题,确保选项先更新后设置选中索引
- 移除调试用的 console.log 语句,清理冗余注释代码
1 parent d41c75b0
...@@ -86,15 +86,35 @@ Component({ ...@@ -86,15 +86,35 @@ Component({
const filter = this.properties.filters[index]; const filter = this.properties.filters[index];
const currentValue = this.data.formData[filter.key]; const currentValue = this.data.formData[filter.key];
let minDate = new Date(2020, 0, 1).getTime();
let maxDate = new Date(new Date().getFullYear() + 5, 11, 31).getTime();
if (filter.minDate) {
let str = filter.minDate;
if (/^\d{4}-\d{2}$/.test(str)) str += "-01";
const d = new Date(str.replace(/-/g, "/"));
if (!isNaN(d.getTime())) minDate = d.getTime();
}
if (filter.maxDate) {
let str = filter.maxDate;
if (/^\d{4}-\d{2}$/.test(str)) str += "-01";
const d = new Date(str.replace(/-/g, "/"));
if (!isNaN(d.getTime())) maxDate = d.getTime();
}
this.setData({ this.setData({
activeFilterIndex: index, activeFilterIndex: index,
showPopup: true, showPopup: true,
formData: this.data.searchObj, formData: this.data.searchObj,
minDate,
maxDate
}); });
if (filter.type === "month") { if (filter.type === "month") {
this.initDatePicker(currentValue, filter.pickerType); this.initDatePicker(currentValue, filter.pickerType);
} else if (filter.type === "select") { } else if (filter.type === "select") {
console.log('99999')
this.initSelectPicker(currentValue); this.initSelectPicker(currentValue);
} }
}, },
...@@ -171,7 +191,7 @@ Component({ ...@@ -171,7 +191,7 @@ Component({
if (isNaN(val)) val = new Date().getTime(); if (isNaN(val)) val = new Date().getTime();
} }
} }
this.setData({ tempDateValue: val }); this.setData({ tempDateValue: val, pickerViewValue: val });
}, },
onDatePickChange(e) { onDatePickChange(e) {
this.setData({ tempDateValue: e.detail }); this.setData({ tempDateValue: e.detail });
...@@ -232,8 +252,11 @@ Component({ ...@@ -232,8 +252,11 @@ Component({
console.log(index, "index---"); console.log(index, "index---");
this.setData({ this.setData({
tempSelectIndex: index,
currentSelectOptions: optionList, // Store current optionList to use in wxml or change handler currentSelectOptions: optionList, // Store current optionList to use in wxml or change handler
}, () => {
this.setData({
tempSelectIndex: index
})
}); });
}, },
......
...@@ -16,6 +16,7 @@ Page({ ...@@ -16,6 +16,7 @@ Page({
type: "month", type: "month",
label: "月份", label: "月份",
key: "reviewMonth", key: "reviewMonth",
minDate: "2026-01",
}, },
{ {
type: "select", type: "select",
...@@ -110,7 +111,6 @@ Page({ ...@@ -110,7 +111,6 @@ Page({
// let total = 0; // let total = 0;
let list = []; let list = [];
let { code, data, message } = res; let { code, data, message } = res;
console.log(data)
if (code == 0) { if (code == 0) {
list = data; list = data;
// total = data.total; // total = data.total;
...@@ -128,7 +128,7 @@ Page({ ...@@ -128,7 +128,7 @@ Page({
flag: true, flag: true,
triggered: false, triggered: false,
// pageNum: pageNum + 1, // pageNum: pageNum + 1,
nothing: !!list.length nothing: !!list.length,
}); });
}); });
}, },
...@@ -165,7 +165,6 @@ Page({ ...@@ -165,7 +165,6 @@ Page({
handleDetail(e) { handleDetail(e) {
let { target } = e.currentTarget.dataset; let { target } = e.currentTarget.dataset;
console.log(target)
wx.navigateTo({ wx.navigateTo({
url: url:
"/packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit?info=" + "/packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit?info=" +
......
<!--packageWorkspace/pages/validReferralCount/referralCountList/referralCountList.wxml--> <!--packageWorkspace/pages/validReferralCount/referralCountList/referralCountList.wxml-->
<!-- <view class="container">
<view class="result-area" style="padding: 20rpx; margin-top: 20rpx;">
<view>筛选结果:</view>
<view>搜索内容:{{searchObj.merchantName || '无'}}</view>
<view>选中月份:{{searchObj.reviewMonth || '无'}}</view>
<view>选中状态:{{searchObj.status || '无'}}</view>
</view>
</view> -->
<view class="list-page"> <view class="list-page">
<view class="top-box"> <view class="top-box">
<FilterBar searchPlaceholder="门店名称" searchKey="merchantName" filters="{{filterConfig}}" searchObj="{{searchObj}}" bind:filterChange="onFilterChange"></FilterBar> <FilterBar searchPlaceholder="门店名称" searchKey="merchantName" filters="{{filterConfig}}" searchObj="{{searchObj}}" bind:filterChange="onFilterChange"></FilterBar>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!