微信小程序時間標簽和時間范圍的聯(lián)動效果
本文實例為大家分享了微信小程序時間標簽和時間范圍聯(lián)動的具體代碼,供大家參考,具體內容如下

最近忙于一個有關數據管理的微信小程序,遇到了上圖情況,雖然很簡單,還是整理一下。若有錯誤,請廣大朋友們指正。
使用微信小程序組件radio-group、picker,用wxss對radio按照需求進行重構,picker里邊的start和end時間是根據radio來顯示的。將start、end時間放在data里,radio發(fā)生改變時,改變data中的時間。當picker中的值發(fā)生改變時,如果時間范圍已經超出了radio中的范圍,需要對radio的顯示進行實時修改。
話不多說,接下來上代碼。
index.wxml
<view class="con_screen">
<text class="cons_ti">日期范圍</text>
<!-- 單選時間 -->
<radio-group class="radio-group" bindchange="radioCheckedChange">
<block >
<label class="cons_radio {{radioCheckVal==1?'active':''}}" >
<radio value="1" hidden="true"/>
<text>今日</text>
</label>
<label class="cons_radio {{radioCheckVal==4?'active':''}}" >
<radio value="4" hidden="true" />
<text>近7日</text>
</label>
<label class="cons_radio {{radioCheckVal==6?'active':''}}" >
<radio value="6" hidden="true"/>
<text>近30日</text>
</label>
</block>
</radio-group>
<!-- 時間段 -->
<view class="picker_group">
<picker mode="date" value="{{date}}" start="2015-09-01" end="{{date2}}" bindchange="bindDateChange">
<view class="picker">
{{date}}
<image src="../../image/home_zsr_icon.png"></image>
</view>
</picker>
到
<picker mode="date" value="{{date2}}" start="{{date}}" end="2018-01-24" bindchange="bindDateChange2">
<view class="picker">
{{date2}}
<image src="../../image/home_zsr_icon.png"></image>
</view>
</picker>
</view>
</view>
index.wxss
.radio-group{
display: inline-block;
}
.cons_radio{
margin-left: 30rpx;
}
.cons_radio text{
font-size: 26rpx;
color: #c8c8c8;
height: 40rpx;
/* width: 93rpx; */
border: #c8c8c8 solid 2rpx;
padding:0 20rpx;
text-align: center;
line-height: 40rpx;
display: inline-block;
border-radius: 20rpx;
}
/* 黃色 */
.cons_radio.active text{
color: #F5A623;
border-color: #F5A623;
}
/* 紅色 */
.cons_radio.activered text{
color: #FA2B21;
border-color: #FA2B21;
}
/* 藍色 */
.cons_radio.activeblue text{
color: #4AAFDD;
border-color: #4AAFDD;
}
/* 黃綠色 */
.cons_radio.activeyg text{
color: #BABC1A;
border-color: #BABC1A;
}
/* 日期選擇 */
.picker_group{
display: block;
font-size: 28rpx;
color: #c8c8c8;
margin-left: 20rpx;
margin-top: 15rpx;
}
.picker_group picker{
display: inline-block;
margin:0 20rpx 0 20rpx;
position: relative;
color: #232323;
}
.picker_group picker image{
width: 20rpx;
height: 20rpx;
}
.cons_zsr{
display: block;
font-size: 32rpx;
color: #232323;
margin-left: 40rpx;
margin-bottom: 15rpx;
}
.cons_zsr picker image{
width: 30rpx;
height: 30rpx;
}
index.js
Page({
data:{
page:'',
Loading:false,
isLogin:false,
radioCheckVal:0,//收益占比單選
date: '2015-09-01',//收益占比時間段起始時間
date2:'2018-01-24',//收益占比時間段終止時間
},
// 收益占比單選時間 ring
radioCheckedChange(e){
let that=this;
that.setData({
radioCheckVal:e.detail.value
})
console.log(that.data.radioCheckVal)
if(that.data.radioCheckVal=='1'){
that.setData({
date:timedate.formatDate(now),
date2:timedate.formatDate(now),
})
// console.log(that.data.date+'------'+that.data.date2)
that.timeFn(that.data.arrayindex,that.data.date,that.data.date2)
}
if(that.data.radioCheckVal=='4'){
that.setData({
date:timedate.sevenDays().t2,
date2:timedate.sevenDays().t1,
})
// console.log(that.data.date+'------'+that.data.date2)
that.timeFn(that.data.arrayindex,that.data.date,that.data.date2)
}
if(that.data.radioCheckVal=='6'){
that.setData({
date:timedate.thirtyDays().t2,
date2:timedate.thirtyDays().t1,
})
// console.log(that.data.date+'------'+that.data.date2)
that.timeFn(that.data.arrayindex,that.data.date,that.data.date2)
}
},
// 收益占比時間段選擇
bindDateChange(e){
let that=this;
console.log(e.detail.value)
that.setData({
date: e.detail.value,
radioCheckVal:0,
})
that.timeFn(that.data.arrayindex,that.data.date,that.data.date2)
},
bindDateChange2(e){
let that=this;
that.setData({
date2: e.detail.value,
radioCheckVal:0,
})
that.timeFn2(that.data.arrayindex,that.data.date,that.data.date2)
},
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Java中int與integer的區(qū)別(基本數據類型與引用數據類型)
這篇文章主要介紹了int與integer的區(qū)別(基本數據類型與引用數據類型),簡單的說 int 是基本數據類型,integer 是引用數據類型,具體區(qū)別詳解大家參考下本文2017-02-02

