index.js 5.65 KB
// pack-book/pages/checkout/index.js
import util from '../../../utils/util';
import App from '../../../utils/api';
import RS from '../../../utils/reserveStatus';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    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:'paylist/images/', //上传到七牛后有一个路径前缀,可为空
      loading:'ring',// none|leaf|circle|ring, def leaf 上传的loading效果; none为无,可自行在page wxml中添加
      group:'def', //一个页面上多个组件的区分标识
      security:false, // 开启非法检测,默认 false

      //上传图片
      count:5, //最多可以选择的图片张数
      sizeType:['compressed'],  //['original', 'compressed'] 所选的图片的尺寸,超大图片 compressed 会引起开卡顿
      sourceType:['album', 'camera'], //['album', 'camera'] 选择图片的来源

    },
    files:[], //组件数据放入这里展示到页面上
    hasAddFile:true,//出现上传加号
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.options=options
    this.setData({
      [`upConf.prefixPath`]:'paylist/'+options.rid+'/'
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDetail();
  },

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

  },

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

  },

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

  },

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

  },
  detail:null,
  getDetail(hasCache=false){
    App.Reserve.Detail({
      openid: getApp().openid,
      rid: this.options.rid
    },hasCache).then(async res => {
      this.detail=this.formatDatail(res.data)
      this.detail.ddate_solt=Number(this.detail.ddate_solt);
      let title=''
      if(this.detail.order_info.status>1){
        title='买单申请详情'
      }
      //debug
      //this.detail.order_info.status=1
      this.setData({
        detail: this.detail,
        title:title,
      })
      if(this.detail.order_info && this.detail.order_info.status==3){
        App.Customer.GetOrderInfo({
          rid:this.options.rid
        }).then(res=>{
          let discount={pt:0,se:0}
          res.data.discount.forEach(q=>{
            if(q.checked){
              if(q.owner==1){//平台
                discount.pt+=parseFloat(q.price)
              }else{
                discount.se+=parseFloat(q.price)
              }
            }
          })
          this.setData({
            discount:{
              pt:discount.pt.toFixed(2),
              se:discount.se.toFixed(2),
              //price:(this.detail.order_info.price-discount.se).toFixed(2)
              price:(this.detail.order_info.should_price*1+discount.pt*1).toFixed(2)
            }
          })
        })
      }
    })
  },
  formatDatail(detail) {
    detail=RS.reserve(detail);
    let formatDate='YYYY-MM-DD '+detail.soltName
    if(detail.type==1 && detail.is_set_ddate==1){
      formatDate +=' HH:II'
    }
    detail.rdateStr = util.unixtoTime(detail.ddate, formatDate);
    detail.orderRemark='';
    if(detail.order_info){
      if(detail.order_info.is_wine==1 || detail.order_info.is_pack==1){
        detail.orderRemark='*顾客'
        let orderRemark=[]
        if(detail.order_info.is_wine==1){
          orderRemark.push('有酒水要退')
        }
        if(detail.order_info.is_pack==1){
          orderRemark.push('菜品需要打包')
        }
        detail.orderRemark+=orderRemark.join(',')
      }
    }
    return detail;
  },
  displayTables(){
    if(this.data.tabs){
      this.setData({
        tabs:'',
      })
      return;
    }
    let tables=this.detail.tables
    let tabs={}
    tables.some(t=>{
      if(!tabs[t.tid]){
        tabs[t.tid]=t.name
      }else{
        tabs[t.tid]+="、"+t.name
      }
    })
    this.setData({
      tabs:tabs,
    })
  },
  setPrice(e){
    this.price=e.detail.value.replace(/[^\.\d]/g,'')
    this.setData({
      price:this.price
    })
    return this.price
  },
  qnevent(e){
    console.log('qnevent',e.detail);
    let files=e.detail.data
    if(e.detail.act=='uploadFail'){
      files[e.detail.fileCurrent].progress=Math.random().toFixed(2)
    }
    files.forEach(f=>{
      if(f.progress==100){
        if(!f.remote || !f.remote.url){
          f.progress=(90+Math.random()*9).toFixed(2)
        }
      }
    })
    this.setData({
      files:files,
      hasAddFile:files.length<this.data.upConf.count
    })
  },
  displayImage(e){
    let path=util.attr(e,'path')
    wx.previewImage({
      urls:[path],
    })
  },
  displayOrderImages(){
    if(this.detail.order_info.bill_list.length>0){
      wx.previewImage({
        urls:this.detail.order_info.bill_list,
      })
    }
  },
  deleteImage(e){
    let index=util.attr(e,'index')
    let files=this.data.files
    files.splice(index,1)
    this.setData({
      files:files,
      hasAddFile:files.length<5
    })
    util.toast('图片已删除','none')
  },
  submit(){
    this.selectComponent('#confirm-price').show(this.options.rid,this.data.files)
  },
  confirmPriceEvent(){
    this.getDetail(true);
  },
})