goodevalute.js 4.4 KB
// pages/goodevalute/goodevalute.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pingid: '',
    type: '',
    star: '',
    imgarr: [],
    chuanimgarr:[],
    star: 1,
    content: '',
    item:"",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    this.setData({
      pingid: options.id,
      type: options.type,
      item:JSON.parse(options.item),
      imgarr: [],
      chuanimgarr: [],
    })
    console.log(this.data.item)
  },

  // 选择五角星
  chosestar(e) {
    console.log(e)
    this.setData({
      star: e.currentTarget.dataset.star
    })

  },
  chooseImage() {
    let that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      success: function(res) {
        console.log('9988776655',res)
        console.log(res.tempFilePaths[0])
        app.upload('image', res.tempFilePaths[0]).then((res) => {
          console.log('上传文件', res);
          let newimagarr = that.data.imgarr;
          console.log(newimagarr)

          newimagarr.push(res.aburl);
          let newchuanimagarr=that.data.chuanimgarr;
          newchuanimagarr.push(res.url);
          that.setData({
            imgarr: newimagarr,
            newchuanimagarr: newchuanimagarr
          })

          console.log(that.data.imgarr)

          // that.setData({
          //   banneritem: res.url
          // })
        }).catch((err) => {
          console.log(err)
        })
      },
      fail: function(res) {}
    })
  },
  delimg(e){
    let that=this;
    let url=e.currentTarget.dataset.url;
    let index=e.currentTarget.dataset.index;

    let newimagarr = that.data.imgarr;
    let newchuanimagarr = that.data.chuanimgarr;
    for(var i=0;i<newimagarr.length;i++){
      
      if (url == newimagarr[i]){
        newimagarr.splice(i,1)
      }
    }
    for (var j = 0; j < newchuanimagarr.length; j++) {
      if (index==j) {
        newchuanimagarr.splice(j, 1)
      }
    }

    that.setData({
      imgarr: newimagarr,
      chuanimgarr: newchuanimagarr
    })

    console.log(that.data.imgarr);
    console.log(that.data.chuanimgarr)
    
  },

  // 输入评论
  enterevalute(e) {
    this.setData({
      content: e.detail.value
    })

  },

  // 发布
  fabu() {
    let that = this;
    if (that.data.content==''){
      wx.showToast({
        title: '请输入评价内容',
        icon:'none'
      })

      return false
    }
   
    var url = 'comment/create_comment';
    var params = {
      order_info_id:this.data.pingid,
      star:this.data.star,
      images: this.data.chuanimgarr.join(","),
      content: this.data.content

    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: '评论成功',
        icon:'none'
      })

      setTimeout(function(){
        wx.navigateTo({
          url: '/pages/orderbox/orderbox?index=' + 4,
        })
      },1000)



    }).catch((err) => {

    })

  },


  // chooseImage() {
  //   let that = this;
  //   wx.chooseImage({
  //     count: 1,
  //     sizeType: ['original', 'compressed'],
  //     success: function (res) {
  //       console.log(res)
  //       app.upload('image', res.tempFilePaths[0]).then((res) => {

  //         console.log('上传文件' + JSON.stringify(res));
  //         let data = JSON.parse(JSON.stringify(res))
  //         console.log(data)
  //         let arr = that.data.images;
  //         arr.push(data.url)
  //         that.setData({
  //           images: arr
  //         })

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



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

  },



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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})