const {
  api,
  rapi,
  formatTime,
  mapApi,
  mockApi,
  imgName,
  getUserInfo,
  wxLogin,
  alertTip,
  wxscan,
  authAgainByUser,
  userLocation
} = require('../../lib/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:'',
    userId:'',
    serviceScore:0,
    skillScore:0,
    comment:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let orderId = options.orderId
    let userId=wx.getStorageSync('user').userMapp.id
    this.setData({
      orderId,
      userId
    })
  },
  //评价
  submitEvaluate(){
    let { orderId, userId, serviceScore, skillScore, comment}=this.data
    console.log({ orderId, userId, serviceScore, skillScore, comment })
    if (serviceScore == 0){
      alertTip('请给服务打分')
      return 
    }
    if (skillScore == 0) {
      alertTip('请给专业技能打分')
      return
    }
    if (comment == '') {
      alertTip('请输入评价内容')
      return
    }
    rapi.get('userOrder/orderEvaluate',{
      orderId, userId, serviceScore, skillScore, comment
    })
    .then(res=>{
      alertTip('评价成功',()=>{
        wx.navigateBack()
      })
    })
    .catch(err=>{
      alertTip(err)
    })
  },
  skillScoreChange(e){
    this.setData({
      skillScore: e.detail.score
    })
  },
  serviceScoreChange(e) {
    this.setData({
      serviceScore: e.detail.score
    })
  },
  bindTextAreaBlur(e){
    this.setData({
      comment: e.detail.value
    })
  }
})