create.js 5.43 KB
// pages/pinglun/create.js
import App from '../../utils/api'
import util from '../../utils/util'
import DA from '../../pages/reserve/data';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    types:'',
    qnConf:{
      accessKey:'uva-aaonM8dukeR6phc9yuPBrOXk9brrNW_PxLD7',
      secretKey:'oZMMVN6phk49lG0J1xwmi1Ju0ETT15EnAEWcU9Cs',
      token:'',
      bucket:'colorcun-attr',//存储空间
      fileType:'image',//image|video|audio|file def:file
      region:'华东',//存储区域
      domain:'http://nosqn.colorcun.com',//你绑定的域名,非必填项
    },
    upConf:{
      prefixPath:'pinglun/images/', //上传到七牛后有一个路径前缀,可为空
      loading:'ring',// none|leaf|circle|ring, def leaf 上传的loading效果; none为无,可自行在page wxml中添加
      group:'image', //一个页面上多个组件的区分标识
      security:false, // 开启非法检测,默认 false
      //上传图片
      count:6, //最多可以选择的图片张数
      sizeType:['compressed'],  //['original', 'compressed'] 所选的图片的尺寸,超大图片 compressed 会引起开卡顿
      sourceType:['album', 'camera'], //['album', 'camera'] 选择图片的来源
    },
    qnConfVideo:{
      accessKey:'uva-aaonM8dukeR6phc9yuPBrOXk9brrNW_PxLD7',
      secretKey:'oZMMVN6phk49lG0J1xwmi1Ju0ETT15EnAEWcU9Cs',
      token:'',
      bucket:'colorcun-attr',//存储空间
      fileType:'video',//image|video|audio|file def:file
      region:'华东',//存储区域
      domain:'http://nosqn.colorcun.com',//你绑定的域名,非必填项
    },
    upConfVideo:{
      prefixPath:'pinglun/videos/', //上传到七牛后有一个路径前缀,可为空
      loading:'ring',// none|leaf|circle|ring, def leaf 上传的loading效果; none为无,可自行在page wxml中添加
      group:'video', //一个页面上多个组件的区分标识
      security:false, // 开启非法检测,默认 false
      //上传图片
      count:6, //最多可以选择的图片张数
      sizeType:['compressed'],  //['original', 'compressed'] 所选的图片的尺寸,超大图片 compressed 会引起开卡顿
      sourceType:['album', 'camera'], //['album', 'camera'] 选择图片的来源
    },
    hasAddFile:true,//出现上传加号
    isnoshow:1,   //是否匿名
    filesHttps:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options',{...options});
    this.options=options
    this.data.types=options.types?options.types:'1';
    this.initPage()
  },
  async initPage(){
    try{
      this.setData({
        labels:await DA.getLabels(),
        sellername:this.options.sellername,
        loading:1,
      })
    }catch(e){
      this.setData({
        loading:-1,
      })
    }
  }

  ,

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  statVal:5,
  statEvent(e){
    //console.log('statEvent',e.detail.value)
    this.statVal=e.detail.value
  },
  // 获取上传的图片或者视频
  tpupload(e){
    this.setData({
      filesHttps:e.detail.filesHttps,
    })
  },
  displayImage(e){
    let path=util.attr(e,'path')
    let duration=util.attr(e,'duration')
    if(duration){
      return util.toast('发布后才能播放')
    }
    wx.previewImage({
      urls:[path],
    })
  },
  labelTap(e){
    let labels=this.data.labels
    labels[util.attr(e,'index')].active=!labels[util.attr(e,'index')].active
    this.setData({
      labels:labels,
    })
  },
  text:'',
  textareaInput(e){
    this.text=util.val(e).trim();
  },
  submit(){
    let eval_label=[]
    this.data.labels.some(l=>{
      if(l.active){
        eval_label.push(l.name)
      }
    })
    if(eval_label.length<1) return util.toast('请选择标签','none')
    wx.showToast({
      icon: 'none',
      title: '提交中,请稍后!',
    })
    let params={
      sid:this.options.sid,
      rid:this.options.oid,
      eval_label:eval_label.toString(),
      author_openid:getApp().openid,
      enclosure:JSON.stringify(this.data.filesHttps),
      identity:1,
      text:this.text||'',
      types:this.data.types,//types为1时  rid就是预订ID   types为2时   rid就是套餐ID  types为3时  rid就是卡券ID
      grade:this.statVal,
	    isnoshow:this.data.isnoshow
    }
    App.User.SetComment(params).then(res=>{
      if(res.ret!=200){
        return util.toast(res.msg,'none');
      }
      // types  3卡券验券评论
      if(this.data.types=='3'){
        this.commentFun()
      }else{
        wx.redirectTo({
          url:'./success?sellername='+this.options.sellername
        })
      }
    }).catch(e=>{
      console.log('catch',e);
    })
  },
  // 设置券订单评论状态	
  commentFun(){
    App.Activity.SetNewRechargeOrderByIsComment({
      id:this.options.oid
    }).then(res=>{
      console.log(res);
      wx.redirectTo({
        url:'./success?sellername='+this.options.sellername
      })
    })
  },
  setnoshow(){
	this.setData({
		isnoshow:!this.data.isnoshow
	})  
  },
})