1.创建组件  components > calander > index.vue

<template>
<div class="page" v-if="show">
<div class="box">
<div class="box_head" v-if="!propshow">
<div class="font28" @click="calanderShowData">取消</div>
<div class="font28" @click="calanderSubmit">确定</div>
</div> <div class="box-flex">
<div class="flex-item item-content-current-day item-content-tit">
<div class="item-content titleHead">{{currentDate}}</div>
</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item">
<div class="item-content">一</div>
</div>
<div class="flex-item">
<div class="item-content">二</div>
</div>
<div class="flex-item">
<div class="item-content">三</div>
</div>
<div class="flex-item">
<div class="item-content">四</div>
</div>
<div class="flex-item">
<div class="item-content">五</div>
</div>
<div class="flex-item">
<div class="item-content">六</div>
</div>
<div class="flex-item">
<div class="item-content">日</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item flexData" v-for='(item, index) in currentDayList' :key='item' @click='itemFun(item.num,mouth[index],index, "first", item.state)' :class="{'hover-date': Section[index] && item.num, 'noBack': !item.state && item.num && !propshow}">
<div class="item-content red-background" v-if='currentDay === item.num && mouth[index].mouth === currentMouth.mouth && currentMouth.year === mouth[index].year' :class="{'hoverColorData' : Section[index] && item.num, 'hover-date':active[index]}">
<p>今天</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
<div class="item-content backgroundData" v-else :class="{'hover-date':active[index]}" >
<p>{{item.num}}</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
</div>
</div>
<div class="box">
<div class="box-flex">
<div class="flex-item item-content-current-day item-content-tit">
<div class="item-content titleHead">{{currentDateTwo}}</div>
</div> </div>
</div>
<div class="box-flex">
<div class="flex-item">
<div class="item-content">一</div>
</div>
<div class="flex-item">
<div class="item-content">二</div>
</div>
<div class="flex-item">
<div class="item-content">三</div>
</div>
<div class="flex-item">
<div class="item-content">四</div>
</div>
<div class="flex-item">
<div class="item-content">五</div>
</div>
<div class="flex-item">
<div class="item-content">六</div>
</div>
<div class="flex-item">
<div class="item-content">日</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item flexData" v-for='(item, index) in currentDayListData' :key='item' @click='itemFun(item.num,mouths[index],index, "last", item.state)' :class="{'hover-date': Sections[index] && item.num, 'noBack': !item.state && item.num && !propshow}">
<div class="item-content backgroundData" :class="{'hover-date':actives[index]}">
<p>{{item.num}}</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
</div>
</div> <div v-if="propshow" class="propshowData"></div>
</div>
</template> <script>
import vue from 'vue'
export default {
name: 'calander',
data () {
return {
calanderList: [],
show: false,
currentDate: '2017年05月03日',
currentDateTwo: '2017年06月03日',
dayList: '',
currentDayList: [],
currentObj: '',
currentDay: '',
mouth: [],
currentMouth: null,
hoverDate: {'date': null, 'mouth': null, 'year': null},
activeClick: 0,
active: [],
actives: [],
Section: [],
firstIndex: 0,
lastIndex: 0,
currentDayListData: [],
currentJudge: false,
currentObjNew: '',
Sections: [],
lastType: '',
fristType: '',
numArray: [],
numArrayTwo: []
}
},
props: {
propshow: false,
boothArray: [], // 从父级传来的数组,中主要携带number展位数,
calanderList: [],
yearAndmouthFirst: {},
yearAndmouthTwo: {},
calanderShow: false
},
mounted () {
let timeData = this.getNextMonth(new Date(),1)
var currentObj = this.getCurrentDayString()
this.currentDate = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日'
this.currentDateTwo = timeData.getFullYear() + '年' + (timeData.getMonth() + 1) + '月' + timeData.getDate() + '日' // this.currentObjNew = currentObj.getFullYear() + '/' + (currentObj.getMonth() + 2) + '/' + currentObj.getDate()
this.currentDay = currentObj.getDate() this.currentObj = currentObj
this.currentMouth = {
mouth: currentObj.getMonth() + 1,
year: currentObj.getFullYear()
} setTimeout(() => {
this.setSchedule(currentObj, 'newMonth')
this.setSchedule(this.getNextMonth(new Date(),1), 'nextMonth')
// this.setSchedule(new Date(this.currentObjNew), 'nextMonth')
},100);
},
methods: {
monthDay: function (year, month) {
month = parseInt(month, 10);
var d = new Date(year, month, 0); //这个是都可以兼容的
var date = new Date(year + "/" + month + "/0") //IE浏览器可以获取天数,谷歌浏览器会返回NaN
return d.getDate();
},
getNextMonth: function (date,length) {
let yy = date.getFullYear()
let mm = date.getMonth()
let dd = date.getDate() let nm= 0//目标月份
nm = mm+length
let nd = 0//目标天数
if(this.monthDay(yy,nm+1)<dd){
nd = this.monthDay(yy,nm+1)
}else{
nd = dd-1
} date.setDate(1)
date.setMonth(nm)
date.setDate(nd)
return date
},
calanderSubmit(){
console.log(this.numArray)
this.$emit('assignment', this.numArray)
},
calanderShowData(){
this.$emit('calanderShowClick', this.calanderShow)
},
formatTwo (n) {
if (n >= 10) return n
else return '0' + n
},
// 判断日历的当前日期是否不可点击
isDisabled (calander, index, item) {
// if (new Date(calander).getTime() < new Date().getTime()) {
// this.mouth[index].state = 'disabled'
// return false
// }
},
getWeekDayNextMonth(){
var myDate = new Date()
myDate.setMonth(myDate.getMonth() + 1);
myDate.setDate(1);
var weekDay=new Array(7, 1, 2, 3, 4, 5, 6)
return weekDay[myDate.getDay()];
},
itemFun (item, yearAndmouth, index, type, stateClick) {
if (stateClick) {
let dataD = new Date();
let curMonthDays = new Date(dataD.getFullYear(), (dataD.getMonth()+1), 0).getDate()
this.hoverDate = {'date': item, 'mouth': yearAndmouth.mouth, 'year': yearAndmouth.year} if (type == 'first') {
var activeArrayData = this.active
var SectionArrayData = this.Section
} else {
var activeArrayData = this.actives
var SectionArrayData = this.Sections
} if (this.activeClick == 0) {
this.yearAndmouthFirst = yearAndmouth
this.yearAndmouthFirst.date = item
for(let i=0; i<this.active.length; i++){
this.active[i] = false
vue.set(this.active, i, this.active[i])
}
for(let i=0; i<this.actives.length; i++){
this.actives[i] = false
vue.set(this.actives, i, this.actives[i])
}
for(let t=0; t<this.Section.length; t++){
this.Section[t] = false
vue.set(this.Section, t, this.Section[t])
}
for(let t=0; t<this.Sections.length; t++){
this.Sections[t] = false
vue.set(this.Sections, t, this.Sections[t])
}
this.numArray = []
this.activeClick = 1
this.fristType = type
this.firstIndex = item
this.yearFirst = yearAndmouth.year
this.mouthFirst = yearAndmouth.mouth activeArrayData[index] = true
vue.set(activeArrayData, index, activeArrayData[index])
this.numArray.push(this.yearAndmouthFirst)
console.log(this.numArray)
} else if (this.activeClick == 1){
this.numArray = []
this.yearAndmouthTwo = yearAndmouth
this.yearAndmouthTwo.date = item
if (this.firstIndex != index) {
this.activeClick = 0
this.lastIndex = item
this.lastType = type
this.yeaTwo = yearAndmouth.year
this.mouthTwo = yearAndmouth.mouth activeArrayData[index] = true
vue.set(activeArrayData, index, activeArrayData[index])
if (this.fristType == this.lastType) {
if (this.lastIndex > this.firstIndex) {
var indexCenter = this.lastIndex - this.firstIndex + 1
} else {
var indexCenter = this.firstIndex - this.lastIndex + 1
}
for(let j=0; j<indexCenter; j++){
if (this.lastIndex < this.firstIndex) {
var indexData = j + index
this.numArray.push({'date': item + j, 'mouth': yearAndmouth.mouth, 'year': yearAndmouth.year})
} else {
this.numArray.unshift({'date': item - j, 'mouth': yearAndmouth.mouth, 'year': yearAndmouth.year})
var indexData = index - j
}
SectionArrayData[indexData] = true
vue.set(SectionArrayData, indexData, SectionArrayData[indexData])
}
} else {
if (this.fristType == 'first') {
var indexCenter = curMonthDays - this.firstIndex + 1
var indexCenters = this.lastIndex
} else {
var indexCenter = curMonthDays - this.lastIndex + 1
var indexCenters = this.firstIndex
} for(let j=0; j<indexCenter; j++){
if (this.fristType == 'first') {
var indexData = this.firstIndex + j
this.numArray.push({'date': indexData, 'mouth': this.mouthFirst, 'year': this.yearFirst})
} else {
var indexData = this.lastIndex + j
this.numArray.push({'date': item + j, 'mouth': this.mouthTwo, 'year': this.yeaTwo})
}
this.Section[indexData + 1] = true
vue.set(this.Section, indexData, this.Section[indexData])
} var monthData = this.getWeekDayNextMonth()
for(let j=0; j<indexCenters; j++){
if (this.fristType == 'first') {
var indexDatas = j + monthData - 1
this.numArrayTwo.unshift({'date': item - j, 'mouth': this.mouthTwo, 'year': this.yeaTwo})
} else {
var indexDatas = this.firstIndex - j + monthData -2
this.numArrayTwo.unshift({'date': this.firstIndex - j , 'mouth': this.mouthFirst, 'year': this.yearFirst})
}
this.Sections[indexDatas] = true
vue.set(this.Sections, indexDatas, this.Sections[indexDatas])
}
}
this.numArray = this.numArray.concat(this.numArrayTwo)
}
}
}
},
doDay: function (e) {
var that = this
var currentObj = that.currentObj
var Y = currentObj.getFullYear()
var m = currentObj.getMonth() + 1
let newData = new Date
let newMonth=newData.getMonth()+1;
let d = currentObj.getDate()
var str = ''
if (e.currentTarget.dataset.key === 'left') {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
this.currentJudge = true
} else if(e.currentTarget.dataset.key === 'right') {
if (newMonth !== m) {
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
this.currentJudge = true
} else {
this.currentJudge = false
}
} else if (e.currentTarget.dataset.key === 'leftTwo'){
if (newMonth !== m) {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
this.currentJudge = true
} else {
this.currentJudge = false
}
} else if (e.currentTarget.dataset.key === 'rightTwo'){
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
this.currentJudge = true
}
if (this.currentJudge) {
currentObj = new Date(str)
this.currentDate = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日'
this.currentDateTwo = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 2) + '月' + currentObj.getDate() + '日'
this.currentObjNew = currentObj.getFullYear() + '/' + (currentObj.getMonth() + 2) + '/' + currentObj.getDate() + '/' this.currentObj = currentObj
if (e.currentTarget.dataset.key == 'left' || e.currentTarget.dataset.key == 'right') {
this.setSchedule(currentObj, 'newMonth')
} else {
this.setSchedule(new Date(this.currentObjNew), 'nextMonth')
}
}
},
getCurrentDayString: function () {
var objDate = this.currentObj
if (objDate !== '') {
return objDate
} else {
var cobj = new Date()
var a = cobj.getFullYear() + '/' + (cobj.getMonth() + 1) + '/' + cobj.getDate()
return new Date(a)
}
},
setSchedule: function (currentObj, type) {
var that = this
var m = currentObj.getMonth() + 1
var Y = currentObj.getFullYear()
var d = currentObj.getDate()
var newDate = new Date()
var newYear = newDate.getFullYear()
var newMonth = newDate.getMonth() + 1 // var dayString = Y + '/' + m + '/' + currentObj.getDate()
var currentDayNum = new Date(Y, m, 0).getDate()
var currentDayWeek = currentObj.getUTCDay() + 1 var result = currentDayWeek - (d % 7 - 1) var firstKey = result <= 0 ? 7 + result : result var currentDayListNew = [] var mouth = []
var f = 0
for (var i = 0; i < 42; i++) {
mouth[i] = {
'mouth': m,
'year': Y
}
currentDayListNew[i] = {
'num': '',
'number': '',
'state': false
}
if (i < firstKey - 1) {
currentDayListNew[i].num = ''
} else {
if (f < currentDayNum) {
currentDayListNew[i].num = f + 1
f = currentDayListNew[i].num
if (newYear == Y && newMonth == m) {
if (f >= d) {
currentDayListNew[i].state = true
}
} else {
if (f <= d) {
currentDayListNew[i].state = true
}
}
} else if (f >= currentDayNum) {
currentDayListNew[i].num = ''
}
if (this.boothArray.length > 0) {
this.boothArray.forEach((element, indexArray) => {
if (element.year == Y && element.mouth == m) {
if (element.date == currentDayListNew[i].num) {
currentDayListNew[i].number = String(element.number)
}
}
})
}
if (this.calanderList.length > 0) {
this.calanderList.forEach((element, indexList) => {
if (element.year == Y && element.mouth == m) {
if (element.date == currentDayListNew[i].num) {
if (type == 'newMonth') {
this.Section[i] = true
} else {
this.Sections[i] = true
}
}
}
});
}
}
} if (type == 'newMonth') {
that.currentDayList = currentDayListNew
that.mouth = mouth
} else {
that.currentDayListData = currentDayListNew
that.mouths = mouth
}
this.show = true
}
}
}
</script> <style scoped>
.box_head{
height: 1.173333rem /* 88/75 */;
background: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 .4rem /* 30/75 */;
border-bottom: .013333rem /* 1/75 */ solid #E5E5E5;
}
.noBack{
background: #bbb!important;
/* border-radius: 5px!important; */
}
.hoverColorData{
color: #fff!important;
}
.propshowData{
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: rgba(0, 0, 0, 0.1);
z-index: 9999;
}
.page{
background: #fff;
position: relative;
}
.titleHead{
margin: .266667rem /* 20/75 */ 0!important;
}
.sectionBack{
background: #8A2BE2;
}
page {
background-color: #2a8cef;
background:-webkit-gradient(linear, 0 0, 0 bottom, from(#2a8cef), to(#8A2BE2));
display: flex;
flex-direction: column;
width: 100%;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
font-size: 16px;
color: #222;
}
.disabled{
color: #ccc !important;
}
.hover-date{
background: #367EED;
color: #fff !important;
border-radius: 5px;
}
.box {
display: block;
/* margin: 10px; */
border-top: .013333rem /* 1/75 */ solid #efefef;
}
.glyphicon-triangle-left img{
transform:rotate(180deg)
}
.glyphicon img{
width:12px;
height: 19px;
margin-top:15px;
}
.box-flex {
display: -webkit-box;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
padding: 0 .133333rem /* 10/75 */;
} .flex-item {
flex-flow: nowrap;
flex-grow: 1;
flex-shrink: 1;
width: 14%;
margin: 1px 1px 1px 0px;
} .item-content {
margin: 1px;
padding: 5px 1px;
text-align: center;
/* height: 45px; */
/* line-height: 45px; */
font-size:14px;
position: relative;
flex-wrap: wrap;
justify-content: center;
}
.item-content i{
width:100%;
text-align: center;
left:0;
position: absolute;
top:8px;
}
.item-content span{
width:100%;
text-align: center;
left:0;
position: absolute;
top:3px;
font-size:12px;
color: #367EED;
line-height: 1;
}
.item-content-tit{
width:30%;
/* margin: .133333rem 10/75 0; */
}
.item-content-tit .item-content{
font-size:17px;
}
.red-background{
color:#367EED;
border-radius: 5px;
} .item-content-current-day {
flex-grow: 2;
}
</style>

2.页面中引用组件

<calander @assignment="assignment" :propshow="propshow" :boothArray="boothArray" :calanderList="calanderList"></calander> 

<script>
import calander from '@/components/calander'
export default {
components: {
calander
},
data() {
return {
calanderList: [],
boothArray: [],
propshow: false,
};
},
methods: {
assignment(){
// 组件调取父级方法
},
}
}
</script>

vue 模仿机票自定义日历组件,区间选择的更多相关文章

  1. vue里在自定义的组件上定义的事件

    事件分为原生事件和自定义事件. vue里在自定义的组件上定义的事件,都被认为是自定义事件,必须用$emit()来触发. 这也是子组件向父传值的原理. 如果想作为原生事件,需要在原生事件后面加上.nat ...

  2. Vue自定义日历组件

    今天给大家介绍Vue的日历组件,可自定义样式.日历类型及支持扩展,可自定义事件回调.Props数据传输. 线上demo效果 示例 Template: <Calendar :sundayStart ...

  3. vue自定义日历组件的实现

    实现一个日期组件,如图: components.js代码如下: Vue.component('sc-calendar',{ template:'<div class="scCalend ...

  4. vue 自定义日历组件

    <template> <div class=""> <div class="calendarTraffic" name=" ...

  5. 使用vue的v-model自定义 checkbox组件

    <template id='c'> <input type="checkbox" :checked="checked" v-on:change ...

  6. Vue.js 桌面端自定义滚动条组件|vue美化滚动条VScroll

    基于vue.js开发的小巧PC端自定义滚动条组件VScroll. 前段时间有给大家分享一个vue桌面端弹框组件,今天再分享最近开发的一个vue pc端自定义滚动条组件. vscroll 一款基于vue ...

  7. 【分享】Vue 资源典藏(UI组件、开发框架、服务端、辅助工具、应用实例、Demo示例)

    Vue 资源典藏,包括:UI组件 开发框架 服务端 辅助工具 应用实例 Demo示例 element ★11612 - 饿了么出品的Vue2的web UI工具套件 Vux ★7503 - 基于Vue和 ...

  8. 任务四十二:UI组件之日历组件(三)

    任务四十二:UI组件之日历组件(三) 面向人群: 有一定基础的同学 难度: 困难 重要说明 百度前端技术学院的课程任务是由百度前端工程师专为对前端不同掌握程度的同学设计.我们尽力保证课程内容的质量以及 ...

  9. vue自定义日期选择,类似美团日期选择,日历控件,vue日历区间选择

    一个日历的控件,基于vue的,可以日历区间选择,可用于酒店日历区间筛选,动手能力强,可以修改成小程序版本的,先上效果图 里面的颜色样式都是可以修改的 选择范围效果 话不多说,直接上干货,代码可以直接复 ...

随机推荐

  1. UCloud首尔机房整体热迁移是这样炼成的

    小结: 1.把两个机房在逻辑上变成一个机房: 2.新老机房的后端服务使用同一套 ZooKeeper,但是配置的却是不同的 IP: 3.UCloud内部服务所使用的数据库服务为MySQL, 内部MySQ ...

  2. 20165317Java实验五 网络编程与安全

    实验五 网络编程与安全 一.中缀转后缀 参考http://www.cnblogs.com/rocedu/p/6766748.html#SECDSA 结对实现中缀表达式转后缀表达式的功能 MyBC.ja ...

  3. C++提供的四种新式转换--const_cast dynamic_cast reinterpret_cast static_cast

    关于强制类型转换的问题,许多书都讨论过,写的最具体的是C++之父的<C++的设计和演化>. 最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_c ...

  4. MongoDB常用操作--简介

    mongodb在项目中使用越来越觉得日志方面的记录和查询是远远优于MySQL的,所以对其一些基本的操作进行了整理,以下就是整理的一些规则插入数据: insert插入多组数据:inserrAll修改数据 ...

  5. Archlinux软件包管理pacman基本使用说明

    熟悉APT和YUM包管理的应该都知道,这两个包管理的使用命令都是采用"主命令+参数"的格式,比如"sudo apt-get install --reinstall pac ...

  6. Cycle (KMP + hash)

    题意:给你2个串,让你判断2个字符串的前缀是否满足首尾连接形成的环是不是一样的. 思路:我们需要提前知道的是满足条件的前缀一定满足 strA = str1 + str2, strB = str2 + ...

  7. idea 更换svn地址

    右键项目-->Subversion-->Relocate 上面是旧的SVN地址,下面填入你要更换的目标SVN地址

  8. SpringMvc HandlerMappings 何时初始化?

    SpringMvc 的转发控制器 DispatcherServlet 执行 initStrategies(),在什么时候初始化 HandlerMappings ? 在容器 AbstractApplic ...

  9. 移动端热更新方案(iOS+Android)

    PPT资源包含iOS+Android 各种方案分析:https://github.com/qiyer/Share/blob/master/%E7%83%AD%E6%9B%B4%E6%96%B0%E5% ...

  10. springMVC学习之路2-文件上传

    springMVC的上传文件方式一共有两种,下面听我简单介绍一下: 1.1 首先配置springAnnotation-servlet.xml,新增一个multipartResolver处理器,并定义默 ...