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

  /**
   * 组件的初始数据
   */
  data: {
    ddate_Str:'',
  },
  attached(){
    //this.init()
  },
  observers: {
    'detail': function() {
      this.init()
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init(){
      let detail=this.data.detail
      if(!detail) return;
      detail.tables=[]
      detail.room_demand.some(t=>{
        detail.tables.push([t.name])
      })
      detail.ddateStr=util.unixtoTime(detail.ddate,'MM月DD日,`DAY/周WW`')
      console.log('detail.init',detail)
      this.getLocalLunchTime(detail.sid,detail.date,detail.section)
      this.setData({
        reserve:detail,
      })
    },
    //获取日期对应的多时段
    getLocalLunchTime(sid,date,section){
        App.Seller.getMealSectionByDay({
            sellerid: sid,
            day: date,
        }).then(res => {
            let data = res.data;
            let lunchDinnerList = [];
            if (data.length <= 3 && !data[0].ddate_solt) {
                data.forEach(i => {
                    if (i.mname == '早餐') {
                        lunchDinnerList.push({
                            mname: "早餐",
                            mdate: i.mdate,
                            ddate_solt: 1,
                        })
                    }
                    if (i.mname == '午餐') {
                        lunchDinnerList.push({
                            mname: "午餐",
                            mdate: i.mdate,
                            ddate_solt: 2,
                        })
                    }
                    if (i.mname == '晚餐') {
                        lunchDinnerList.push({
                            mname: "晚餐",
                            mdate: i.mdate,
                            ddate_solt: 3,
                        })
                    }
                })
            } else {
                lunchDinnerList = data;
            }
            lunchDinnerList.forEach((item,index)=>{
                item.section = 'ket'+index
            })
            let obj=lunchDinnerList.filter(item=>{return item.section == section})
            if(obj && obj.length>0){
                this.setData({
                    ddate_Str:obj[0].mname
                })
            }
        }).catch(res => {
            console.log(res, '获取多时段失败');
        })
    },
  }
})