seller-card.js 3.08 KB
// components/seller-card/seller-card.js
import util from '../../utils/util';
import RS from '../../utils/reserveStatus'

Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {
    seller: Object,
    detail: {
      type: Object,
      value: {},
      observer: function () {
        //console.log('observer', arguments);
        this.init();
      }
    },
    hasMaster: { //预订人+手机
      type: Boolean,
      value: false
    },
    hasListShare: { //首页列表的预订人+分享
      type: Boolean,
      value: false
    },
    hasShowStatus: { //右上角显示状态
      type: Boolean,
      value: false
    },
    hasAddress: { //显示地址,默认显示
      type: Boolean,
      value: true
    },
    hasOnlineReserve:{ //是否为在线预订卡片
      type: Boolean,
      value: false
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    rdateStr: "",
    tableSubInfo: "",
    masterMan: "",
  },
  attached() {

  },
  detached() {

  },
  /**
   * 组件的方法列表
   */
  methods: {
    init() {
      if (this.data.detail && this.data.detail.ddate) {
        let masterMan = (this.data.detail.rname || '');
        if (this.data.detail.phone) {
          masterMan += ' (' +
            this.data.detail.phone
              .replace(/([\d]{2}).*([\d]{4})/, function ($0, $1, $2) {
                return $1 + '*' + $2
              })
            + ')';
        }
        let tableSubInfo = ''
        let tableFirst = '';
        if (this.data.detail.tableFirst) {
          tableSubInfo = (this.data.detail.tableFirst || '') + ' ' + (this.data.detail.tableSubInfo || '');
          tableFirst = this.data.detail.tableFirst
        } else if(this.data.detail.tables && this.data.detail.tables.length>0) {
          tableFirst = this.data.detail.tables[0].name
          tableSubInfo = this.data.detail.tables[0].name;
          if (this.data.detail.tables.length > 1) {
            tableSubInfo += ' 等' + (this.data.detail.tables.length) + '个'
              + (this.data.detail.tables[0].tid == 2 ? '包间' : '');
            tableFirst += '等';
          }
        }

        let obj = {
          rdateStr: util.unixtoTime(this.data.detail.ddate, 'MM月DD日 HH:II'),
          tableSubInfo: tableSubInfo,
          tableFirst: tableFirst,
          masterMan: masterMan,
        }
        if (this.data.hasShowStatus) {
          obj.showStatusStr = RS.reserve(this.data.detail).getStatusStr;
        }
        this.setData(obj)
      }
    },
    lookLocation: function () {
      //console.log(this.data.seller.lat,this.data.seller.long,this.data.detail.map_address)
      wx.openLocation({
        latitude: Number(this.data.seller.lat),
        longitude: Number(this.data.seller.long),
        scale: 17,
        address: this.data.seller.map_address,
        success: function (res) {
          console.log(res)
        }
      })
    },
    tapEvent(){
      this.triggerEvent('event',{
        act:'gotoDetail',
        detail:this.data.detail,
      })
    },
  }
})