<template>
  <div>
    <div class="query-box" style="border-bottom: none;">
      <ul>
        <li>
          <input type="button" class="fr normalBtn mb30" value="保存" @click="saveList(1)" />
          <input type="button" class="fr normalBtn mb30" value="保存草稿" @click="saveList(0)" />
        </li>
      </ul>
    </div>
    <div style="width: 100%;  overflow-x: auto;padding-bottom: 10px; " class="ownScrollbarStyle">
      <table border="0" cellspacing="1" cellpadding="0" class="bookDinnerStatisticsTalbe" v-loading="loading">
        <tr>
          <th>
            公司团号
          </th>
          <th colspan="17" style="text-align:left;">
            <p class="link" @click="goUrlT('productQuery',TCNUM,'产品查询')">{{TCNUM}}</p>
          </th>
        </tr>
        <tr>
          <th width="150">用餐时间</th>
          <th width="250">餐厅名称</th>
          <th width="160">修改餐厅</th>
          <th width="80">类别</th>
          <th width="200" style="display:none;">餐饮类型</th>
          <th width="80">总人数</th>
          <th width="70">用餐人<br />类型</th>
          <th width="70">用餐<br />人数</th>
          <th width="100">价格</th>
          <th width="100">免人数</th>
          <th width="80">金额小计</th>
          <th width="100">返佣</th>
          <th width="120">总金额</th>
          <th width="210">付款方式/订餐方式/订团号</th>
          <th width="80">备注</th>
        </tr>
        <template v-for="(item,index) in list">
          <template v-for="(subItem,subIndex) in item.DiningSummaryList">
            <tr v-for="(childItem,childIndex) in subItem.DiningPriceList">
              <td v-if="childIndex==0" :rowspan="3">
                {{item.UseTimeStr}}
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                <table class="dinnerTable">
                  <tr>
                    <td colspan="2">
                      <span style="padding-left:5px;" class="link"
                        @click="goUrlR('restaurantList',subItem.DiningID,'餐厅列表')">{{subItem.DiningName}}</span>
                    </td>
                  </tr>
                  <tr>
                    <td width="40">
                      电话：
                    </td>
                    <td style="text-align:left;">
                      {{subItem.Tel}}
                    </td>
                  </tr>
                  <tr>
                    <td width="40">
                      地址：
                    </td>
                    <td style="text-align:left;">
                      {{subItem.Address}}
                    </td>
                  </tr>
                </table>
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                <el-select class='w160 sel' v-model='subItem.NewDiningID' filterable :placeholder="$t('pub.pleaseSel')"
                  @visible-change='getDingList(item)' @change='sendValue(subItem,item)'>
                  <el-option v-for='itemHotel in item.DinnerList' :label='itemHotel.Name' :value='itemHotel.ID'
                    :key='itemHotel.ID'></el-option>
                </el-select>
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                {{subItem.UseDinnerTypeStr}}
              </td>
              <td v-if="childIndex==0" :rowspan="3" style="display:none;">
                {{subItem.MealName}}
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                {{GuestNum}}
              </td>
              <td>
                {{personStrToWord(childItem.PeopleType)}}
              </td>
              <td>
                {{childItem.PeopleNum}}
              </td>
              <td>
                <span class="spanlink" v-if='childItem.PeoplePrice==0'
                  @click="goUrl('RestaurantPackage',subItem,'套餐查询')">设置</span>
                <span v-if='childItem.PeoplePrice!=0'>{{childItem.PeoplePrice}}</span>
              </td>
              <td>
                <el-input class='w50 tcenter' @input='calculationPrice(subItem)' maxlength='2'
                  v-model='childItem.Discount' @keyup.native="checkInteger(childItem,'Discount')"></el-input>
              </td>
              <td>
                {{(childItem.PeopleNum-childItem.Discount)*childItem.PeoplePrice}}
              </td>
              <td>
                <el-input class='w50 tcenter' @input='calculationPrice(subItem)' v-model='childItem.DiscountPrice'
                  @keyup.native="checkInteger(childItem,'DiscountPrice')"></el-input>%
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                {{subItem.TotalPrice}}
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                <table class="dinnerTable">
                  <tr>
                    <td width="60" style="text-align:right;">
                      付款方式：
                    </td>
                    <td style="text-align:left;">
                      <el-select class='w135 sel' v-model='subItem.PayStyle' :placeholder="$t('pub.pleaseSel')">
                        <el-option label='请选择' value='0'></el-option>
                        <el-option label='现付' value='1'></el-option>
                        <el-option label='签单' value='2'></el-option>
                        <el-option label='实物抵扣' value='3'></el-option>
                        <el-option label='预付' value='4'></el-option>
                      </el-select>
                    </td>
                  </tr>
                  <tr>
                    <td width="60" style="text-align:right;">
                      订餐方式：
                    </td>
                    <td style="text-align:left;">
                      <el-select v-model='subItem.DiningReserveType' class='w135 sel'
                        :placeholder="$t('pub.pleaseSel')">
                        <el-option label='请选择' value='0'></el-option>
                        <el-option label='公司预订' value='1'></el-option>
                        <el-option label='导游预订' value='2'></el-option>
                      </el-select>
                    </td>
                  </tr>
                  <tr>
                    <td width="60" style="text-align:right;">
                      订团号：
                    </td>
                    <td style="text-align:left;">
                      <el-input class='w135 tcenter' v-model='subItem.ReserveNo'></el-input>
                    </td>
                  </tr>
                </table>
              </td>
              <td v-if="childIndex==0" :rowspan="3">
                <el-input type='textarea' rows="4" class='w120' v-model='subItem.Remarks'></el-input>
              </td>
            </tr>
          </template>
        </template>
      </table>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        defaultSelectValue: 0,
        list: [],
        roomList: [],
        TCNUM: "",
        flightTotal: 0,
        GuestNum: 0,
        loading: false,
      };
    },
    methods: {
      //页面跳转[大写]
      goUrlR(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            ID: obj,
            blank: 'y',
            tab: title
          }
        });
      },
      //页面跳转[小写]
      goUrlT(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            id: obj,
            blank: 'y',
            tab: title
          }
        });
      },
      goUrl(path, obj, name) {
        this.$router.push({
          path: path,
          query: {
            id: obj.DiningID,
            blank: "y",
            tab: name
          }
        });
      },
      personStrToWord(str) {
        if (str == 1)
          return '大人'
        if (str == 2)
          return '儿童'
        if (str == 3)
          return '婴儿'
      },
      getList() {
        this.loading = true;
        this.apipost(
          "dmcstatistics_get_GetDinnerStaticsDetail", {
            TCIDs: this.$route.query.id
          },
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              this.list = res.data.data;
              this.list.forEach(item => {
                item.DinnerList = [];
                item.DiningSummaryList.forEach(x => {
                  x.PayStyle = x.PayStyle.toString();
                  x.DiningReserveType = x.DiningReserveType.toString();
                  this.calculationPrice(x);
                  item.DinnerList.push({
                    Name: x.NewDiningName,
                    ID: x.NewDiningID
                  })
                  if (x.ReserveNo == '' || x.ReserveNo == null) {
                    x.ReserveNo = this.$route.query.NewCombinationNum;;
                  }
                })
              })
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      calculationPrice(obj) {
        let totalPrice = 0;
        obj.DiningPriceList.forEach(item => {
          totalPrice += item.PeoplePrice * (item.PeopleNum - item.Discount) * (1 - item.DiscountPrice / 100);
        })
        obj.TotalPrice = totalPrice.toFixed(2);
      },
      saveList(type) {
        if (type == 0) {
          this.list.forEach(item => {
            item.DiningSummaryList.forEach(insideItem => {
              insideItem.OrderState = 0;
            })
          })
        }
        if (type == 1) {
          this.list.forEach(item => {
            item.DiningSummaryList.forEach(insideItem => {
              insideItem.OrderState = 1;
            })
          })
        }
        this.apipost('dmcstatistics_get_SetDiningOrder', this.list, res => {
          if (res.data.resultCode == 1) {
            this.$message.success(res.data.message);
            this.getList();
          } else {
            this.$message.error(res.data.message);
          }
        }, err => {})
      },
      //获取餐厅下拉
      getDingList(item) {
        let msg = {
          QCity: item.DiningSummaryList[0].QCity
        }
        this.apipost('dining_post_GetLineDinnerList', msg, res => {
          if (res.data.resultCode == 1) {
            item.DinnerList = res.data.data;
            this.$forceUpdate();
          } else {
            this.Error(res.data.message)
          }
        }, err => {})
      },
      //重置电话地址
      sendValue(subItem, item) {
        item.DinnerList.forEach(x => {
          if (subItem.NewDiningID == x.ID) {
            subItem.Address = x.Address;
            subItem.Tel = x.Tel;
          }
        })
      },
    },
    mounted() {
      this.TCNUM = this.$route.query.TCNUM;
      this.GuestNum = this.$route.query.GuestNum;
      this.getList();
    }
  };

</script>

<style>
  .bookDinnerStatisticsTalbe {
    border-collapse: collapse;
    background: #fff;
    text-align: center;
  }

  .bookDinnerStatisticsTalbe tr th {
    background: #eee;
    height: 40px;
    font-size: 12px;
    color: #333;
    border: 1px solid #d1d1d1;
  }

  .bookDinnerStatisticsTalbe tr td {
    font-size: 12px;
    height: 25px;
    line-height: 25px;
    border: 1px solid #d1d1d1;
  }

  .bookDinnerStatisticsTalbe tr td input {
    height: 20px !important;
    padding: 0;
    text-align: center;
  }

  .bookDinnerStatisticsTalbe tr td .sel input {
    height: 34px !important;
  }

  .bookDinnerStatisticsTalbe tr td .link:hover {
    text-decoration: underline;
    cursor: pointer;
  }

  .bookDinnerStatisticsTalbe tr td .spanlink:hover {
    text-decoration: underline;
    cursor: pointer;
  }

  .bookDinnerStatisticsTalbe .dinnerTable {
    border: none;
  }

  .bookDinnerStatisticsTalbe .dinnerTable tr td {
    border: none;
  }

</style>
