餓了麼專案---13、模組化程式設計,實現商品詳情頁面
阿新 • • 發佈:2019-01-08
import BScroll from 'better-scroll';
import cartcontrol from '../cartcontrol/cartcontrol.vue';
import ratingSelecte from '../ratingSelecte/ratingSelecte.vue';
import {dateToString} from '../../common/js/common.js';
//商品評價的篩選狀態
const SATISFY=0; //推薦
const UNSATISFY=1; //吐槽
const All=2; //全部
export default{
name:'food' ,
props:{
selectedfood:{
type:Object
}
},
data(){
return{
showthis:false,//顯示或隱藏改元件
suggestion:{
all:'全部',
satisfy:'推薦',
unsatisfy:'吐槽'
},
selectType:All,
onlyContent:false//只看內容
}
},
methods:{
showthisfood(){
this.showthis = true;
//初始化篩選內容
this.selectType=All,
this.onlyContent=false//只看內容
this.$nextTick(()=>{
//better scroll需要更新DOM物件
if(!this.scroll){
this.scroll = new BScroll(this.$refs.food, {
click:true
});
}else{
this.scroll.refresh();
}
})
},
hidethisfood(){
this.showthis = false;
},
cartAddcontrol(el){
this.$emit('cartAddEvent',el);
},
addCount(el){
//為food數量置1
this.$set(this.selectedfood,'count',1)
//派發小球點選事件,做拋物動畫
this.$emit('cartAddEvent',el.target);
},
//切換評價篩選條件
selectContent(type){
this.selectType = type
//切換篩選條件時,更新了DOM節點,要更新better scroll
this.$nextTick(()=>{
this.scroll.refresh()
})
},
onlyshowcon(){
this.onlyContent = !this.onlyContent
this.$nextTick(()=>{
this.scroll.refresh()
})
},
//是否顯示評價資訊
showRating(rating){
//只看評價時,不顯示的
if(this.onlyContent && rating.text==''){
return false;
}
//點選三個評價篩選
if(this.selectType===All){
return true;
}else{
return this.selectType ===rating.rateType;
}
}
},
components:{cartcontrol,ratingSelecte}
,
filters:{
//將字串時間轉換成時間格式
dateString(datenumber) {
let date = new Date(datenumber);
return dateToString(date);
}
}
}