|
@@ -55,10 +55,17 @@
|
|
|
<div class="field-row" v-if="region.phenologyId">
|
|
<div class="field-row" v-if="region.phenologyId">
|
|
|
<div class="field-label">{{ getPhenologyLabel(crop, region.phenologyId) }}</div>
|
|
<div class="field-label">{{ getPhenologyLabel(crop, region.phenologyId) }}</div>
|
|
|
<div class="field-value">
|
|
<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"
|
|
value-format="YYYY-MM-DD"
|
|
|
- :disabled-date="disabledFutureDate" />
|
|
|
|
|
|
|
+ :disabled-date="(time) => disabledFutureDate(time, crop, region)"
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -215,13 +222,22 @@ const handlePhenologyChange = (crop, region) => {
|
|
|
region.phenologyStartDate = getStartDate(crop, region.phenologyId);
|
|
region.phenologyStartDate = getStartDate(crop, region.phenologyId);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-// 禁用今天之后的日期;最早只能选到前 3 个月
|
|
|
|
|
-const disabledFutureDate = (time) => {
|
|
|
|
|
|
|
+// 禁用今天之后的日期;最早只能选到「该物候期默认开始时间」的前 3 个月
|
|
|
|
|
+// 如果没有物候期开始时间,则基于今天往前 3 个月
|
|
|
|
|
+const disabledFutureDate = (time, crop, region) => {
|
|
|
const today = new Date();
|
|
const today = new Date();
|
|
|
today.setHours(0, 0, 0, 0);
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
- // 三个月前的同一天(简单按 3 个月回退)
|
|
|
|
|
- const threeMonthsAgo = new Date(today);
|
|
|
|
|
|
|
+ // 基准开始时间:物候期默认开始日期
|
|
|
|
|
+ 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);
|
|
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
|
|
|
|
|
|
|
|
const t = time.getTime();
|
|
const t = time.getTime();
|