const util = require("../../../../utils/util");

Page({
  data: {
    radioArr:[
      {
        value:0,
        title:'这次课很开心，喜欢领队，希望可以跟领队在线下活动见面'
      },
      {
        value:1,
        title:'这次课对自己有帮助，以后还要继续上成长课'
      },
      {
        value:2,
        title:'这次课没什么意思，想上其他领队的课'
      },
      {
        value:3,
        title:'这次课很无聊，以后再也不想上了'
      },
    ],
    data:{
      courseId:'',
      score:'',
      comment:'',
      remark:''
    },
    headInfo:{
      leaderName:'',
      courseTitle:'',
      city:''
    }
  },
  onLoad: function (options) {
    console.log(options)
    if (options) {
      this.setData({
        'data.courseId':options.id,
        'data.studentId':options.studentId,
        'headInfo.leaderName':options.leaderName,
        'headInfo.courseTitle':options.courseTitle,
        'headInfo.city':options.city,
      })
    }
  },
  // 提交
  submit(){
    let self = this,info=this.data.data;
    if (util.isEmpty(info.score) || util.isEmpty(info.comment)) {
      util.showTips('请选择您对本次课程的感受')
      return false;
    }
    util.ajax({
      func: "v2/gwcourse/comment/add",
      data:info
    }, function (res) {
      if (res.code==0) {
        util.showTips(res.reason)
        setTimeout(() => {
          wx.navigateBack({
            delta: 1
          })
        }, 500);
      }else{
        util.showTips(res.reason)
      }
    })
  },
  // 单选框选中
  checkRadio(e){
    let value = e.detail.value
    let arr = value.split('|')
    this.setData({
      'data.score':arr[0],
      'data.comment':arr[1]
    })
  },
  // 脱焦绑定
  bindTextAreaBlur(e){
    let info = e.detail.value;
    this.setData({'data.remark':info})
  },
})