></el-date-picker>
</span>
</li>
</ul>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="20" :offset="2" class="time-range">
<span
@click="pickTime(time, index)"
v-for="(time, index) in times"
:key="index"
:class="{active:index == tabTimeIndex}"
>{{time}}</span>
</el-col>
</el-row>
</div>
</template>
<script>
/* eslint-disable */
import moment from "moment";
export default {
props: {
dateValue: {
type: String,
default: moment(new Date()).format("YYYY-MM-DD")
},
timeValue: {
type: String,
default: "00:00"
}
},
data() {
return {
currentYear: 1970, // 年份
currentMonth: 1, // 月份
currentDay: 1, // 日期
currentWeek: 1, // 星期
days: [],
value1: "",
tabIndex: null,
tabTimeIndex: 0,
times: [
"00:00~06:00",
"06:00~12:00",
"12:00~18:00",
"18:00~24:00",
"今日节目"
] };
},
filters: {
dateFormat(date) {
return moment(date).format("YYYY-MM-DD");
},
getWeekFormat(date) {
const weeksObj = {
1: "周一",
2: "周二",
3: "周三",
4: "周四",
5: "周五",
6: "周六",
7: "周日"
};
let weekNumber = moment(date).isoWeekday();
return weeksObj[weekNumber];
}
}, mounted() {
const index = _.findIndex(this.days, function(o) {
// console.log('o: ', o.getDate());
// console.log('new Date().getDate(): ', new Date().getDate());
return o.getDate() === new Date().getDate();
});
console.log("index: ", index);
this.tabIndex = index;
},
created() {
this.initData(null);
},
methods: {
formatDate(year, month, day) {
const y = year;
let m = month;
if (m < 10) m = `0${m}`;
let d = day;
if (d < 10) d = `0${d}`;
return `${y}-${m}-${d}`;
},
pickDate(date) {
let newDate = moment(date).format("YYYY-MM-DD");
this.$emit("dateValue", newDate);
},
initData(cur) {
let date = "";
if (cur) {
date = new Date(cur);
} else {
date = new Date();
}
this.currentDay = date.getDate(); // 今日日期 几号
this.currentYear = date.getFullYear(); // 当前年份
this.currentMonth = date.getMonth() + 1; // 当前月份
this.currentWeek = date.getDay(); // 1...6,0 // 星期几
if (this.currentWeek === 0) {
this.currentWeek = 7;
}
const str = this.formatDate(
this.currentYear,
this.currentMonth,
this.currentDay
); // 今日日期 年-月-日
this.days.length = 0;
// 今天是周日,放在第一行第7个位置,前面6个 这里默认显示一周,如果需要显示一个月,则第二个循环为 i<= 35- this.currentWeek










