card.js 3.32 KB
// components/2.0/reserve/card.js
import util from '../../../utils/util';
import App from '../../../utils/api';
import RS from '../../../utils/reserveStatus'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    detail:Object,
	tabType:Number
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  attached(){
    //this.init()
  },
  observers: {
    'detail': function() {
      this.init()
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init(){
      let detail=RS.reserve(this.data.detail)
      console.log('detail.init',detail)
      let tableSubInfo = ''
      let tableFirst = '';
      if (detail.tableFirst) {
        tableSubInfo = (detail.tableFirst || '') + ' ' + (detail.tableSubInfo || '');
        tableFirst = detail.tableFirst
      } else if(detail.tables && detail.tables.length>0) {
        tableFirst = detail.tables[0].name
        tableSubInfo = detail.tables[0].name;
        if (detail.tables.length > 1) {
          tableSubInfo += ' 等' + (detail.tables.length) + '个'
            + (detail.tables[0].tid == 2 ? '包间' : '');
          tableFirst += '等';
        }
      }
      detail.tableFirst=tableFirst
      detail.tableSubInfo=tableSubInfo
      this.setData({
        reserve:detail,
      })
	  console.log('666666',detail);
		  
	  if(this.data.tabType==6){
		this.remark('auto');  
	  }
	  
    },
	openlocation(){
		console.log('6666666')
		wx.openLocation({
		     latitude:Number(this.data.reserve.seller.lat),
		     longitude:Number(this.data.reserve.seller.long),
		     scale: 18
		})
	},
	remark(action='click'){
		App.Customer.CheckIsComment({rid:this.data.reserve.id}).then(res => {
		  console.log('66666fffffff',res)		
		  this.setData({
		    hasComment:res.data!=1,//已评论
		  })
		  if(action=='click'){
			if(res.data==0){
						wx.navigateTo({
							url:'/pages/pinglun/create?sid='+this.data.reserve.seller.id+'&oid='+this.data.reserve.id+'&sellername='+this.data.reserve.seller.sellername
						})  
			}else{
						wx.showToast({
							title:'该订单已评论',
							icon:'none'
						})  
			}  
		  }
		  
		  
		}) 
		
	},
	cookbook() {
	  if (this.data.reserve.order && this.data.reserve.order.cookbooklist.length > 0) {
	    wx.navigateTo({
	      url: util.http_build_query({
	        rid: this.data.reserve.id,
	        oid: this.data.reserve.order.id,
	        identity: 1
	      }, '/pack-cookbook/pages/success')
	    });
	  } else {
	    App.Advance.CreateOrder({
	      rid: this.data.reserve.id,
	      openid: getApp().openid,
	    }).then(res => {
	      if (res.ret != 200) {
	        return util.toast(res.msg, 'none')
	      }
	      wx.navigateTo({
	        url: util.http_build_query({
	          rid: this.data.reserve.id,
	          oid: res.data.id,
	          identity: 1,
	          sid: res.data.sellerid
	        }, '/pack-cookbook/pages/index')
	      });
	    })
	  }
	
	},
	checkout(){
		  if(this.data.reserve.status==0){
	    this.selectComponent('#showModal').options({
	      header: '您点早啦!',
	      body: '商家分配包间后,您可以通过在线买单支付,无需到前台结账排队等发票。'
	    }).show();
	  }else{
	    wx.navigateTo({
	      url:util.http_build_query({
	        rid:this.data.reserve.id,
	        sid:this.data.reserve.seller.id
	      },'/pack-checkout/pages/index')
	    })
	  }
	},
  }
})