comment.js 4.8 KB
// pages/comment/comment.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalstar:0,
    servicestar:0,
    taststar: 0, 
    environmentstar:0,
    foodstar:0,
    mark:'',
    image:[],
    cimage:[],
    money:'',
    name:'',
    shopid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      name:options.name,
      shopid:options.shopid
    })
  },
  // 综合评分
  total(e){
    let id=e.currentTarget.dataset.id;
    this.setData({
      totalstar:id
    })
  },
  // 服务评分

  service(e){
    let id=e.currentTarget.dataset.id
    this.setData({
      servicestar:id
    })
  },

  // 口味评分
  tast(e){
    let id=e.currentTarget.dataset.id
    this.setData({
      taststar:id
    })
  },

  // 环境评分
  envirment(e){
    let id = e.currentTarget.dataset.id
    this.setData({
      environmentstar:id
    })
  },
  // 食材评分
  food(e){
    let id=e.currentTarget.dataset.id
    this.setData({
      foodstar:id
    })
  },

  //感受
  entermark(e){
    this.setData({
      mark:e.detail.value
    })

    console.log(this.data.mark)
  },

  chooseImage() {
    let that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      success: function (res) {
        console.log(res.tempFilePaths[0])
        app.upload('image', res.tempFilePaths[0], "post").then((res) => {
          console.log('上传文件', res);
          let url = app.globalData.baseurl+res.url;
          that.data.image.push(url)
          that.data.cimage.push(res.url)
          that.setData({
            image: that.data.image,
            cimage: that.data.cimage
          })

          console.log(that.data.image);
          console.log(that.data.cimage)


        }).catch((err) => {
          console.log(err)
        })
      },
      fail: function (res) { }
    })
  },

  // 删除图片
  del(e){
    let that=this;
    let url=e.currentTarget.dataset.url;
    that.data.image.forEach(function(value,index,array){
        if(value==url){
          that.data.image.splice(index,1);
          that.data.cimage.splice(index, 1)
        }
    })
    that.setData({
      image:that.data.image,
      cimage:that.data.cimage
    })

    console.log(that.data.image);
    console.log(that.data.cimage)

  },

  // 输入金额
  entermoney(e){
    this.setData({
      money:e.detail.value
    })
  },

  publish(){
    let that = this;
    if (that.data.totalstar==0){
      wx.showToast({
        title: '请选择综合评分',
        icon:"none"
      })
      return false
    }
    if (that.data.servicestar == 0) {
      wx.showToast({
        title: '请选择服务评分',
        icon: "none"
      })
      return false
    }
    if (that.data.taststar == 0) {
      wx.showToast({
        title: '请选择口味评分',
        icon: "none"
      })
      return false
    }
    if (that.data.environmentstar == 0) {
      wx.showToast({
        title: '请选择环境评分',
        icon: "none"
      })
      return false
    }
    if (that.data.mark == '') {
      wx.showToast({
        title: '请输入评论内容',
        icon: "none"
      })
      return false
    }
    if (that.data.mark == '') {
      wx.showToast({
        title: '请输入评论内容',
        icon: "none"
      })
      return false
    }


    if (that.data.money == '') {
      wx.showToast({
        title: '请输入人均消费',
        icon: "none"
      })
      return false
    }


    var url = '/remark/addRemark';
    var params = {
      shop_id:that.data.shopid,
      price:that.data.money,
      content:that.data.mark,
      images:that.data.image.join(","),
      score1:that.data.totalstar,
      score2:that.data.servicestar,
      score3:that.data.taststar,
      score4:that.data.environmentstar,
      score5:that.data.foodstar,
      type:1

    }
    app.post(url, params,"post").then((res) => {
      console.log(res);
      wx.showToast({
        title: '发表成功',
        icon:'none'
      })
      setTimeout(function(){
        wx.navigateBack({
          checked:true
        })
      },1500)



    }).catch((err) => {

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})