微信小程序中,评教系统如何计算出评分的分数

首先要获取到评分的那个分数,这里有一个基本上比较完整的评教系统

首先在.wxml文件中搭一个基本的界面:

<!--pages/evaluation/evaluation.wxml-->
<view class='kuang'>
<view class='top'>被评老师:{{teacher.teachername}}</view>
<swiper bindchange="swiper_change" current="{{currentid}}">
    <swiper-item wx:for="{{wen}}">
      <view class='group1'>
        <view>{{index+1}}:{{item.content}}</view>
        <radio-group class="radio-group" bindchange="item_change" data-id="{{item.id}}">
        <label class='radio'>
          <radio value="a#{{item.scorea}}"/>{{item.itema}}
        </label>
        <label class='radio'>
          <radio value="b#{{item.scoreb}}"/>{{item.itemb}}
        </label>
        <label class='radio' wx:if="{{item.itemc!=''}}">
          <radio value="c#{{item.scorec}}"/>{{item.itemc}}
        </label>
        <label class='radio' wx:if="{{item.itemd!=''}}">
          <radio value="d#{{item.scored}}"/>{{item.itemd}}
        </label>
        </radio-group>
      </view>
    </swiper-item>
    
    <swiper-item >
      <view class='group1'>
        <view>我的留言:</view>
        <textarea bindblur="bindTextAreaBlur"  placeholder="" />
      </view>
    </swiper-item>
</swiper>
 <button disabled='{{btn_disabled}}' bindtap="submit">提交</button>  
 <!-- <button  form-type="submit">提交</button>  -->
</view>

然后在.js文件中来获取题目,分数,在.js文件中写获取用户答案的一个方法item_change(如下),当用户选一个选项时会自动跳到下一题,此方法为next,在onload方法下获取题目的信息,然后在submit方法内获取用户选项的分数和题号最后在提交,

data: {
    indicatorDots: true,
    currentid: 0,
    count: 0,
    teacher:null,
    wen:null,
    answer:{},
    score:{},
    btn_disabled:true,
    pj:null,
    details:null
    
  
  },
  swiper_change:function(e){
    if(e.detail.source=='touch'){
      this.setData({currentid:e.detail.current})
    }
  },
  item_change:function(e){
    setTimeout(this.next,1000);
    // console.log(e);
    var id = e.currentTarget.dataset.id;
    // console.log(id);
    var fen = e.detail.value;
    var arr = fen.split("#");
    // console.log(arr);
    var _answer = this.data.answer;
    _answer[id] = arr[0];
    this.setData({ answer: _answer });
    // console.log(_answer);
    var _score=this.data.score;
    _score[id]=arr[1];
    this.setData({score:_score});
    // console.log(_score);
    //判断按钮是否可用
    var json=this.data.answer;
    var jsonlength=0;
    for(var i in json){
      jsonlength++;
    }
    if(jsonlength==this.data.count){
      this.setData({btn_disabled:false});
    }else{
      this.setData({btn_disabled:true});
    }
    
  },
  next: function () {
    // console.log(e);
    var index = this.data.currentid;//读取变量的值
    index++;
    if(index>=this.data.count) {
      // index = 0;
      index=this.data.count-1;
    }
    this.setData({ currentid: index });

  },
  //提交

  submit:function(){
    // console.log(this.data.answer);
    // console.log(this.data.score);
    //计算分值
    var _score=0;
    for(var i in this.data.score){
      _score +=parseInt(this.data.score[i]);
    } 
    // console.log(_score);
   //学生信息
   var student =wx.getStorageSync('student');
   var _student={no:student.no,name:student.name,classid:student.classid};
  //  var pjid=this.data.pj.pjid;

  //  console.log(pjid);
 
  },



猜你喜欢

转载自blog.csdn.net/lixiaotong_123/article/details/80273349