<template>
  <div>
    <div class="query-box" style="border-bottom: none;">
      <ul>
        <li>
          <template v-if="IsOperation !=1">
            <input type="button" class="fr normalBtn mb30" :value="$t('pub.saveBtn')" @click="saveList(1)" :disabled="IsDisabled" />
            <input type="button" class="fr normalBtn mb30" :value="$t('ground.baocuncaogao')" @click="saveList(0)" :disabled="IsDisabled" />
          </template>
          <template v-else>
            <span style="color:red;font-size:14px;">{{$t('objFill.v101.hote.yizhidbnzxg')}}</span>
            <input v-if="EditBtn" type="button" class="fr normalBtn mb30" :value="$t('pub.saveBtn')"
              @click="saveList(1)" />
          </template>
        </li>
      </ul>
    </div>
    <div style="width: 100%;  overflow-y: auto;padding-bottom: 10px; height: 100%; " class="ownScrollbarStyle">
      <table border="0" cellspacing="1" cellpadding="0" class="admissionStatisticsDetailsTalbe" v-loading="loading">
        <tr>
          <th>
            {{$t('salesModule.CompanyNum')}}
          </th>
          <th colspan="15" style="text-align:left; padding-left:8px;">
            <p class="link" @click="goUrlT('productQuery',TCNUM,'产品查询')">{{TCNUM}}</p>
          </th>
        </tr>
        <tr>
          <th width="115">{{$t('ground.youlanshijian')}}</th>
          <th width="200">{{$t('visaT.jdname')}}</th>
          <th width="70">{{$t('objFill.zongrenshu')}}</th>
          <th width="70">{{$t('objFill.youke')}}<br />{{$t('advmanager.v_type')}}</th>
          <th width="70">{{$t('objFill.youke')}}<br />{{$t('admin.admin_personNumber')}}</th>
          <th width="70">{{$t('objFill.shiyong')}}<br />{{$t('admin.admin_personNumber')}}</th>
          <th width="70">{{$t('ground.mianrenshu')}}</th>
          <th width="90">{{$t('fnc.danjia')}}</th>
          <th width="90">{{$t('objFill.jingexj')}}</th>
          <th width="80">{{$t('hotel.hotel_commission')}})</th>
          <th width="100">{{$t('fnc.a_zongjine')}}</th>
          <th width="210">{{$t('ground.fkfsdth')}}</th>
          <th width="200">{{$t('pub.pubRemark')}}</th>
        </tr>
        <template v-for="(item,index) in DataList">
          <template v-for="(subItem,subIndex) in item.ScenicStatisticsList">
            <tr v-for="(childItem,childIndex) in subItem.TicketPriceList">
              <td v-if="childIndex==0" :rowspan="subItem.RowSpan">
                {{item.UseTimeStr}}
              </td>
              <td v-if="childIndex==0" :rowspan="subItem.RowSpan">
                <table class="scenicTable">
                  <tr>
                    <td colspan="2" style="text-align:left;padding-left:8px;">
                      <span class="spanlink" @click="goUrl('ticketManagement',subItem,'门票管理')">
                        {{subItem.ScenicName}}
                      </span>
                    </td>
                  </tr>
                  <tr>
                    <td width="40">
                      {{$t('hotel.table_tel')}}：
                    </td>
                    <td style="text-align:left;">
                      {{subItem.Tel}}
                    </td>
                  </tr>
                  <tr>
                    <td width="40">
                      {{$t('admin.admin_address')}}：
                    </td>
                    <td style="text-align:left;">
                      {{subItem.Address}}
                    </td>
                  </tr>
                </table>
              </td>
              <td v-if="childIndex==0" :rowspan="subItem.RowSpan">
                {{subItem.UseAccount}}
              </td>
              <td>
                 {{childItem.TicketName}}
              </td>
              <td>
                {{childItem.PeopleNum}}
              </td>
              <td>
                <el-input class='w50 tcenter' v-model='childItem.UsePeopleNum' type="number"
                  @input='calculationPrice(subItem)' @keyup.native="checkInteger(childItem,'UsePeopleNum')"></el-input>
              </td>
              <td>
                <el-input class='w50 tcenter' maxlength='2' v-model='childItem.Discount' type="number"
                  @input='calculationPrice(subItem)' @keyup.native="checkInteger(childItem,'Discount')"></el-input>
              </td>
              <td>
                <template v-if="EditBtn">
                  <el-input class='w135' v-model='childItem.PeoplePrice'
                    @keyup.native="checkPrice(childItem,'PeoplePrice')" type="text"></el-input>
                </template>
                <template v-else>
                  <span class="spanlink" v-if='childItem.PeoplePrice==0'
                    @click="goUrl('ticketManagement',subItem,'门票管理')">{{$t('leader.leader_Set')}}</span>
                  <span v-else>
                    {{childItem.PeoplePrice}}
                  </span>
                </template>
              </td>
              <td>
                {{(childItem.UsePeopleNum-childItem.Discount)*childItem.PeoplePrice}}
              </td>
              <td>
                <template v-if="EditBtn">
                  <el-input class='w135' v-model='childItem.DiscountPrice'
                    @keyup.native="checkPrice(childItem,'DiscountPrice')" type="text"></el-input>
                </template>
                <template v-else>
                  <span class="spanlink" v-if='childItem.DiscountPrice==0'
                    @click="goUrl('scenicSpotInfoManage',subItem,'景区列表')">{{$t('leader.leader_Set')}}</span>
                  <span v-if='childItem.DiscountPrice!=0'>{{childItem.DiscountPrice}}%</span>
                </template>
              </td>
              <td v-if="childIndex==0" :rowspan="subItem.RowSpan">
                {{subItem.TotalPrice}}
              </td>
              <td v-if="childIndex==0" :rowspan="subItem.RowSpan">
                <table class="scenicTable">
                  <tr>
                    <td width="60" style="text-align:right;">
                      {{$t('hotel.hotel_payType')}}：
                    </td>
                    <td style="text-align:left;">
                      <el-select class='w135 sel' v-model='subItem.PayStyle' :placeholder="$t('pub.pleaseSel')">
                        <el-option :label="$t('objFill.qingxuanzhe')" value='0'></el-option>
                        <el-option :label="$t('objFill.xianfu')" value='1'></el-option>
                        <el-option :label="$t('objFill.qiandan')" value='2'></el-option>
                        <el-option :label="$t('objFill.shiweidikou')" value='5'></el-option>
                        <el-option :label="$t('objFill.yufu')" value='4'></el-option>
                      </el-select>

                    </td>
                  </tr>
                  <tr>
                    <td width="60" style="text-align:right;">
                      {{$t('objFill.v101.hote.dingtuanh')}}：
                    </td>
                    <td style="text-align:left;">
                      <el-input class='w135' v-model='subItem.CombinationNum' type="text"></el-input>
                    </td>
                  </tr>
                </table>
              </td>
              <td v-if="childIndex==0" :rowspan="subItem.RowSpan">
                <el-input type='textarea' rows="4" class='w170' v-model='subItem.Remarks'></el-input>
              </td>
            </tr>
          </template>
        </template>
      </table>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        EditBtn:false,//房餐景点修改权限
        defaultSelectValue: 0,
        DataList: [],
        roomList: [],
        TCNUM: '',
        flightTotal: 0,
        GuestNum: 0,
        loading: false,
        IsOperation: '',
        //是否禁用按钮
        IsDisabled: false,
      }
    },
    methods: {
      personStrToWord(str) {
        if (str == 1)
          return this.$t('objFill.darens')[0]
        if (str == 2)
          return this.$t('objFill.darens')[1]
        if (str == 3)
          return this.$t('objFill.xiaoren')
      },
      goUrl(path, obj, name) {
        this.$router.push({
          path: path,
          query: {
            id: obj.ID,
            blank: "y",
            tab: name
          }
        });
      },
      calculationPrice(obj) {
        let totalPrice = 0;
        obj.TicketPriceList.forEach(item => {
          totalPrice += item.PeoplePrice * (item.UsePeopleNum - item.Discount) * (1 - item.DiscountPrice / 100);
        })
        obj.TotalPrice = totalPrice.toFixed(2);
      },
      getList() {
        this.loading = true;
        this.apipost('dmcstatistics_get_GetScenicStaticsDetail_SWT', {
          TCIDs: this.$route.query.id
        }, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.DataList = res.data.data.ScenicList;
            this.IsOperation = res.data.data.IsOperation;
            this.DataList.forEach(item => {
              item.ScenicStatisticsList.forEach(x => {
                x.PayStyle = x.PayStyle.toString();
                this.calculationPrice(x);
                if (x.CombinationNum == '' || x.CombinationNum == null) {
                  x.CombinationNum = this.$route.query.NewCombinationNum;
                }
              })
            });
          } else {
            this.$message.error(res.data.message);
          }
        }, err => {})
      },
      saveList(type) {
        this.IsDisabled = true;
        if (type == 0) {
          this.DataList.forEach(item => {
            item.ScenicStatisticsList.forEach(insideItem => {
              insideItem.OrderState = 0;
              insideItem.TicketPriceList.forEach(subItem => {
                if (!subItem.Discount) {
                  subItem.Discount = 0;
                }
                if (!subItem.UsePeopleNum) {
                  subItem.UsePeopleNum = 0;
                }
              });
            })
          })
        }
        if (type == 1) {
          this.DataList.forEach(item => {
            item.ScenicStatisticsList.forEach(insideItem => {
              insideItem.OrderState = 1;
              insideItem.TicketPriceList.forEach(subItem => {
                if (!subItem.Discount) {
                  subItem.Discount = 0;
                }
                if (!subItem.UsePeopleNum) {
                  subItem.UsePeopleNum = 0;
                }
              });
            })
          })
        }
        this.apipost('dmcstatistics_get_SetTicketOrder', this.DataList, res => {
          if (res.data.resultCode == 1) {
            this.$message.success(res.data.message);
            this.getList();
            this.IsDisabled = false;
          } else {
            this.IsDisabled = false;
            this.$message.error(res.data.message);
          }
        }, err => {})

      },
       CheckAuth() {
        var actionCode = this.$AuthCode.EditRoomDinnerTIcket;
        this.CheckUserAuth(actionCode, res => {
          if (res.data.resultCode == 1 && res.data.data == 1) {
            this.EditBtn = true;
          }
        });
      },
    },
    mounted() {
      this.CheckAuth();
      this.TCNUM = this.$route.query.TCNUM;
      this.flightTotal = this.$route.query.flightTotal;
      this.GuestNum = this.$route.query.GuestNum;
      this.getList();
    },
  }

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

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


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

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

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

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

  .admissionStatisticsDetailsTalbe .scenicTable {
    border: none;
  }

  .admissionStatisticsDetailsTalbe .scenicTable tr td {
    border: none;
  }

</style>
