|
@@ -18,95 +18,102 @@
|
|
|
<div class="date">
|
|
|
<div class="weeks date van-hairline--bottom">
|
|
|
<div
|
|
|
- class="day"
|
|
|
- @click="getDate(item)"
|
|
|
- v-for="(item, index) in weeks"
|
|
|
- :key='index'
|
|
|
+ class="day"
|
|
|
+ @click="getDate(item)"
|
|
|
+ v-for="(item, index) in weeks"
|
|
|
+ :key='index'
|
|
|
>{{item}}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div
|
|
|
- class="days"
|
|
|
- @touchstart='touchStart'
|
|
|
- @touchmove='touchMove'
|
|
|
- @touchend='touchEnd'
|
|
|
- v-if="daysShow"
|
|
|
+ class="days"
|
|
|
+ v-if="daysShow"
|
|
|
>
|
|
|
<div
|
|
|
- v-for="(items, i) in date"
|
|
|
- :key="i"
|
|
|
- class="date"
|
|
|
+ v-for="(items, i) in date"
|
|
|
+ :key="i"
|
|
|
+ class="date"
|
|
|
>
|
|
|
<div
|
|
|
- v-for="(item, index) in items"
|
|
|
- :key="index"
|
|
|
- class="day"
|
|
|
- :class="{'other':item.other}"
|
|
|
- @click.stop="onChange(item)"
|
|
|
+ v-for="(item, index) in items"
|
|
|
+ :key="index"
|
|
|
+ class="day"
|
|
|
+ :class="{'other':item.other}"
|
|
|
+ @touchstart.stop.prevent='touchStart($event)'
|
|
|
+ @touchmove.stop.prevent='touchMove($event)'
|
|
|
+ @touchend.stop.prevent='touchEnd($event, item)'
|
|
|
>
|
|
|
- <span class="text" :class="{'active':item.isWork}">{{item.day}}</span>
|
|
|
+ <span
|
|
|
+ class="text"
|
|
|
+ :class="{'active':item.isWork}"
|
|
|
+ >{{item.day}}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <div>
|
|
|
+ <div>开始{{startX}}</div>
|
|
|
+ <div>结束{{moveX}}</div>
|
|
|
+ <div>移动{{Math.abs(startX - moveX)}}</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
/**
|
|
|
- * 日期结构
|
|
|
- * 数据结构为二元数组,
|
|
|
- * 下面为数据中的某一个数组示例
|
|
|
- * [
|
|
|
- * ....星期....
|
|
|
- * {
|
|
|
- * year: 2018, // 哪一年
|
|
|
- * months: 12, // 哪一月
|
|
|
- * day: 15, // 几号
|
|
|
- * week: 6, // 星期几
|
|
|
- * isWork: true|false // 当天是否有派单
|
|
|
- * },
|
|
|
- * {
|
|
|
- * year: 2018, // 哪一年
|
|
|
- * months: 12, // 哪一月
|
|
|
- * day: 16, // 几号
|
|
|
- * week: 7, // 星期几
|
|
|
- * isWork: true|false // 当天是否有派单
|
|
|
- * },
|
|
|
- * {
|
|
|
- * year: 2018, // 哪一年
|
|
|
- * day: 17, // 几号
|
|
|
- * week: 1, // 星期几
|
|
|
- * months: 12, // 哪一月
|
|
|
- * isWork: true|false // 当天是否有派单
|
|
|
- * }
|
|
|
- * ......
|
|
|
- * ]
|
|
|
- */
|
|
|
-import moment from 'moment';
|
|
|
+ * 日期结构
|
|
|
+ * 数据结构为二元数组,
|
|
|
+ * 下面为数据中的某一个数组示例
|
|
|
+ * [
|
|
|
+ * ....星期....
|
|
|
+ * {
|
|
|
+ * year: 2018, // 哪一年
|
|
|
+ * months: 12, // 哪一月
|
|
|
+ * day: 15, // 几号
|
|
|
+ * week: 6, // 星期几
|
|
|
+ * isWork: true|false // 当天是否有派单
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * year: 2018, // 哪一年
|
|
|
+ * months: 12, // 哪一月
|
|
|
+ * day: 16, // 几号
|
|
|
+ * week: 7, // 星期几
|
|
|
+ * isWork: true|false // 当天是否有派单
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * year: 2018, // 哪一年
|
|
|
+ * day: 17, // 几号
|
|
|
+ * week: 1, // 星期几
|
|
|
+ * months: 12, // 哪一月
|
|
|
+ * isWork: true|false // 当天是否有派单
|
|
|
+ * }
|
|
|
+ * ......
|
|
|
+ * ]
|
|
|
+ */
|
|
|
+import moment from "moment";
|
|
|
// eslint-disable-next-line
|
|
|
- import {formatDate} from '@/util/index';
|
|
|
+import { formatDate } from "@/util/index";
|
|
|
|
|
|
export default {
|
|
|
- name: 'date-picker',
|
|
|
+ name: "date-picker",
|
|
|
data() {
|
|
|
return {
|
|
|
- year: '',
|
|
|
+ year: "",
|
|
|
date: [[], [], [], [], [], []],
|
|
|
- months: '',
|
|
|
- weeks: ['一', '二', '三', '四', '五', '六', '日'],
|
|
|
- days: '',
|
|
|
- day: '',
|
|
|
+ months: "",
|
|
|
+ weeks: ["一", "二", "三", "四", "五", "六", "日"],
|
|
|
+ days: "",
|
|
|
+ day: "",
|
|
|
daysShow: false,
|
|
|
startX: 0, // 开始触摸的位置
|
|
|
moveX: 0, // 滑动时的位置
|
|
|
endX: 0, // 结束触摸的位置
|
|
|
- disX: 0, // 移动距离
|
|
|
+ disX: 0 // 移动距离
|
|
|
};
|
|
|
},
|
|
|
props: {
|
|
|
period: Array,
|
|
|
start: Number,
|
|
|
- end: Number,
|
|
|
+ end: Number
|
|
|
},
|
|
|
created() {
|
|
|
// 初始化[年, 月, 日] 为当前时间
|
|
@@ -124,8 +131,8 @@ export default {
|
|
|
day: this.day,
|
|
|
year: this.year,
|
|
|
months: this.months,
|
|
|
- week: '',
|
|
|
- isWork: true,
|
|
|
+ week: "",
|
|
|
+ isWork: true
|
|
|
};
|
|
|
date.week = this.getWeek(this.setDate(date));
|
|
|
date.isWork = this.isServerWork(this.setDate(date), date.week);
|
|
@@ -135,14 +142,14 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
/**
|
|
|
- * 1 星期一
|
|
|
- * 2 星期二
|
|
|
- * 3 星期三
|
|
|
- * 4 星期四
|
|
|
- * 5 星期五
|
|
|
- * 6 星期六
|
|
|
- * 7 星期日
|
|
|
- */
|
|
|
+ * 1 星期一
|
|
|
+ * 2 星期二
|
|
|
+ * 3 星期三
|
|
|
+ * 4 星期四
|
|
|
+ * 5 星期五
|
|
|
+ * 6 星期六
|
|
|
+ * 7 星期日
|
|
|
+ */
|
|
|
init() {
|
|
|
for (let i = 0; i < 6; i += 1) {
|
|
|
this.date[i] = new Array(7);
|
|
@@ -157,13 +164,15 @@ export default {
|
|
|
const date = self.setDate({
|
|
|
year: self.year,
|
|
|
months: self.months,
|
|
|
- day: self.day,
|
|
|
+ day: self.day
|
|
|
}); // 2018-12-04
|
|
|
- // 获取上月天数
|
|
|
- let previousDays = moment(date)
|
|
|
- .subtract(1, 'month')
|
|
|
- .daysInMonth() + 1;
|
|
|
- // 获取指定月份天数
|
|
|
+ // 获取上月天数
|
|
|
+ // eslint-disable-next-line
|
|
|
+ let previousDays =
|
|
|
+ moment(date)
|
|
|
+ .subtract(1, "month")
|
|
|
+ .daysInMonth() + 1;
|
|
|
+ // 获取指定月份天数
|
|
|
self.days = moment(date).daysInMonth();
|
|
|
// 填充当月天数
|
|
|
let n = 0;
|
|
@@ -171,7 +180,7 @@ export default {
|
|
|
const dateInFor = self.setDate({
|
|
|
year: self.year,
|
|
|
months: self.months,
|
|
|
- day: i,
|
|
|
+ day: i
|
|
|
});
|
|
|
const dayInWeek = self.getWeek(dateInFor);
|
|
|
self.date[n][dayInWeek - 1] = {
|
|
@@ -181,7 +190,7 @@ export default {
|
|
|
other: false,
|
|
|
week: dayInWeek,
|
|
|
// 判断当天是否有服务
|
|
|
- isWork: self.isServerWork(dateInFor, dayInWeek),
|
|
|
+ isWork: self.isServerWork(dateInFor, dayInWeek)
|
|
|
};
|
|
|
if (dayInWeek === 7) {
|
|
|
n += 1;
|
|
@@ -189,10 +198,10 @@ export default {
|
|
|
}
|
|
|
// 给self.date[0]中填充上月天数
|
|
|
const firstDayInWeek = self.getWeek(
|
|
|
- self.setDate({ year: self.year, months: self.months, day: 1 }),
|
|
|
+ self.setDate({ year: self.year, months: self.months, day: 1 })
|
|
|
);
|
|
|
for (let i = firstDayInWeek; i > -1; i -= 1) {
|
|
|
- const getPreviousDate = self.getPreviousDate(previousDays -= 1);
|
|
|
+ const getPreviousDate = self.getPreviousDate((previousDays -= 1));
|
|
|
const dayInWeek = self.getWeek(self.setDate(getPreviousDate));
|
|
|
self.date[0][i - 2] = {
|
|
|
year: getPreviousDate.year,
|
|
@@ -200,7 +209,7 @@ export default {
|
|
|
day: previousDays,
|
|
|
week: dayInWeek,
|
|
|
other: true,
|
|
|
- isWork: self.isServerWork(self.setDate(getPreviousDate), dayInWeek),
|
|
|
+ isWork: self.isServerWork(self.setDate(getPreviousDate), dayInWeek)
|
|
|
};
|
|
|
}
|
|
|
// 给self.date填充下月天数
|
|
@@ -215,10 +224,10 @@ export default {
|
|
|
self.date[x][y] = {
|
|
|
year: getNextDate.year,
|
|
|
months: getNextDate.months,
|
|
|
- day: next += 1,
|
|
|
+ day: (next += 1),
|
|
|
week: dayInWeek,
|
|
|
other: true,
|
|
|
- isWork: self.isServerWork(self.setDate(getNextDate), dayInWeek),
|
|
|
+ isWork: self.isServerWork(self.setDate(getNextDate), dayInWeek)
|
|
|
};
|
|
|
}
|
|
|
}
|
|
@@ -262,7 +271,7 @@ export default {
|
|
|
// 设置指定日期
|
|
|
setDate(date) {
|
|
|
return `${date.year}-${this.setMonths(date.months)}-${this.setDays(
|
|
|
- date.day,
|
|
|
+ date.day
|
|
|
)}`;
|
|
|
},
|
|
|
// 处理月份字符串格式: 2 ==> 02
|
|
@@ -285,7 +294,7 @@ export default {
|
|
|
const date = {
|
|
|
months: 0,
|
|
|
year: 0,
|
|
|
- day: d,
|
|
|
+ day: d
|
|
|
};
|
|
|
if (this.months === 1) {
|
|
|
date.months = 12;
|
|
@@ -301,7 +310,7 @@ export default {
|
|
|
const date = {
|
|
|
year: 0,
|
|
|
months: 0,
|
|
|
- day: d,
|
|
|
+ day: d
|
|
|
};
|
|
|
if (this.months === 12) {
|
|
|
date.months = 1;
|
|
@@ -318,7 +327,7 @@ export default {
|
|
|
const dayToTime = moment(date).valueOf() / 1000;
|
|
|
let isServerWork = false;
|
|
|
// 判断当前日期是否为服务日期
|
|
|
- this.period.forEach((value) => {
|
|
|
+ this.period.forEach(value => {
|
|
|
if (value === window.Number.parseInt(dayInWeek)) {
|
|
|
if (dayToTime > self.start && dayToTime < this.end) {
|
|
|
isServerWork = true;
|
|
@@ -330,121 +339,145 @@ export default {
|
|
|
},
|
|
|
// 回调
|
|
|
onChange(item) {
|
|
|
- this.$emit('time', item);
|
|
|
+ console.log(338);
|
|
|
+ this.$emit("time", item);
|
|
|
},
|
|
|
// 滑动事件
|
|
|
touchStart(event) {
|
|
|
- // ev = ev || event;
|
|
|
- event.preventDefault();
|
|
|
if (event.touches.length === 1) {
|
|
|
this.startX = event.touches[0].clientX; // 记录开始位置
|
|
|
}
|
|
|
},
|
|
|
touchMove(event) {
|
|
|
- event.preventDefault();
|
|
|
if (event.touches.length === 1) {
|
|
|
- this.moveX = event.touches[0].clientX;
|
|
|
+ this.moveX = Math.abs(event.touches[0].clientX);
|
|
|
}
|
|
|
},
|
|
|
- touchEnd(event) {
|
|
|
- event.preventDefault();
|
|
|
+ touchEnd(event, item) {
|
|
|
+ const self = this;
|
|
|
+ //
|
|
|
+ console.clear();
|
|
|
+ if (self.moveX === 0 || self.startX === self.moveX) {
|
|
|
+ self.onChange(item);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 滑动结束
|
|
|
if (event.changedTouches.length === 1) {
|
|
|
- this.disX = this.startX - this.moveX;
|
|
|
- const percentage = Math.abs(this.disX) / window.innerWidth * 100 > 10;
|
|
|
- if (this.disX > 0) {
|
|
|
- if (percentage) {
|
|
|
- this.setNext();
|
|
|
- }
|
|
|
- } else if (percentage) {
|
|
|
- this.setPrevious();
|
|
|
+ self.disX = self.startX - self.moveX;
|
|
|
+ // eslint-disable-next-line
|
|
|
+ const percentage =
|
|
|
+ Math.floor((Math.abs(self.disX) / window.innerWidth) * 100) > 20;
|
|
|
+ // console.log(`开始:${self.startX}`);
|
|
|
+ // console.log(`结束:${self.moveX}`);
|
|
|
+ // console.log(`位移:${Math.abs(self.startX - self.moveX)}`);
|
|
|
+ // console.log(
|
|
|
+ // `比例:${(Math.abs(self.startX - self.moveX) / window.innerWidth) *
|
|
|
+ // 100}`
|
|
|
+ // );
|
|
|
+ // console.log(`是否滑动:${percentage}`);
|
|
|
+ self.$nextTick(() => {
|
|
|
+ self.startX = 0;
|
|
|
+ self.moveX = 0;
|
|
|
+ console.log(376);
|
|
|
+ });
|
|
|
+ if (!percentage) return;
|
|
|
+ // 向左
|
|
|
+
|
|
|
+ // 下一个月
|
|
|
+ if (self.disX > 0) {
|
|
|
+ self.setNext();
|
|
|
+ } else {
|
|
|
+ // 上一个月
|
|
|
+ self.setPrevious();
|
|
|
}
|
|
|
}
|
|
|
- },
|
|
|
- },
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="less" scoped>
|
|
|
- @import "../assets/style/vant.less";
|
|
|
+@import "../assets/style/vant.less";
|
|
|
|
|
|
- .date-picker-wrapper {
|
|
|
- .date {
|
|
|
- display: flex;
|
|
|
- justify-content: center;
|
|
|
- align-items: center;
|
|
|
- width: 100%;
|
|
|
- line-height: 30px;
|
|
|
- .day {
|
|
|
- flex: 1;
|
|
|
+.date-picker-wrapper {
|
|
|
+ .date {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ width: 100%;
|
|
|
+ line-height: 30px;
|
|
|
+ .day {
|
|
|
+ flex: 1;
|
|
|
+ text-align: center;
|
|
|
+ font-size: @inputSize;
|
|
|
+ transform: rotate3d(0, 0, 0);
|
|
|
+ transition: all 0.3s ease-in;
|
|
|
+ width: calc(100% / 7);
|
|
|
+ height: 40px;
|
|
|
+ position: relative;
|
|
|
+ border-right: 1px solid black;
|
|
|
+ border-bottom: 1px solid black;
|
|
|
+ box-sizing: border-box;
|
|
|
+ .text {
|
|
|
+ position: absolute;
|
|
|
+ z-index: 1;
|
|
|
+ width: 25px;
|
|
|
+ height: 25px;
|
|
|
+ line-height: 25px;
|
|
|
text-align: center;
|
|
|
- font-size: @inputSize;
|
|
|
- transform: rotate3d(0, 0, 0);
|
|
|
- transition: all .3s ease-in;
|
|
|
- width: calc(100% / 7);
|
|
|
- height: 40px;
|
|
|
- position: relative;
|
|
|
- border-right: 1px solid black;
|
|
|
- border-bottom: 1px solid black;
|
|
|
- box-sizing: border-box;
|
|
|
- .text {
|
|
|
- position: absolute;
|
|
|
- z-index: 1;
|
|
|
- width: 25px;
|
|
|
- height: 25px;
|
|
|
- line-height: 25px;
|
|
|
- text-align: center;
|
|
|
- transform: translate(-50%, 25%);
|
|
|
- }
|
|
|
+ transform: translate(-50%, 25%);
|
|
|
+ }
|
|
|
+ .active {
|
|
|
+ color: red;
|
|
|
+ }
|
|
|
+ &.other {
|
|
|
+ color: white;
|
|
|
+ background-color: #c6c6c6;
|
|
|
.active {
|
|
|
- color: red;
|
|
|
- }
|
|
|
- &.other {
|
|
|
- color: white;
|
|
|
- background-color: #c6c6c6;
|
|
|
- .active {
|
|
|
- color: #8d8d8d;
|
|
|
- }
|
|
|
- }
|
|
|
- &:last-child {
|
|
|
- border-right: 0;
|
|
|
+ color: #8d8d8d;
|
|
|
}
|
|
|
}
|
|
|
&:last-child {
|
|
|
- .day {
|
|
|
- border-bottom: 0;
|
|
|
- }
|
|
|
+ border-right: 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ &:last-child {
|
|
|
+ .day {
|
|
|
+ border-bottom: 0;
|
|
|
}
|
|
|
}
|
|
|
- .bar-nav-wrapper {
|
|
|
+ }
|
|
|
+ .bar-nav-wrapper {
|
|
|
+ display: flex;
|
|
|
+ padding: 10px 0;
|
|
|
+ text-align: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ .flex {
|
|
|
+ width: calc(100% / 3);
|
|
|
display: flex;
|
|
|
- padding: 10px 0;
|
|
|
- text-align: center;
|
|
|
- justify-content: space-between;
|
|
|
- .flex {
|
|
|
- width: calc(100% / 3);
|
|
|
- display: flex;
|
|
|
+ & > div {
|
|
|
+ flex: 1;
|
|
|
+ font-size: @inputSize;
|
|
|
+ line-height: 20px;
|
|
|
+ }
|
|
|
+ &:nth-child(2) {
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+ &:nth-child(1),
|
|
|
+ &:nth-child(3) {
|
|
|
+ flex: 0 0 100px;
|
|
|
& > div {
|
|
|
- flex: 1;
|
|
|
- font-size: @inputSize;
|
|
|
- line-height: 20px;
|
|
|
- }
|
|
|
- &:nth-child(2) {
|
|
|
- flex: 1;
|
|
|
- }
|
|
|
- &:nth-child(1), &:nth-child(3) {
|
|
|
- flex: 0 0 100px;
|
|
|
- & > div {
|
|
|
- flex: 0 0 40px;
|
|
|
- }
|
|
|
+ flex: 0 0 40px;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- .weeks {
|
|
|
- background-color: #eee;
|
|
|
- line-height: 40px;
|
|
|
- border-bottom: 1px solid black;
|
|
|
- .day {
|
|
|
- background-color: #eee !important;
|
|
|
- }
|
|
|
+ }
|
|
|
+ .weeks {
|
|
|
+ background-color: #eee;
|
|
|
+ line-height: 40px;
|
|
|
+ border-bottom: 1px solid black;
|
|
|
+ .day {
|
|
|
+ background-color: #eee !important;
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
</style>
|