<template>
  <div>
    <div class="query-box" style="border-bottom: none;" v-if="isShowBtn==1">
      <ul>
        <li>
          <input type="button" class="fr normalBtn mb30" :value="$t('objFill.v101.Rest.piliantyi')" @click="ChangeHotelInfo(2)" />
          <input type="button" class="fr normalBtn mb30" :value="$t('objFill.v101.Rest.pilianjjue')" @click="ChangeHotelInfo(3)" />
        </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 width="120">{{$t('salesModule.CompanyNum')}}</th>
          <th width="150">{{$t('restaurant.res_etTime')}}</th>
          <th width="200">{{$t('objFill.v101.Rest.yuanctminc')}}</th>
          <th width="200">{{$t('objFill.v101.Rest.xincantminc')}}</th>
          <th width="80">{{$t('objFill.v101.Rest.canyinleix')}}</th>
          <th width="150">{{$t('objFill.v101.Rest.yongcanrenlx')}}</th>
          <th width="80">{{$t('objFill.yongchanrenshu')}}</th>
          <th width="150">{{$t('Operation.Op_price')}}</th>
          <th width="80">{{$t('hotel.table_operat')}}</th>
        </tr>
        <tr v-for="(item,index) in list" :key="`d_`+index">
          <td :rowspan="list.length" v-if="index==0">
            <div class="w120">
              <p class="link" @click="goUrlT('productQuery',TCNUM,'产品查询')">{{TCNUM}}</p>
            </div>
          </td>
          <td>
            <div class="w120">{{item.UseTimeStr}}</div>
          </td>
          <td>
            <div class="w200">
              <p style="height: 84px; padding-left: 10px; display:flex; align-items:center;"
                v-for="(subItem,subIndex) in item.DiningSummaryList" class="link pHouseStyle"
                @click="goUrlR('restaurantList',subItem.DiningID,'餐厅列表')"
                :style="{color: subItem.DiningChangeState==1?'red':''}" :key="`d_s_n_`+index+subIndex">
                {{subItem.DiningName}}
                <br />
                {{$t('objFill.v101.traveltrip.zhenshixm')}}:{{subItem.DiningRealName}}
              </p>
            </div>
          </td>
          <td>
            <div class="w200">
              <p style="height: 84px; padding-left: 10px; display:flex; align-items:center;"
                v-for="(subItem,subIndex) in item.DiningSummaryList" class="link pHouseStyle"
                :style="{color: subItem.DiningChangeState==1?'red':''}" :key="`d_r_n_`+index+subIndex">
                {{subItem.NewDiningName}}
                <br />
                {{$t('objFill.v101.traveltrip.zhenshixm')}}:{{subItem.NewDiningRealName}}
              </p>
            </div>
          </td>
          <td>
            <div class="w80">
              <p style="height: 84px; line-height: 84px;" v-for="(subItem,subIndex) in item.DiningSummaryList"
                :key="`d_r_ds_`+index+subIndex" class="pHouseStyle">
                {{subItem.UseDinnerTypeStr}}
              </p>
            </div>
          </td>
          <td>
            <div class="w180">
              <div class="DivStyle" v-for="(subItem,subIndex) in item.DiningSummaryList"
                :key="`d_r_dspt_`+index+subIndex">
                <p v-for="(childItem,childIndex) in subItem.DiningPriceList"
                  :key="`d_r_dsptd_`+index+subIndex+childIndex">
                  {{personStrToWord(childItem.PeopleType)}}
                </p>
              </div>
            </div>
          </td>
          <td>
            <div class="w80">
              <div class="DivStyle" v-for="(subItem,subIndex) in item.DiningSummaryList"
                :key="`d_r_dsp_`+index+subIndex">
                <p v-for="(childItem,childIndex) in subItem.DiningPriceList"
                  :key="`d_r_dsp_d_`+index+subIndex+childIndex">
                  {{childItem.PeopleNum}}
                </p>
              </div>
            </div>
          </td>
          <td>
            <div>
              <div class="DivStyle" v-for="(subItem,subIndex) in item.DiningSummaryList"
                :key="`d_r_dsp_a_`+index+subIndex">
                <p v-for="(childItem,childIndex) in subItem.DiningPriceList"
                  :key="`d_r_dsp_b_`+index+subIndex+childIndex">
                  <span class="spanlink" v-if='childItem.PeoplePrice==0'
                    @click="goUrl('RestaurantPackage',subItem,'套餐查询')">{{$t('leader.leader_Set')}}</span>
                  <span v-if='childItem.PeoplePrice!=0'>{{childItem.PeoplePrice}}</span>
                </p>
              </div>
            </div>
          </td>
          <td>
            <div class="w120">
              <p style="height: 84px; padding-left: 10px; display:flex; align-items:center;"
                v-for="(subItem,subIndex) in item.DiningSummaryList" class="link pHouseStyle"  :key="`d_r_dsp_c_`+index+subIndex">
                <span v-if="subItem.DiningChangeState==1">
                  <input type="button" class="normalBtn" :value="$t('salesModule.Agree')" @click="HotelChangeState(subItem,2)" />
                  <input type="button" class="normalBtn" :value="$t('visa.v_jujue')" @click="HotelChangeState(subItem,3)" />
                </span>
              </p>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        list: [],
        TCNUM: "",
        isShowBtn: 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 this.$t('objFill.darens')[0]
        if (str == 2)
          return this.$t('sm.ertong')
        if (str == 3)
          return this.$t('Operation.Op_baby')
      },
      getList() {
        this.loading = true;
        this.apipost(
          "dmcstatistics_get_GetDinnerStaticsDetail", {
            TCIDs: this.$route.query.id
          },
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              var tempData = res.data.data;
              if (tempData && tempData.DiningList && tempData.DiningList.length > 0) {
                this.list = tempData.DiningList;
                if (this.list && this.list.length > 0) {
                  this.list.forEach(item => {
                    item.DinnerList = [];
                    item.DiningSummaryList.forEach(x => {
                      if (x.DiningChangeState > 0) {
                        this.isShowBtn = 1;
                      }
                    })
                  })
                }
              }
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      HotelChangeState(obj, State) {
        if (State == 2) { //给出提示
          obj.DiningChangeState = State;
          this.$confirm(this.$t('objFill.v101.Rest.shiftyjfgzqxx'), this.$t('tips.tips'), {
            confirmButtonText: this.$t('pub.sureBtn'),
            cancelButtonText: this.$t('pub.cancelBtn'),
            type: 'warning'
          }).then(() => {
            this.saveList(0);
          }).catch(() => {
            this.$message({
              type: 'info',
              message: this.$t('tips.cancleDelete')
            });
          });
        } else {
          this.saveList(0);
        }
      },
      ChangeHotelInfo(type) {
        if (type == 2) {
          this.$confirm(this.$t('objFill.v101.Rest.shiftyjfgzqxx'), this.$t('tips.tips'), {
            confirmButtonText: this.$t('pub.sureBtn'),
            cancelButtonText: this.$t('pub.cancelBtn'),
            type: 'warning'
          }).then(() => {
            this.list.forEach(item => {
              item.DinnerList = [];
              item.DiningSummaryList.forEach(x => {
                if (x.DiningChangeState > 0) {
                  x.DiningChangeState = 2;
                }
              })
            })
            this.saveList();
          }).catch(() => {
            this.$message({
              type: 'info',
              message: this.$t('tips.cancleDelete')
            });
          });
        } else if (type == 3) {
          this.list.forEach(item => {
            item.DinnerList = [];
            item.DiningSummaryList.forEach(x => {
              if (x.DiningChangeState > 0) {
                x.DiningChangeState = 3;
              }
            })
          })
          this.saveList();
        }
      },
      saveList() {
        this.apipost('dmcstatistics_post_SetUpdateDiningOrder', this.list, res => {
          if (res.data.resultCode == 1) {
            this.$message.success(res.data.message)
            this.getList()

          } else {
            this.$message.error(res.data.message)
          }
        }, err => {})
      },
    },
    mounted() {
      this.TCNUM = this.$route.query.TCNUM;
      this.getList();
    }
  };

