| | |
| | | <template> |
| | | <el-calendar ref="calendar"> |
| | | <template #header="{ date }"> |
| | | <span>æ¥åè§å¾</span> |
| | | <span>{{ date }}</span> |
| | | <el-button-group> |
| | | <el-button size="small" @click="selectDate('prev-year')"> |
| | | Previous Year1 |
| | | </el-button> |
| | | <el-button size="small" @click="selectDate('prev-month')"> |
| | | Previous Month1 |
| | | </el-button> |
| | | <el-button size="small" @click="selectDate('today')">Today</el-button> |
| | | <el-button size="small" @click="selectDate('next-month')"> |
| | | Next Month1 |
| | | </el-button> |
| | | <el-button size="small" @click="selectDate('next-year')"> |
| | | Next Year |
| | | </el-button> |
| | | </el-button-group> |
| | | </template> |
| | | <template #date-cell="{ data }"> |
| | | <p :class="data.isSelected ? 'is-selected' : ''"> |
| | | {{ data.day.split('-').slice(1).join('-') }} <br/> |
| | | 工使¥ |
| | | {{ data.isSelected ? 'âï¸' : '' }} |
| | | </p> |
| | | </template> |
| | | </el-calendar> |
| | | <div class="container"> |
| | | <div class="header"> |
| | | <div class="title">{{ nowYear }}å¹´{{ nowMonth }}æ</div> |
| | | <!-- <div class="btns"> |
| | | <button @click="toPrevMonth"> < </button> |
| | | <button @click="toToday"> ä»å¤© </button> |
| | | <button @click="toNextMonth"> > </button> |
| | | </div> --> |
| | | <div> |
| | | <el-date-picker |
| | | v-model="queryParams.monthDays" |
| | | type="month" |
| | | placeholder="éæ©æä»½" |
| | | @change="changeDate($event)" |
| | | /> |
| | | <el-select |
| | | clearable |
| | | v-model="queryParams.applicableFactory" |
| | | style="width: 160px; margin-left: 20px" |
| | | placeholder="请è¾å
¥éç¨å·¥å" |
| | | @change="changePlant($event)" |
| | | > |
| | | <el-option |
| | | v-for="plant in plantList" |
| | | :key="plant.id" |
| | | :label="plant.plantName" |
| | | :value="plant.plantCode" |
| | | > |
| | | </el-option> |
| | | </el-select> |
| | | </div> |
| | | </div> |
| | | <div class="calendar"> |
| | | <div class="itemWeeks" v-for="item in weeks" :key="item"> |
| | | {{ "å¨" + item }} |
| | | </div> |
| | | <!-- <div |
| | | class="item color_grey" |
| | | v-for="item in prefixView" |
| | | :key="item" |
| | | @click="toPrevMonth(item.day)" |
| | | > |
| | | {{ item.day.split("-")[2] }} {{ item.typeHoliday }} |
| | | </div> --> |
| | | <!-- :class="{ |
| | | today: |
| | | realDate.year === nowYear && |
| | | realDate.month === nowMonth && |
| | | realDate.date === item, |
| | | }" --> |
| | | <div |
| | | v-for="item in dateCalendarView" |
| | | :key="item" |
| | | class="item" |
| | | :class="{ |
| | | 'bg_success': item.type === '伿¯æ¥', |
| | | 'bg_primary': item.type === '工使¥', |
| | | 'bg_warn': item.type === 'è忥', |
| | | }" |
| | | > |
| | | <div |
| | | class="text_cell" |
| | | :class="{ |
| | | color_grey: |
| | | item.date.substring(0, 7) !== |
| | | dateStr(queryParams.monthDays).substring(0, 7), |
| | | }" |
| | | > |
| | | {{ item.date.split("-")[2] }} |
| | | </div> |
| | | <div class="text_cell_right">{{ item.type }}</div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | const calendar = ref() |
| | | const selectDate = (val) => { |
| | | if (!calendar.value) return |
| | | calendar.value.selectDate(val) |
| | | } |
| | | const isToday = (date) => { |
| | | const today = new Date(); |
| | | return date.getDate() === today.getDate() && |
| | | date.getMonth() === today.getMonth() && |
| | | date.getFullYear() === today.getFullYear(); |
| | | import { calendarView } from "@/api/basicData/calendar"; |
| | | import { listAll_plant } from "@/api/basicData/plant"; |
| | | const plantList = ref([]); |
| | | // ä»å¤©çå¹´ææ¥ |
| | | const realDate = { |
| | | year: new Date().getFullYear(), |
| | | month: (new Date().getMonth() + 1).toString().padStart(2, "0"), |
| | | date: new Date().getDate(), |
| | | }; |
| | | const queryParams = ref({ |
| | | monthDays: `${realDate.year}-${realDate.month}`, |
| | | applicableFactory: "æ²é³", |
| | | applicableFactoryCode: "FORTUNE", |
| | | }); |
| | | const weeks = ["æ¥", "ä¸", "äº", "ä¸", "å", "äº", "å
"]; |
| | | const now = ref(new Date()); |
| | | const dateCalendarView = ref([]); |
| | | const formatDateCalendar = (day) => { |
| | | dateCalendarView.value.map((item) => { |
| | | console.log(day.day, item.day); |
| | | if (day.day === item.day) { |
| | | return { |
| | | ...day, |
| | | ...item, |
| | | }; |
| | | } |
| | | }); |
| | | }; |
| | | // æ¬æ1å·æ¯å¨å |
| | | // const firstDateDay = computed(() => { |
| | | // return new Date(now.value.getFullYear(), now.value.getMonth(), 1).getDay(); |
| | | // }); |
| | | // // æ¬æçæ»å¤©æ° |
| | | // const days = computed(() => { |
| | | // return new Date( |
| | | // now.value.getFullYear(), |
| | | // now.value.getMonth() + 1, |
| | | // 0 |
| | | // ).getDate(); |
| | | // }); |
| | | // 宿¶è®¡ç®å½å页颿¾ç¤ºç年份 |
| | | const nowYear = computed(() => { |
| | | return dateStr(queryParams.value.monthDays).split("-")[0]; |
| | | }); |
| | | // 宿¶è®¡ç®å½å页颿¾ç¤ºçæä»½ |
| | | const nowMonth = computed(() => { |
| | | return dateStr(queryParams.value.monthDays).split("-")[1]; |
| | | }); |
| | | |
| | | const toPrevMonth = (date) => { |
| | | now.value = date |
| | | ? new Date(date.split("-")[0], parseInt(date.split("-")[1]) - 1, 1) |
| | | : new Date(now.value.getFullYear(), now.value.getMonth() - 1, 1); |
| | | }; |
| | | const toNextMonth = (date) => { |
| | | now.value = date |
| | | ? new Date(date.split("-")[0], parseInt(date.split("-")[1]) - 1, 1) |
| | | : new Date(now.value.getFullYear(), now.value.getMonth() + 1, 1); |
| | | }; |
| | | // åå°ä»å¤© |
| | | const toToday = () => { |
| | | now.value = new Date(); |
| | | console.log(now.value, "now.valuenow.value"); |
| | | }; |
| | | function dateStr(dateTimeString) { |
| | | const dateTime = new Date(dateTimeString); |
| | | // æå年份åæä»½ |
| | | const year = dateTime.getFullYear(); |
| | | const month = String(dateTime.getMonth() + 1).padStart(2, "0"); // æä»½ä»0å¼å§ï¼æä»¥éè¦å 1ï¼å¹¶ç¨padStartè¡¥é¶ |
| | | // æ ¼å¼å年份åæä»½ä¸º "yyyy-mm" æ ¼å¼çå符串 |
| | | return `${year}-${month}-01`; |
| | | } |
| | | async function changePlant(plant) { |
| | | queryParams.value.applicableFactoryCode = plant; |
| | | const res = await calendarView({ |
| | | effectiveDate: dateStr(queryParams.value.monthDays), |
| | | applicableFactory: plant, |
| | | }); |
| | | dateCalendarView.value = res.data; |
| | | } |
| | | async function changeDate(e) { |
| | | const res = await calendarView({ |
| | | effectiveDate: dateStr(queryParams.value.monthDays), |
| | | applicableFactory: queryParams.value.applicableFactoryCode, |
| | | }); |
| | | dateCalendarView.value = res.data; |
| | | } |
| | | onMounted(async () => { |
| | | const response = await listAll_plant({}); |
| | | plantList.value = response.data; |
| | | const res = await calendarView({ |
| | | effectiveDate: `${queryParams.value.monthDays}-01`, |
| | | applicableFactory: "FORTUNE", |
| | | }); |
| | | dateCalendarView.value = res.data; |
| | | }); |
| | | </script> |
| | | <style lang="scss" scoped> |
| | | .is-selected { |
| | | color: #1989fa; |
| | | |
| | | <style lang="scss"> |
| | | .container { |
| | | .header { |
| | | height: 60px; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: space-between; |
| | | padding: 20px; |
| | | .title { |
| | | font-size: 26px; |
| | | font-weight: 600; |
| | | } |
| | | .btns { |
| | | button { |
| | | height: 26px; |
| | | border-radius: 0; |
| | | margin: 0 2px; |
| | | cursor: pointer; |
| | | border-width: 1px; |
| | | } |
| | | } |
| | | } |
| | | .calendar { |
| | | display: flex; |
| | | flex-wrap: wrap; |
| | | border-bottom: 1px solid #ccc; |
| | | border-left: 1px solid #ccc; |
| | | .itemWeeks { |
| | | width: calc(100% / 7); |
| | | height: 40px; |
| | | line-height: 40px; |
| | | text-align: center; |
| | | border-top: 1px solid #ccc; |
| | | border-right: 1px solid #ccc; |
| | | } |
| | | .item { |
| | | width: calc(100% / 7); |
| | | height: 80px; |
| | | text-align: center; |
| | | border-top: 1px solid #ccc; |
| | | border-right: 1px solid #ccc; |
| | | & .color_grey { |
| | | color: #999; |
| | | } |
| | | .text_cell_right { |
| | | text-align: right; |
| | | margin-right:20px; |
| | | margin-top:20px; |
| | | } |
| | | .text_cell { |
| | | padding-top: 10px; |
| | | } |
| | | } |
| | | .today { |
| | | color: blue; |
| | | font-weight: 600; |
| | | } |
| | | } |
| | | } |
| | | .bg_success { |
| | | background: #f0f9eb; |
| | | color: #67c23a; |
| | | } |
| | | .bg_warn { |
| | | background: #fdf6ec; |
| | | color: #e6a23c; |
| | | } |
| | | .bg_primary { |
| | | background: #d8ebff; |
| | | color: #409EFF; |
| | | } |
| | | </style> |