首先对学生登录login,登录学生评教页面,得到id,no数据
然后获取教师信息,做好评教的基础准备后,做评教页面
获取数据信息,最重要的是先要调用接口
onLoad: function (options) { var id = options.id; // var that = this; var url = "https://www.lishuming.top/pj/index.php/student/api/paperdetails"; var student = wx.getStorageSync('student'); var no = student.no; wx.request({ url: url, //仅为示例,并非真实的接口地址 data: { id: id, no: no, }, header: { 'content-type': 'application/json' // 默认值 }, success: (res) =>{ console.log(res.data); if(res.data.error){ wx.navigateBack({ delta:1 }) wx.showToast({ title: res.data.errormsg, icon:'none', duration:1000 }) }else{ this.setData({ data: res.data.data, pj: res.data.pj, count: res.data.data.length+2, }); } } }) },
今天要展示的是评教页面的数据处理,评教内容页面,代码展示:
<swiper bindchange='swiper_change' current='{{currentid}}' style='height:400px' duration='300'> <view class='father'> <view class='top'> <text class='pjtea'>被评老师:{{pj.teachername}}</text> <text class='type'>被评类型:{{pj.papertype}}</text> </view> <swiper-item> <view class='sm'>学生评教说明</view> <view class='pjcont'> 同学们评教是激励教师不断进步的重要手段,为深入了解我级部教学工作状况,增进师生互动、教学互动,提高教学质量,进一步完善我级部教学质量监控机制。 评教原则 同学们评教要体现以评促教、以评促改、教学相长和坚持公平、公正、 客观、实事求是的评教原则。 学生评教时,要严格按照评教内容,从关爱教师和有利提高教学质量的角度出发,认真负责的进行量化打分。反对弄虚作假,更不能借评教之机对曾经批评多自己的老师进行报复。 </view> </swiper-item> <block class='pjnum' wx:for="{{data}}" wx:key="{{data}}"> <swiper-item> <text class='timu'>{{index+1}}.{{item.content}}</text> <radio-group class="radio-group" bindchange="item_change" data-id="{{item.id}}"> <label class="radio" > <view><radio value="a#{{item.scorea}}">A.{{item.itema}}</radio></view> </label> <label class="radio" > <view><radio value="b#{{item.scoreb}}">B.{{item.itemb}}</radio></view> </label> <label class="radio" wx:if="{{item.itemc!==''}}"> <view><radio value="c#{{item.scorec}}">C.{{item.itemc}}</radio></view> </label> <label class="radio" wx:if="{{item.itemd!==''}}"> <view><radio value="d#{{item.scored}}">D.{{item.itemd}}</radio></view> </label> </radio-group> </swiper-item> </block> <swiper-item> <textarea class='cont' placeholder='请认真填写建议和意见'></textarea> </swiper-item> </view> </swiper> <view style='width:80%;margin-top:20px;margin-left:10%;'> <button type='primary' form-type='submit' bindtap="mysubmit" disabled='{{btn_disabled}}'>提交</button> </view>
首先实现评教数据的返回,对页面进行初始数据处理data
data: { currentid:0, count:0, pj: null, data: null, answer: {}, score: {}, btn_disabled:true, },
然后对页面中的swiper绑定swiper_change进行处理,实现页面的人工翻动,代码如下:
swiper_change:function(e){ // console.log(e); if(e.detail.source=='touch'){ this.setData({currentid:e.detail.current}) } },
next:function(e){ var index =this.data.currentid;//读取缓存 index++; if(index>=this.data.count){ index=0; } this.setData({currentid:index}); },
接着,对页面评教内容选中要评教的选项,返回返回的数据(序号以及对应的分数),代码如下:
//选中选项 item_change: function (e) { setTimeout(this.next,1000); console.log(e); var value = e.detail.value; // split()函数返回一个字符串数组 var arr = value.split("#"); var id = e.currentTarget.dataset.id; var _answer = this.data.answer; var _score = this.data.score; _answer[id] = arr[0]; _score[id] = arr[1]; this.setData({answer:_answer,score:_score}); //计算json里面值的个数 var len=2; for(var i in _answer){ len++; } if(len<this.data.count){ this.setData({btn_disabled:true}); }else{ this.setData({btn_disabled:false}); } },
这样该获取的数据,我们已经获取到了,进而要对提交按钮'mysubmit'作数据处理
//提交 mysubmit: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}; wx.request({ url: 'https://www.lishuming.top/pj/index.php/student/api/pj', method: 'POST', data:{ pjid: this.data.pj.pjid, testpaperid: this.data.pj.testpaperid, message:'', answer:JSON.stringify(this.data.answer), student:JSON.stringify(_student), score:_score }, header: { 'content-type':'application/x-www-form-urlencoded' }, success: (res) => { console.log(res.data); } }) },
这样,评教成功的话,会提示‘评教成功’,常规评教可以评教多次,但统一评教只能评教一次,如需再次评教,会提示您‘您已经测评!’。
最后,提交评教处理数据就实现了。