</script>

<style>
  .bookDinnerStatisticsTalbe {
    background: #ccc;
  }

  .bookDinnerStatisticsTalbe tr th {
    background: #e6e6e6;
    height: 40px;
    font-size: 12px;
    color: #333;
  }

  .bookDinnerStatisticsTalbe tr {
    background: #fff;
    text-align: center;
    height: 40px;
  }

  .bookDinnerStatisticsTalbe tr td {
    font-size: 12px;
  }

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

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

  .bookDinnerStatisticsTalbe tr td .pHouseStyle {
    border-bottom: 1px solid #ccc;
    height: 28px;
    line-height: 28px;
  }

  .bookDinnerStatisticsTalbe tr td .pHouseStyle:last-child {
    border-bottom: none;
  }

  .bookDinnerStatisticsTalbe tr td .DivStyle {
    border-bottom: 1px solid #ccc;
    height: 84px;
    line-height: 28px;
    box-sizing: border-box;
  }

  .bookDinnerStatisticsTalbe tr td .DivStyle p {
    border-bottom: 1px solid #ccc;
  }

  .bookDinnerStatisticsTalbe tr td .DivStyle p:last-child {
    border-bottom: none;
  }

  .bookDinnerStatisticsTalbe tr td .DivStyle:last-child {
    border-bottom: none;
  }

  .bookDinnerStatisticsTalbe tr td .tdItemStyle {
    border-bottom: 1px solid #ccc;
  }

  .bookDinnerStatisticsTalbe tr td .tdItemStyle:last-child {
    border-bottom: none;
  }

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

  .bookDinnerStatisticsTalbe .Book_span {
    margin-right: 3px;
  }

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

</style>