<style>
  /* 日期样式开始 */
  .RestaurantSalesBoard .month ul {
    border-radius: 4px 4px 0 0;
    width: 100%;
    height: 50px;
    line-height: 50px;
    background: #e95252;
    margin: 0;
    padding: 0;
    text-align: center;
  }

  .RestaurantSalesBoard .year-month {
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
  }

  .RestaurantSalesBoard .year-month>input {
    width: 100px;
    float: left;
  }

  .RestaurantSalesBoard .arrow {
    padding: 10px;
    font-style: normal;
    cursor: pointer;
  }

  .RestaurantSalesBoard .monthminus {
    position: absolute;
    left: 0px;
    top: 15px;
  }

  .RestaurantSalesBoard .monthadd {
    position: absolute;
    right: 21px;
    top: 15px;
  }

  .RestaurantSalesBoard .month ul li {
    font-size: 18px;
    color: #fff;
    position: relative;
    display: inline-block;
    letter-spacing: 3px;
  }

  .RestaurantSalesBoard .month ul li i {
    font-size: 22px;
    color: #ff7e7e;
    cursor: pointer;
  }

  .RestaurantSalesBoard .month ul li>input {
    text-align: center;
  }

  .RestaurantSalesBoard .weekdays {
    margin: 0;
    padding: 3px 0;
    background-color: #3fa783;
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    color: #fff;
    justify-content: space-around;
  }

  .RestaurantSalesBoard .weekdays li {
    display: inline-block;
    width: 14.2857%;
    text-align: center;
  }

  .RestaurantSalesBoard .days {
    width: 100%;
    padding: 0;
    margin: 0;
    border-left: 1px solid #dddddd;
    flex-wrap: wrap;
    box-sizing: border-box;
    justify-content: space-around;
  }

  .RestaurantSalesBoard .days>li {
    list-style-type: none;
    width: 14.2857%;
    height: 140px;
    text-align: center;
    position: relative;
    font-size: 12px;
    float: left;
    color: #000;
    box-sizing: border-box;
    border-right: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
  }

  .RestaurantSalesBoard .days li>div {
    height: 112px;
    width: 100%;
    overflow-y: auto;
    text-align: left;
  }

  .RestaurantSalesBoard .days li>div>p {
    border-bottom: 1px dashed #ccc;
    height: 28px;
    line-height: 28px;
    width: 100%;
    text-indent: 10px;
  }

  .RestaurantSalesBoard .currentInput {
    width: 120px;
    height: 30px;
    border-radius: 17px;
    outline: none;
    border: none;
    color: #fff;
    background: transparent;
    font-size: 18px;
  }

  .RestaurantSalesBoard .days li .other-month {
    display: inline-block;
    position: absolute;
    right: 0;
    bottom: 0;
    width: 24px;
    height: 17px;
    font-size: 12px;
    line-height: 17px;
    background-color: #cccccc;
    color: #fff;
  }

  .RestaurantSalesBoard .ckStyle {
    width: 100%;
    height: 28px;
    line-height: 28px;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    background: #ccc;
    color: #000;
  }

  .RestaurantSalesBoard .ckStyleOther {
    background: #dddddd !important;
    font-weight: normal !important;
    color: #999;
  }

  .RestaurantSalesBoard .Owe_Room {
    color: #e95252;
  }

  .RestaurantSalesBoard .Used_room {
    color: #13b0ae;
  }

  .RestaurantSalesBoard .otherMoth {
    background: #f2f2f2;
  }

  .RestaurantSalesBoard .title {
    height: 14px;
    line-height: 14px;
    border-left: 3px solid #e95252;
    font-size: 16px;
    color: #333;
    text-indent: 10px;
    margin: 20px 0;
  }

  .RestaurantSalesBoard .hasStock_1 {
    color: #FFFFFF;
    background-color: #ff3737;
  }

  .RestaurantSalesBoard .hasStock_2 {
    background-color: #ff99cc;
  }

  .RestaurantSalesBoard .hasStock_3 {
    background-color: #bcd6ee;
  }

  .RestaurantSalesBoard .hasStock_4 {
    background-color: #ffffff;
  }

  /* 日期样式结束*/

