evaluate.js 6.0 KB
// pages/evaluate/evaluate.js
//获取应用实例
const app = getApp()
Page({

   /**
    * 页面的初始数据
    */
   data: {
      noteMaxLen: 50, //备注最多字数  
      // 输入评论内容
      value: "",
      orderNote: [],
      //  图片上传预览删除
      allLength: 3,//  最多上传多少张
      getState: true,
      imgArray: [],
      getImgArr: [],
      // 订单id
      oid: ""
   },
   // 提交
   submit() {
      wx.showLoading({
         title: '正在提交',
      })
      var value = this.data.value;
      var getImgArr = this.data.getImgArr;
      console.log(getImgArr)
      var str = ""
      for (let n in getImgArr) {
         str = str + getImgArr[n] + "," 
      }
      console.log(value)
      console.log(str)
      if(value != ""){
         app.ajax("MyComment/comment",{
            unique_id: app.globalData.unique_id,
            oid: this.data.oid,
            comment_content:value,
            comment_photo:str
         },(res)=>{
            wx.hideLoading()
            console.log(res)
            if(res.data.status == true){
               wx.showToast({
                  title: res.data.msg,
                  icon: 'success',
                  duration: 2000,
                  mask:true
               })
               setTimeout(function () {
                  wx.navigateBack({})
               }, 2000)
            }else{
               wx.showLoading({
                  title: res.data.msg
               })
            }
         },(res)=>{})
      }else{
         wx.showLoading({
            title: '填写评论',
            mask:true,
            duration: 1000
         })
      }

   },
   //   选择图片
   getImg() {
     let that = this
      wx.chooseImage({
         count: this.data.allLength - this.data.imgArray.length, // 还可以上传几张
         sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
         sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
         success: (res) => {                                                                                            
            // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
            var tempFilePaths = res.tempFilePaths;
            var imgArray = Object.assign([],this.data.imgArray);
           
            for (let n in tempFilePaths) {
               console.log(tempFilePaths[n])
               wx.uploadFile({
                  url: app.globalData.imgUrlUp,                              
                  filePath: tempFilePaths[n],
                  name: "files",
                  formData: {},
                  success: (res) => {
                    console.log(res)
                     var getImgArr = this.data.getImgArr
                    let data = JSON.parse(res.data)
                    if(data.status){
                      console.log(data.data)
                      getImgArr.push(data.data)
                      console.log(tempFilePaths[n])
                      imgArray.push(tempFilePaths[n])                           
                      console.log(imgArray)
                      
                    }else{
                      wx.showToast({
                        title: data.msg,
                        icon: 'none'
                      })
                    }
                     console.log()
                     this.setData({
                        getImgArr: getImgArr
                     })
                    this.setData({
                      imgArray: imgArray 
                    })
                    that.detection()
                  },
                 complete:(res)=>{
                   console.log(res)
                 }
               })
            }
            
         }
      })
   },
   // 检测图片数量
   detection() {
      if (this.data.imgArray.length == this.data.allLength) {
         this.setData({
            getState: false
         })
      } else {
         this.setData({
            getState: true
         })
      }
   },
   // 删除
   del(e) {
      var index = e.currentTarget.dataset.index;
      var imgArray = this.data.imgArray;
      var getImgArr = this.data.getImgArr;
      imgArray.splice(index, 1)
      getImgArr.splice(index,1)
      this.setData({
        imgArray: imgArray,
        getImgArr: getImgArr
      })
      console.log(this.data.imgArray)
      this.detection()
   },
   //选择订单备注  
   bindOrderNote: function (e) {
      var index = e.currentTarget.dataset.index, list = this.data.orderNote;
      for (var i = 0, len = list.length; i < len; i++) {
         if (index == list[i].index) {
            list[i].selected = !list[i].selected;
         }
      }
      this.setData({
         orderNote: list
      });
   },

   //字数限制  
   bindWordLimit: function (e) {
      var value = e.detail.value, len = parseInt(value.length);
      if (len > this.data.noteMaxLen) return;

      this.setData({
         currentNoteLen: len, //当前字数  
         value: value
         //limitNoteLen: this.data.noteMaxLen - len //剩余字数  
      });
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
      if (options.id) {
         console.log(options.id)
         this.setData({
            oid: options.id
         })
      }
   },

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

   },

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

   },

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

   },

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

   },

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

   },

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

   },

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

   }
})