您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了微信小程序時(shí)間標(biāo)簽和時(shí)間范圍聯(lián)動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
最近忙于一個(gè)有關(guān)數(shù)據(jù)管理的微信小程序,遇到了上圖情況,雖然很簡(jiǎn)單,還是整理一下。若有錯(cuò)誤,請(qǐng)廣大朋友們指正。
使用微信小程序組件radio-group、picker,用wxss對(duì)radio按照需求進(jìn)行重構(gòu),picker里邊的start和end時(shí)間是根據(jù)radio來(lái)顯示的。將start、end時(shí)間放在data里,radio發(fā)生改變時(shí),改變data中的時(shí)間。當(dāng)picker中的值發(fā)生改變時(shí),如果時(shí)間范圍已經(jīng)超出了radio中的范圍,需要對(duì)radio的顯示進(jìn)行實(shí)時(shí)修改。
話不多說(shuō),接下來(lái)上代碼。
index.wxml
<view class="con_screen"> <text class="cons_ti">日期范圍</text> <!-- 單選時(shí)間 --> <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> <!-- 時(shí)間段 --> <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; } /* 藍(lán)色 */ .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',//收益占比時(shí)間段起始時(shí)間 date2:'2018-01-24',//收益占比時(shí)間段終止時(shí)間 }, // 收益占比單選時(shí)間 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) } }, // 收益占比時(shí)間段選擇 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) },
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。