1.日期控件中添加:picker-options屬性,即:picker-options=“myPickerOptions”
<el-date-picker:class="item.scds !=null ?'xtsjBlue':'xtsjRed'"v-model="item.date"value-format="yyyy-MM-dd"type="date":picker-options="pickerOptions"placeholder="選擇日期" @change="bsdsChange(item)"></el-date-picker>
2.在data中定義要標記的日期數組hasXtdsDate,及myPickerOptions處理邏輯,篩選出要標記的日期數組
hasXtdsDate:[],//要標記的數組
pickerOptions: {cellClassName: time => {const month = time.getMonth() + 1;const day = time.getDate();const val = time.getFullYear() + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);if (this.hasXtdsDate.indexOf(val) >= 0){return 'hasXtdsDateClass'; //有系統讀數的日期顯示藍色}else {return 'noXtdsDateClass' //沒有系統讀數的日期顯示紅色}}}
3.對要進行標記的日期進行數據篩選
this.meterList = res.bcdsres.bcds.forEach(o=>{o.taskId = row.ido.planId = row.planIdo.industrialUserId = row.industrialUserIdif(o.xtds !=null || o.xtds !=''){this.hasXtdsDate.push(o.date)}})
4.自定義日期標記的樣式
<style lang="scss">.hasXtdsDateClass > div > span:after {content: "?";color: blue;bottom: -16px;position: absolute;font-size: 20px;left: 10px;}
.noXtdsDateClass > div > span:after {content: "?";color: red;bottom: -16px;position: absolute;font-size: 20px;left: 10px;
}
</style>
效果如下圖: