vue 里面日历能够自定义价格

cell-month 组件

<template>
	<div class="cell-month">
		<div class="weeklist">
      <!--星期几-->
			<div class="week_box">
        <p v-for="(item,index) in weekData">
          {{item}}
        </p>
      </div>

      <!--slot插入时间-->
      <slot slot="select_month"></slot>

      <!--具体的时间-->
			<div class="monthDayList">
				<div
          v-for="(item,index) in daysData" class="dayList"
          @click="selectDate(item,index)"
          :class="{selectDay:isSelect == index,unData:item.day == ' '}">
				<p :class="item.price?'':'hui_color'">{{item.day}}</p>
				<span :class="item.price?'':'hidden'">{{item.price}}</span>
			   </div>
			</div>

		</div>
	</div>
</template>

<script>
	export default{

		props:{
			dateData: Array,
			day:String,
		},

		data(){

		return{
			weekData:['日','一','二','三','四','五','六'],
			currentDay: this.day,
			DaysInMonth:[],
			daysData:[],
			priceData:this.dateData,
      isSelect :-1,
      undate :1,
		 }
		},
		methods:{
			getYearMonthDay(){
			 let currentYear = this.$data.currentDay.substring(0,4); //当前年份
			 let currentMonth = this.$data.currentDay.substring(5,7); //当前月份
			//判断是否是闰年
			  if (this.isleapYears(currentYear)) {
			  	this.$data.DaysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
			  }else{
			  	this.$data.DaysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
			  }
             let monthDay = this.$data.DaysInMonth[Number(currentMonth)-1];//当前月的天数
             let daysData = [];
              //给数据源赋值
             for (var i = 0 ;i < Number(monthDay) ;i++) {
             	var priceDict = {'day':String(i+1),'price':0};
             	daysData.push(priceDict);
             }
             this.$data.daysData = daysData;
             var currentDay = `${currentYear}-${currentMonth}-01`;
              var dateObject = new Date(currentDay);
              var firstDay = dateObject.getDay();//得到每个月1号是周几
              for (var i  in this.$data.priceData) {
              	var price = this.$data.priceData[i];
              	var dayIndex = price.dateStr.substring(price.dateStr.length-2,price.dateStr.length);
              	var dayDict = daysData[Number(dayIndex)-1];
              	dayDict.price = price.price;
              }
             if (firstDay > 0) {
             	var firstDayData = [];
             	for (var i=0; i< firstDay;i++) {
             		var dict = {'day':' ',price:' '};
             		firstDayData.push(dict);
             	}
             	this.$data.daysData = firstDayData.concat(daysData);
             }else{
             	this.$data.daysData = daysData;
             }
			},
			isleapYears(year){
				if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)) {
					return true;
				} else{
					return false;
				}
			},
			selectDate(item,index){

			  if(!item.price){
			    return
        }else{
          if (this.$data.daysData[index].day == 0) {
            return;
          }
          this.$data.isSelect = index;
          this.$store.commit('SetTicketPrice',item)
        }
				// this.back();
			},

		},

		created(){
			this.getYearMonthDay();
      // console.log(this.priceData)
		}

	}
</script>

<style scoped lang="less">
	.weeklist{
    .week_box{
      line-height: 42px;
      border:1px solid #eee;
      display: flex;
      p{
        float: left;
        width: 14%;
        padding-left: 10px;
        padding-right: 10px;
        color: #999999;
        text-align: center;
        .font11;
        &:nth-child(1),&:last-child{
          color:#B49C63;
        }
      }
    }
		background-color: white;

	}

	.dayList{
		position: relative;
		float: left;
		width: 14%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 50px;
		p{
      float: initial;
      width: 100%;
			text-align: center;
			padding: 0 0 0 0;
      font-size: 15px;
      color:#222222;
		}
    span{
      font-size: 11px;
      color:#FF5858;
      &.hidden{
        opacity: 0;
      }
    }

	}
	.monthDayList{
		background-color: #fff;
    overflow: hidden;
	}

	.selectDay{
		background-color: #B49C63;
		p{
			color: #fff;
		}
    span{
      color: #fff;
    }
	}

	.unData{
		p{
			color: white;
		}
	}
  .hui_color{
    color:#999999 !important;
  }



</style>

  页面引用

