微信小程序?qū)崿F(xiàn)五星評(píng)價(jià)功能
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)五星評(píng)價(jià)的具體代碼,供大家參考,具體內(nèi)容如下
需求如圖:


1個(gè)星-很不滿意;
2個(gè)星-不滿意;
3個(gè)星-一般;
4個(gè)星-還不錯(cuò);
5個(gè)星-很滿意;

找了demo,刪刪改改,demo地址:微信小程序?qū)崿F(xiàn)星星評(píng)價(jià)效果
需要的頁面引入:
json:
{
?? ? ?"usingComponents": {
?? ? ? ?"star": "../../components/star/star"
?? ? ?},
?? ? ?"navigationBarTitleText": "評(píng)價(jià)"
?}wxml:
<star></star>
組件代碼:
wxml:
<!--components/star/star.wxml-->
<view class='buy' bindtap='showBuyModal'>測試版評(píng)價(jià)本次維修服務(wù)</view>
<!-- 點(diǎn)擊彈出遮罩層 -->
<view class="cover_screen" bindtap="hideBuyModal" wx:if="{{showModalStatus}}"></view>
<!-- 點(diǎn)擊立即購買 彈窗 -->
<view animation="{{animationData}}" class="buy_box" wx:if="{{showModalStatus}}">
? <view class='startitle'>{{tatle}}</view>
? <!-- 星星start -->
? <view class='container'>
? ? <view class='evaluate_contant'>
? ? ? <!--外層循環(huán)控制有幾個(gè)評(píng)價(jià)條目 -->
? ? ? <block wx:for='{{evaluate_contant}}' wx:key='' wx:for-index='idx'>
? ? ? ? <view class='evaluate_item'>
? ? ? ? ? <view class='evaluate_title'>{{staritem}}</view>
? ? ? ? ? <!--星星評(píng)價(jià) -->
? ? ? ? ? <view class='evaluate_box'>
? ? ? ? ? ? <!--內(nèi)層循環(huán)展示每個(gè)評(píng)價(jià)條目的星星 -->
? ? ? ? ? ? <block wx:for="{{stars}}" wx:key=''>
? ? ? ? ? ? ? <image class="star-image" style="left: {{item*80}}rpx" src="{{scores[idx] > item ?normalSrc:selectedSrc}}">
? ? ? ? ? ? ? ? <view class="staritem" data-score="{{item + 1}}" data-idx='{{idx}}' bindtap="selectRight"></view>
? ? ? ? ? ? ? </image>
? ? ? ? ? ? </block>
? ? ? ? ? </view>
? ? ? ? </view>
? ? ? </block>
? ? ? <view class="evaluation">{{evaluation}}</view>
? ? ? <!-- <button class='sub_button' bindtap='submit_evaluate' type='primary'>提交</button> -->
? ? </view>
? </view>
? <!-- 星星end -->
? <view class="detail-btn">
? <button class="done-person" style='border:4rpx solid #FF4A4A;background-color: #FFFFFF;font-weight: bold;color: #FF4A4A;font-size:28rpx;' bindtap='hideBuyModal' plain='{{plain}}'>取消</button>
? ? <button class="done-person" style='border:none;background-color: #FF4A4A;font-weight: bold;color: #FFFFFF;font-size:28rpx;' bindtap='submit_evaluate' plain='{{plain}}'>提交</button>
? ? <!-- <button type="primary" bindtap='hideBuyModal' class=""> 取消</button>
? ? <button type="primary" bindtap='submit_evaluate' class=""> 確定 </button> -->
? </view>
</view>js:
// components/star/star.js
Component({
? /**
? ?* 組件的屬性列表
? ?*/
? properties: {
? },
? /**
? ?* 組件的初始數(shù)據(jù)
? ?*/
? data: {
? ? showModalStatus: false,
? ? tatle: "您對(duì)這次服務(wù)的評(píng)價(jià)",
? ? // 星星
? ? evaluate_contant: ['一', ],
? ? stars: [0, 1, 2, 3, 4],
? ? normalSrc: '../../image/star_gray.png',
? ? selectedSrc: '../../image/star_red.png',
? ? score: 0,
? ? scores: [0],
? ? evaluation:' ',
? ? plain:true
? },
? /**
? ?* 組件的方法列表
? ?*/
? methods: {
? ? // 星星顆數(shù)start
? ? // 提交事件
? ? submit_evaluate: function() {
? ? ? console.log('評(píng)價(jià)得分' + this.data.scores)
? ? },
? ? //點(diǎn)擊星
? ? selectRight: function(e) {
? ? ? var score = e.currentTarget.dataset.score
? ? ? console.log(score)
? ? ? this.data.scores[e.currentTarget.dataset.idx] = score
? ? ? let evaluation = score == 1 ? '很不滿意' : (score == 2 ? '不滿意' : (score == 3 ? '一般' : (score == 4 ? '還不錯(cuò)' : (score == 5 ? '很滿意' : ''))))
? ? ? this.setData({
? ? ? ? scores: this.data.scores,
? ? ? ? score: score,
? ? ? ? evaluation: evaluation
? ? ? })
? ? },
? ? // 星星顆數(shù)end
? ? // onLoad: function (options) {
? ? // ? console.log(options.id)
? ? // },
? ? showBuyModal() {
? ? ? // 顯示遮罩層
? ? ? var animation = wx.createAnimation({
? ? ? ? duration: 200,
? ? ? ? /**
? ? ? ? ?* http://cubic-bezier.com/?
? ? ? ? ?* linear 動(dòng)畫一直較為均勻
? ? ? ? ?* ease 從勻速到加速在到勻速
? ? ? ? ?* ease-in 緩慢到勻速
? ? ? ? ?* ease-in-out 從緩慢到勻速再到緩慢
? ? ? ? ?*?
? ? ? ? ?* http://www.tuicool.com/articles/neqMVr
? ? ? ? ?* step-start 動(dòng)畫一開始就跳到 100% 直到動(dòng)畫持續(xù)時(shí)間結(jié)束 一閃而過
? ? ? ? ?* step-end 保持 0% 的樣式直到動(dòng)畫持續(xù)時(shí)間結(jié)束 一閃而過
? ? ? ? ?*/
? ? ? ? timingFunction: "ease",
? ? ? ? delay: 0
? ? ? })
? ? ? this.animation = animation
? ? ? animation.translateY(300).step()
? ? ? this.setData({
? ? ? ? animationData: animation.export(), // export 方法每次調(diào)用后會(huì)清掉之前的動(dòng)畫操作。
? ? ? ? showModalStatus: true
? ? ? })
? ? ? setTimeout(() => {
? ? ? ? animation.translateY(0).step()
? ? ? ? this.setData({
? ? ? ? ? animationData: animation.export() // export 方法每次調(diào)用后會(huì)清掉之前的動(dòng)畫操作。
? ? ? ? })
? ? ? ??
? ? ? }, 200)
? ? },
? ? hideBuyModal() {
? ? ? // 隱藏遮罩層
? ? ? var animation = wx.createAnimation({
? ? ? ? duration: 200,
? ? ? ? timingFunction: "ease",
? ? ? ? delay: 0
? ? ? })
? ? ? this.animation = animation
? ? ? animation.translateY(300).step()
? ? ? this.setData({
? ? ? ? animationData: animation.export(),
? ? ? })
? ? ? setTimeout(function() {
? ? ? ? animation.translateY(0).step()
? ? ? ? this.setData({
? ? ? ? ? animationData: animation.export(),
? ? ? ? ? showModalStatus: false
? ? ? ? })
? ? ? ? // console.log(this)
? ? ? }.bind(this), 200)
? ? }
? }
})wxss:
/* components/star/star.wxss */
.buy{
? margin-top: 200rpx;
? text-align: center;
}
.cover_screen {
? width: 100%;
? height: 100%;
? position: fixed;
? top: 0;
? left: 0;
? background: #000;
? opacity: 0.2;
? overflow: hidden;
? z-index: 1000;
? color: #fff;
}
.buy_box {
? width: 100%;
? box-sizing: border-box;
? position: fixed;
? bottom: 0;
? left: 0;
? z-index: 2000;
? background: #fff;
? padding: 20rpx;
? overflow: hidden;
}
.buy_box .startitle {
? ? font-size: 28rpx;
? ? text-align: center;
? ? line-height: 40rpx;
? ? color: #333;
? ? padding: 20rpx 0;
}
/* 星星 */
.footer_end{
? display: flex
}
.footer_end button{
? width: 30%;
}
/* 插入星星 */
/*評(píng)價(jià)區(qū)域 */
.container .evaluate_contant .evaluate_item {
?font-size: 30rpx;
?color: gray;
?margin-left: 20rpx;
?margin-top: 30rpx;
}
?
/*評(píng)價(jià)標(biāo)題 */
.container .evaluate_contant .evaluate_item .evaluate_title {
?display: inline-block;
}
?
/*評(píng)價(jià)盒子 */
.container .evaluate_contant .evaluate_item .evaluate_box {
?position: absolute;
?left: 220rpx;
?width: 100%;
?display: inline-block;
}
?
/*星星評(píng)價(jià)的每個(gè)圖片 */
.container .evaluate_contant .evaluate_item .evaluate_box .star-image {
?position: absolute;
?width: 40rpx;
?height: 40rpx;
?src: "../../image/star_gray.png";
}
/* 評(píng)價(jià)對(duì)應(yīng)內(nèi)容 */
.evaluation{
? text-align: center;
? margin: 30rpx 0 40rpx;
? color: #535353;
}
?
/*星星區(qū)域 */
.container .evaluate_contant .evaluate_item .evaluate_box .star-image .staritem {
?position: absolute;
?top: 0rpx;
?left: 0rpx;
?width: 40rpx;
?height: 40rpx;
}
?
/*按鈕 */
.container .evaluate_contant .sub_button {
?height: 60rpx;
?font-size: 30rpx;
?line-height: 60rpx;
?margin: 20rpx;
}
.detail-btn{
? width: 750rpx;
? display: flex;
? justify-content: space-around;
? align-items: center;
? margin-bottom: 100rpx;
}
.done-person{
? width:220rpx;
? height:72rpx;
? border-radius:36rpx;
}以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS操作CSS隨機(jī)改變網(wǎng)頁背景實(shí)現(xiàn)思路
JS和CSS讓頁面每次刷新隨機(jī)產(chǎn)生一張背景圖,當(dāng)然我的回答是可以的,下面是具體的實(shí)現(xiàn)思路,感興趣的朋友可以參考下2014-03-03
利用js的閉包原理做對(duì)象封裝及調(diào)用方法
下面小編就為大家?guī)硪黄胘s的閉包原理做對(duì)象封裝及調(diào)用方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04
BootStrap下拉框在firefox瀏覽器界面不友好的解決方案
BootStrap下拉框在firefox瀏覽器界面很不友好,在firefix瀏覽器打開鏈接就會(huì)發(fā)現(xiàn)里面有個(gè)小容器,怎么處理呢,下面看下小編給大家分享的有關(guān)這個(gè)問題的處理方案2016-08-08
微信小程序web-view無法打開該頁面不支持打開的解決方法
小程序現(xiàn)在日漸成熟,功能也越來越強(qiáng)大,我們今天來一起看看小程序跳轉(zhuǎn)的問題,下面這篇文章主要給大家介紹了關(guān)于微信小程序web-view無法打開該頁面不支持打開的解決方法,需要的朋友可以參考下2023-01-01
微信小程序獲取地理位置及經(jīng)緯度授權(quán)代碼實(shí)例
這篇文章主要介紹了微信小程序獲取地理位置及經(jīng)緯度授權(quán)代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
淺析JavaScript中l(wèi)et與const命令的區(qū)別
這篇文章主要為大家詳細(xì)介紹了JavaScript中l(wèi)et命令與const命令的用法及區(qū)別,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考下2023-09-09

