功能:
- 展示默认的分数,
- 点击几颗星星,展示几分
<template>
<div class="form-content">
<div>
<span class='name'>质量分<span class="required"></span></span>
<div class="stars">
<img v-for="(item,ydx) in qStars" :key="ydx" :src="item?yellow:gray" @click="onSetStars('q',ydx)">
<span>{{formData.qscore}}分</span>
</div>
</div>
<div>
<span class='name'>效率分<span class="required"></span></span>
<div class="stars">
<img v-for="(item2,ydx2) in eStars" :key="ydx2" :src="item2?yellow:gray" @click="onSetStars('e',ydx2)">
<span>{{formData.escore}}分</span>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
qStars:[false,false,false,false,false],
eStars:[false,false,false,false,false],
yellow:require("../../../assets/images/emer/star-yellow.png"),
gray:require("../../../assets/images/emer/star-gray.png"),
formData:{
taskid:"",
qscore: 0,
escore:0
}
}
},
created() {
this.formData.qscore = this.$route.params.row.qscore;
this.formData.escore = this.$route.params.row.escore;
// 填充星星显示与否的值
if(this.formData.qscore){
this.qStars.fill(true,0,this.formData.qscore);
}else{
this.qStars.fill(false);
}
if(this.formData.escore){
this.eStars.fill(true,0,this.formData.escore);
}else{
this.eStars.fill(false);
}
},
methods: {
/**----------------------------按钮操作--------------------------------------- */
// 1 设置分数
onSetStars(name,index){
if(name.indexOf('q')>-1){
this.formData.qscore=index+1;
if(index==4){//最后一个
this.qStars.fill(true);
}else{
this.qStars.fill(true,0,index+2);
this.qStars.fill(false,index+1);
}
this.$forceUpdate();
}else{
this.formData.escore=index+1;
if(index==4){//最后一个
this.eStars.fill(true);
}else{//其他
this.eStars.fill(true,0,index+2);
this.eStars.fill(false,index+1);
}
this.$forceUpdate();
}
},
// 2.1 提交前验证信息
doSubmit(){
if(this.formData.qscore ===0){
errStr("请设置质量分。");
return;
}
if(this.formData.escore ===0){
errStr("请设置效率分。");
return;
}
this.doSubmitOK();
},
// 2.2 提交
doSubmitOK(){
this.blnShowLoad = true;
axios({
method:'post',
url:'task/scoring',
data:this.formData,
}).then((res)=>{
this.blnShowLoad = false;
if(res.data.data.result){
showAlert("评分成功!","提示",()=>{
this.$router.go(-1);
});
}else{
errStr("评分失败!");
}
}).catch(err =>{
this.blnShowLoad = false;
showErrMsg(err,"评分失败!");
})
}
}
}
</script>
<style lang="stylus" scoped>
@import "~common/stylus/duty"
@import "~common/stylus/form"
.stars{
>img{
width:0.8rem;
height:0.8rem;
margin-right:0.1rem;
}
}
</style>