|
|
@@ -44,7 +44,8 @@
|
|
|
<div class="field-row">
|
|
|
<div class="field-label">当下物候期</div>
|
|
|
<div class="field-value">
|
|
|
- <el-select v-model="region.phenologyId" class="select-input" placeholder="选择物候期">
|
|
|
+ <el-select
|
|
|
+ v-model="region.phenologyId" @change="handlePhenologyChange(crop, region)" class="select-input" placeholder="选择物候期">
|
|
|
<el-option v-for="(item, index) in crop.phenologyOptions" :key="index"
|
|
|
:label="item.phenologyName" :value="item.phenologyId" />
|
|
|
</el-select>
|
|
|
@@ -54,10 +55,17 @@
|
|
|
<div class="field-row" v-if="region.phenologyId">
|
|
|
<div class="field-label">{{ getPhenologyLabel(crop, region.phenologyId) }}</div>
|
|
|
<div class="field-value">
|
|
|
- <el-date-picker :editable="false" style="width: 100%" v-model="region.phenologyStartDate"
|
|
|
- class="date-picker" type="date" placeholder="选择时间" format="YYYY-MM-DD"
|
|
|
+ <el-date-picker
|
|
|
+ :editable="false"
|
|
|
+ style="width: 100%"
|
|
|
+ v-model="region.phenologyStartDate"
|
|
|
+ class="date-picker"
|
|
|
+ type="date"
|
|
|
+ placeholder="选择时间"
|
|
|
+ format="YYYY-MM-DD"
|
|
|
value-format="YYYY-MM-DD"
|
|
|
- :disabled-date="disabledFutureDate" />
|
|
|
+ :disabled-date="(time) => disabledFutureDate(time, crop, region)"
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -202,11 +210,38 @@ const getPhenologyLabel = (farm, phenologyId) => {
|
|
|
return found?.startDateLabel || "选择时间";
|
|
|
};
|
|
|
|
|
|
-// 禁用今天之后的日期:只能选择今天及之前
|
|
|
-const disabledFutureDate = (time) => {
|
|
|
+const getStartDate = (farm, phenologyId) => {
|
|
|
+ if (!farm?.phenologyOptions) return "";
|
|
|
+ const found = farm.phenologyOptions.find(
|
|
|
+ (item) => item.id === phenologyId || item.phenologyId === phenologyId
|
|
|
+ );
|
|
|
+ return found?.startDate || "";
|
|
|
+};
|
|
|
+
|
|
|
+const handlePhenologyChange = (crop, region) => {
|
|
|
+ region.phenologyStartDate = getStartDate(crop, region.phenologyId);
|
|
|
+};
|
|
|
+
|
|
|
+// 禁用今天之后的日期;最早只能选到「该物候期默认开始时间」的前 3 个月
|
|
|
+// 如果没有物候期开始时间,则基于今天往前 3 个月
|
|
|
+const disabledFutureDate = (time, crop, region) => {
|
|
|
const today = new Date();
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
- return time.getTime() > today.getTime();
|
|
|
+
|
|
|
+ // 基准开始时间:物候期默认开始日期
|
|
|
+ const baseStartStr = getStartDate(crop, region.phenologyId);
|
|
|
+ const baseStart = baseStartStr ? new Date(baseStartStr) : null;
|
|
|
+
|
|
|
+ // 选择基准日期:有物候期开始时间则用它,否则用今天
|
|
|
+ const base = !baseStart || isNaN(baseStart.getTime()) ? new Date(today) : new Date(baseStart);
|
|
|
+ base.setHours(0, 0, 0, 0);
|
|
|
+
|
|
|
+ // 三个月前的同一天(基于 base)
|
|
|
+ const threeMonthsAgo = new Date(base);
|
|
|
+ threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
|
|
|
+
|
|
|
+ const t = time.getTime();
|
|
|
+ return t > today.getTime() || t < threeMonthsAgo.getTime();
|
|
|
};
|
|
|
|
|
|
const showTipPopup = ref(false);
|