<div class="data_model">
            <div class="calender-content">
              <!--选择日期 取消按钮-->
              <div class="text_title">
                <b>选择日期</b>
                <span @click="show_date_model = false">取消</span>
              </div>

              <cell-month
                v-for = "(item,index) in classArray"
                :dateData= "item" :day = "item[0].dateStr"
                v-if = "index === selectMonth" :key = "index">
                <slot name="select_month">
                  <!--包含的日期-->
                  <div class="detail_time">
                    <div class="allMounth"
                         v-for="(item , index) in dateArray"
                         @click="selectMounth(index)">
                      <p :class="index === selectMonth?'active':''">
                        {{item.mounth.substring(5)}}月</p>
                      <!--<p>{{item.price}}起</p>-->
                    </div>
                  </div>
                </slot>
              </cell-month>

              <div class="sure_btn" @click="select_date">确定</div>

            </div>

          </div>

    script  如下
    import cellMonth from '@/components/cell-month'

    
    methods:{
    // 加载价格的接口。
          loadData(){
            //  数据里面的时间年都要完整。 例如1号,就要写 01
            let jsonArray = [
              {id: '4', dateStr: '2019-12-25', price: '¥2'},
              {id: '4', dateStr: '2019-12-26', price: '¥2'},
              {id: '4', dateStr: '2019-12-27', price: '¥2'},
              {id: '4', dateStr: '2019-12-28', price: '¥2'},
              {id: '4', dateStr: '2019-12-29', price: '¥2'},
              {id: '4', dateStr: '2019-12-30', price: '¥2'},
              {id: '4', dateStr: '2019-12-31', price: '¥2'},
              {id: '0', dateStr: '2020-01-01', price: '¥123'},
              {id: '0', dateStr: '2020-01-02', price: '¥123'},
              {id: '0', dateStr: '2020-01-03', price: '¥123'},
            ];
            let monthArray = [];
            for (var i in jsonArray) {
              var data = jsonArray[i];
              var dateDict = {'mounth':data.dateStr.substring(0,data.dateStr.length-3)};
              monthArray.push(dateDict);
            }
            //数组去重,获取有几个月
            var hash={};
            monthArray = monthArray.reduce(
              function (item,next) {
                hash[next.mounth]?'' :hash[next.mounth] = true && item.push(next);
                return item;
              },[]
            )
            console.log(monthArray);
            this.$data.dateArray = monthArray;
            //数据分组
            let classArray = [];
            for (var j in monthArray) {
              var newArray = new Array();
              for (var i in jsonArray) {
                var data = jsonArray[i];
                if (data.dateStr.substring(0,data.dateStr.length-3) == monthArray[j].mounth) {
                  newArray.push(data)
                }
              }
              classArray.push(newArray);
            }
            this.$data.classArray = classArray;
          },
          // 点击选择月份
          selectMounth(index){
            this.$data.selectMonth = index;
            console.log(index);
          },
          // 点击时间确认
          select_date() {
            this.show_date_model = false // 关闭弹窗
            var click_current_month = this.classArray[this.selectMonth][0].dateStr.substring(5,7)
            this.click_current_month = click_current_month
          },
},
created(){
          this.loadData();
        },

<style scoped lang="less">
.container{
padding-bottom:60px;
.ticket_item{
margin-bottom:5px;
width: 100%;
.flex-justify-between();
background: @color_fff;
padding:20px 20px 10px 20px;
.ticket_item_left{
width: 240px;
.name{
font-weight:500;
line-height: 30px;
.overflow2;
.font16;
i{
display: inline-block;
width: 16px;
height: 16px;
background: url("../../../static/img/ic_jing.png") no-repeat;
background-size: cover;
margin-right:8px;
}
}
.tap{
margin:15px 0 11px;
.flex();
.flex-wrap();
span{
padding:0 7px;
line-height: 26px;
border:1px solid @color_border;
margin-right:8px;
color:@color_h4;
}
}
.need_know{
.flex-align-center();
line-height: 30px;
>span{
color:@color_h4;
}
>i{
width: 4px;
height: 6px;
background: url("../../../static/img/ic_more.png");
background-size: cover;
margin-left:4px;
}
}
}
.ticket_item_right{
.flex-column();
.flex-justify-between();
.money{
b{
.font12;
color:@color_red;
font-weight: normal;
}
span{
.font18;
color:@color_red;
}
}
.btn{
background: @color_btn;
padding:8px;
border-radius: 3px;
color:#fff;
.font13;
margin-bottom:10px;
}
}
}
.need_conditions{
line-height: 32px;
background: @page_bg;
.padding20();
color:@color_red;
.font12;
}
.content_item{
border-bottom:1px solid @color_border;
.flex-justify-between();
.flex-align-center();
margin:0 20px;
padding:20px 0;
>span{
.font16;
color:@color_h2;
.flex-column();
b{
line-height: 20px;
font-weight: normal;
.font11;
color:@color_span;
}
}
.select_num{
.flex_center();
.btn{
.flex_center();
width: 25px;
height: 25px;
border:1px solid @color_border;
&:active{
background: @color_btn;
color:@color_fff;
}
}
.input{
width: 34px;
height: 25px;
border:1px solid @color_border;
margin:8px;
outline: none;
text-align: center;
.font12();
}
}
.input_text{
width: 46%;
text-align: right;
line-height: 30px;
.font14;
color:@color_h3;
&::-webkit-input-placeholder{

}
}
.tel_box{
.flex-align-center();
input{
flex:1;
}
i{
width: 19px;
height: 18px;
background: url("../../../static/img/ic_peoples.png");
background-size: cover;
margin-left:10px;
}
}
/*使用日期*/
.buy_time{
.flex();
.time_box{
.flex_center();
.flex-column();
text-align: center;
padding:6px;
border-radius: 3px;
min-width: 70px;
border:1px solid @color_h5;
margin-left:5px;
color:@color_h4;
&.active{
background: @color_btn;
color:@color_fff;
border:none;
}
&.disable{
color:@color_span;
}
span{
.font11;
line-height: 18px;
i{
display: block;

}
}
}
.time_box_more{
flex-direction: row;
i{
width: 4px;
height: 7px;
background: url("../../../static/img/ic_switch_choice_jiatou_hui.png") no-repeat;
background-size: cover;
margin:0 11px;
}
}
}
}
.buy_btn_box{
position: fixed;
bottom:0;
width: 100%;
height:60px;
.flex-justify-between();
.flex-align-center();
background: @color_fff;
border-top:1px solid @color_border;
.money{
margin-left:20px;
>span:nth-child(1){
.font14;
color:@color_red;
}
>span:last-child{
color:@color_red;
.font20;
font-weight: 600;
}
}
.buy_btn{
background: @color_btn;
height: 100%;
.flex_center();
width: 140px;
.font18;
color:@color_fff;
}
}
}
.data_model{
position: fixed;
left:0;
top:0;
right:0;
bottom:0;
background: rgba(0,0,0,.4);
}
.calender-content{
background: #fff;
position: fixed;
bottom:0;
left:0;
width: 100%;

.text_title{
text-align: center;
padding:20px 0 30px;
color:@color_h3;
position: relative;
.font16;
font-weight: 400;
span{
.font13;
position: absolute;
padding:20px;
top:0;
right:0;
}
}
.detail_time{
display: flex;
overflow-x: scroll;

}
}

.allMounth{
float: left;
width: 20%;
padding-left: 10px;
padding-right: 10px;
p:last-child{
.font18;
color: #222;
margin:30px 0;
font-weight:400;
}
p{
text-align: center;
&.active{
color:#B49C63;
}
}

}

.cell-month{
margin-top: 3%;
background: #fff;
}

.sure_btn{
width: 100%;
height:50px;
display: flex;
justify-content: center;
align-items: center;
background: #B49C63;
color:#fff;
font-size: 20px;
font-weight: 400;
margin-top:10px;
}
</style>

  

原文地址:https://www.cnblogs.com/dashaxiong/p/12167934.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