</style>
<template>
  <div class="flexOne RestaurantSalesBoard">
    <div class="query-box Plan_Query">
      <ul>
        <li>
          <span>
            <em>{{$t('commonPickUp.Pick_resName')}}</em>
            <el-select v-model="msg.DiningID" :placeholder="$t('pub.pleaseSel')" filterable>
              <el-option :label="$t('pub.unlimitedSel')" :value="defaultSelectValue"></el-option>
              <el-option v-for="item in DinnerList" :key="item.ID" :label="item.Name" :value="item.ID"></el-option>
            </el-select>
          </span>
        </li>
        <li >
          <span>
            <em>{{$t('advmanager.v_type')}}</em>
            <el-select v-model="msg.QStatus" :placeholder="$t('pub.pleaseSel')" filterable>
              <el-option  :key="0" :label="$t('ground.dijiectdd')" :value="0"></el-option>
              <el-option  :key="1" :label="$t('ground.xingchct')" :value="1"></el-option>
            </el-select>
          </span>
        </li>
        <li style="margin-right:50px;">
          <button class="normalBtn" type="button" @click="GetHoltelInventory()">{{$t('pub.searchBtn')}}</button>
          <button class="normalBtn" type="button" @click="DownLoadDinnerSalesBoard()">{{$t('adm.adm_download')}}</button>
        </li>
      </ul>
    </div>
    <div class="title">
      {{$t('ground.canttongjig')}}
      <span class="Owe_Room">{{TotalInventory}}</span>
    </div>
    <div class="month">
      <ul>
        <li>
          <i class="el-icon-caret-left monthminus" @click="currentYear-=1,getDateString(),initCalendar(dateString)"></i>
          <input type="text" disabled="disabled" v-model="currentYear" class="currentInput"
            @input="getDateString(),initCalendar(dateString)">{{$t('pub.year')}}
          <i class="el-icon-caret-right monthadd" @click="currentYear+=1,getDateString(),initCalendar(dateString)"></i>
        </li>
        <li>
          <i class="el-icon-caret-left monthminus" @click="pickPre(currentYear,currentMonth)"></i>
          <input type="text" disabled="disabled" v-model="currentMonth" class="currentInput"
            @input="getDateString(),initCalendar(dateString)">{{$t('pub.month')}}
          <i class="el-icon-caret-right monthadd" @click="pickNext(currentYear,currentMonth)"></i>
        </li>
      </ul>
    </div>

    <ul class="weekdays">
      <li>{{$t('hotel.hotel_Monday')}}</li>
      <li>{{$t('hotel.hotel_Tuesday')}}</li>
      <li>{{$t('hotel.hotel_Wednesday')}}</li>
      <li>{{$t('hotel.hotel_Thursday')}}</li>
      <li>{{$t('hotel.hotel_Friday')}}</li>
      <li>{{$t('hotel.hotel_Saturday')}}</li>
      <li>{{$t('hotel.hotel_Sunday')}}</li>
    </ul>
    <ul class="days clearfix" v-loading="msg.loading">
      <li v-for="(dayItem,index) in days" :key="dayItem.index">
        <p class="ckStyle" :class="{ckStyleOther:dayItem.day.getMonth()+1 != currentMonth}">{{dayItem.day.getDate()}}
        </p>
        <div>
          <p v-for="item in dayItem.dayValue">
            <span class="text_underLine">{{item.DinnerName}}（{{item.DiningNum}}）</span>
          </p>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        msg: {
          Year: 0,
          Month: 0,
          DiningID: 0,
          QStatus:0,
          loading: false,
          uid:0,
        },
        //餐厅列表
        DinnerList: [],
        defaultSelectValue: 0,
        currentDay: 1,
        currentMonth: 1,
        currentYear: 1970,
        currentWeek: 1,
        days: [],
        //每天的机位库存
        DayData: [],
        //总库存
        TotalInventory: 0,
        //使用库存
        UseInventory: 0
      };
    },
    methods: {
      stockColor: function (type) {
        if (type === 1) {
          return 'hasStock_1'
        } else if (type === 2) {
          return 'hasStock_2'
        } else if (type === 3) {
          return 'hasStock_3'
        } else if (type === 4) {
          return 'hasStock_4'
        }
      },
      //格式化日期
      getDateString: function () {
        this.dateString = this.$calendarUtils.formatDate(
          this.currentYear,
          this.currentMonth,
          1
        );
        this.GetHoltelInventory();
      },
      initCalendar: function (cur) {
        var newDays = this.$calendarUtils.createCalendar(cur);
        this.currentDay = newDays.CurrentDay;
        this.currentYear = newDays.CurrentYear;
        this.currentMonth = newDays.CurrentMonth;
        this.currentWeek = newDays.CurrentWeek;
        this.days.length = 0;
        var dateArray = newDays.DayArray;
        for (var i = 0; i < dateArray.length; i++) {
          var d = dateArray[i].day;
          var dayobject = {};
          dayobject.day = d;
          this.days.push(dayobject);
        }
      },
      //点击左箭头切换年月
      pickPre: function (year, month) {
        var d = new Date(this.$calendarUtils.formatDate(year, month, 1));
        d.setDate(0);
        this.nowDate = d.getFullYear() + "-" + (d.getMonth() + 1) + "-1";
        this.initCalendar(
          this.$calendarUtils.formatDate(d.getFullYear(), d.getMonth() + 1, 1)
        );
        this.GetHoltelInventory();
      },
      //点击右箭头切换年月
      pickNext: function (year, month) {
        var d = new Date(this.$calendarUtils.formatDate(year, month, 1));
        d.setDate(35);
        this.nowDate = d.getFullYear() + "-" + (d.getMonth() + 1) + "-1";
        this.initCalendar(
          this.$calendarUtils.formatDate(d.getFullYear(), d.getMonth() + 1, 1)
        );
        this.GetHoltelInventory();
      },
      //点击获取酒店库存数据
      GetHoltelInventory() {
        this.msg.loading = true;
        var that = this;
        this.msg.Year = this.currentYear;
        this.msg.Month = this.currentMonth;
        this.DayData = [];
        this.apipost(
          "order_post_GetDinnerMonthStatistics",
          this.msg,
          res => {
            this.msg.loading = false;
            this.DayData = res.data.data;
            this.UseInventory = 0;
            this.TotalInventory = 0;
            this.days.forEach(dayItem => {
              let d = dayItem.day;
              let myDate = this.$calendarUtils.formatDate(
                d.getFullYear(),
                d.getMonth() + 1,
                d.getDate()
              );
              dayItem.dayValue = [];
              for (var j = 0; j < this.DayData.length; j++) {
                if (this.DayData[j].Day == myDate) {
                  dayItem.dayValue = this.DayData[j].SubList;
                  this.DayData[j].SubList.forEach(sunItem => {
                    that.TotalInventory = parseFloat(this.TotalInventory) + parseFloat(sunItem.DiningNum)
                  });
                }
              }
            });
            this.$forceUpdate();
          },
          err => {}
        );
      },
      //获取酒店列表
      GetDinnerList() {
        this.apipost(
          "dining_post_GetList", {
            QCountrys: "651,1252"
          },
          res => {
            if (res.data.resultCode == 1) {
              this.DinnerList = res.data.data;
            }
          },
          err => {}
        );
      },
      //下载餐厅统计
      DownLoadDinnerSalesBoard() {
        if (this.msg.DiningID <= 0) {
          this.Info(this.$t('sm.qxzcanting'));
          return;
        }
        this.msg.uid=this.getLocalStorage().EmployeeId;
        this.msg.loading = true;
        let fileName = this.$t('ground.cantxiazai') + this.$commonUtils.getCurrentDate() + ".xls";
        this.GetLocalFile("dinner_get_downloadDinnerSalesBoard", this.msg, fileName,
          res => {
            this.msg.loading = false;
          });
      }
    },
    mounted() {
      //初始化日历
      let myDate = new Date();
      this.currentYear = myDate.getFullYear();
      this.currentMonth = myDate.getMonth() + 1;
      this.msg.Year = this.currentYear;
      this.msg.Month = this.currentDay;

      this.GetDinnerList();
      this.initCalendar();
      this.GetHoltelInventory();
    }
  };

</script>