一:display:flex布局display:flex是一种布局方式。它即可以应用于容器中,也可以应用于行内元素。是W3C提出的一种新的方案,可以简便、完整、响应式地实现各种页面布局。目前,它已经得到了所有浏览器的支持。Flex是FlexibleBox的缩写,意为"弹性布局",用来为盒状模型提供最大的灵
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何垂直居中对齐,方法有很多,但是在学习了flex布局之后,垂直居中更加容易实现HTML代码:1<divclass="demo">2<divclass="inner">3<p>这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试</p>4</div
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些应用。常见的例子,比如360杀毒,photoShop,VisualStudioCode等等移动端app是什么,有哪些应用。常见的例子,比如手机微信,手机qq,手机浏览器,美颜相机等等PC端与移动端的区别第一:PC考虑的是浏览器的兼容性,移动端考
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周末了,难得学点东西,grid是之前看到的,很好奇,讲的二维的布局,看起来很方便,应该很适合移动端布局,所以今天抽时间学一学,这个当是笔记了。参考的是阮老师的博客。阮一峰:CSSGrid网格布局教程http://www.ruanyifeng.com/blog/2019/03/g
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后,浮动,定位将不会有效果)给父元素设置的属性:(1)display:flex---把容器设置为弹性盒模型。(2)flex-direction---设置弹性盒模型主轴方向默认情况下主
我在网页上运行了一个Flex应用程序,我想使用Command←组合键在应用程序中触发某些操作.这在大多数浏览器上都很好,但在Safari上,浏览器拦截此键盘事件并导致浏览器“返回”事件.有没有办法,通过Flex或通过页面上的其他地方的JavaScript,我可以告诉Safari不要这样做?解决方法:简短的
flex布局,flex-item1<template>2<viewclass="container">3<viewclass="greentxt">4A5</view>6<viewclass="redtxt">7B8<
我应该设计一个大型多点触控屏幕的应用程序.从大到大,我的意思是新闻广播员(大约55英寸及以上).该应用程序是一个交互式地图.我的问题是:开发应用程序的技术.我的第一个想法是在AdobeFlex中制作,但是HTML5也是如此……必须有一些非常棒的Java库用于触摸交互,但是在Windows平台上
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equiv="X-UA-Compatible&quo
【1】需求:  【2】解决方案:最近遇到布局上要求item两端对齐,且最后一行在列不满的情况下要求左对齐,使用flex的justify-content:space-between;实现时发现最后一行不能左对齐,而是两端对齐方式。 不是项目上想要的效果#网上查了一些资料,有两种方法可以实现效果:**1.
我有一个java套接字服务器,它在连接时将Animal对象发送到Flash客户端.对象发送方式如下:Amf3Outputamf3Output=newAmf3Output(SerializationContext.getSerializationContext());amf3Output.setOutputStream(userSocket.getOutputStream());amf3Output.writeObject(animal)
我正在开发一个Flex3.4应用程序,它通过最新版本的BlazeDS与JBoss-4.2.2服务器上运行的JavaEE后端进行交互.当我在Tomcat上从FlashBuilder4beta2运行Flex应用程序时,一切都很好,Flex应用程序能够进行所需的远程调用.但我的生产环境是在JBoss上,当我将应用程序移动到JBoss时(更
我有一个非常大的问题.我使用Flex3/Tomcat/BlazeDS/Spring编写了一个大型应用程序,在本地开发时运行良好,当我部署到公共开发环境时很好,但是当部署到我们的测试环境时经常失败.当远程处理请求花费大量时间(超过20秒)时,故障似乎最常发生.在我的开发服务器上,错误发生,但仅
弹性和布局display:flex在ie6,ie7不兼容状态,一般在pc用的比较少,在手机端所有的浏览器都是支持的控制子元素在父元素里面的位置关系display:flex是给父元素加的文档流是按照主轴排列,只要父元素加了flex,那么里面的子元素全部可以直接添加宽高主轴的方向
FLEX2.0源码分析(一)https://www.jianshu.com/p/8bc4c5f4b19fFLEX源码分析二(网络监测swizzle)https://www.jianshu.com/p/ffb95f2cbda6FLEX源码分析三(网络监测记录FLEXNetworkRecorder)https://www.jianshu.com/p/66267dc922c5FLEX源码分析四(Systemlog)https://www.jianshu.
1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<title><itle>6<style>7*{8margin:0;9padding:0;10
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equiv="X-UA-Compatible&qu
flex:将对象作为弹性伸缩盒显示inline-flex:将对象作为内联块级弹性伸缩盒显示两者都是使子元素们弹性布局,但是如果是flex,父元素的尺寸不由子元素尺寸动态调整,不设置时默认是100%,而inline-flex则会使父元素尺寸跟随子元素们的尺寸动态调整。
<html><head><metacharset="utf-8"><metaname="viewport"content="width=device-width"><title>test<itle><stylemedia="screen">.tab-head{list-style-type:no
有没有办法使用邮政编码找到径向距离?我的任务是搜索居住在指定距离内的所有用户.我知道用户的zipcodes.例如,距离当前位置25英里的用户.我有其他搜索类别,我正在使用mysql查询.我无法解决距离问题.我的后端是在PHP中Flex的前端和前端.对我来说最好的选择就是www.zip-codes.com