<template>
  <div v-if="isShow"  class="DirectQuotation clearfix">
    <DirectQuotation ref="QuotationPrice" :postConfig="postData"></DirectQuotation>
    <div class="btnFixedDiv">
      <div class="toTop" @click="backTop">
        <i class="iconfont icon-huidaodingbu"></i>
      </div>
      <div class="DTSaveBtn" :class="{'disClick':!isSubmit}" @click="submitForm(2)">{{$t('fnc.tijiao')}}</div>
      <div class="DTSaveBtn" @click="copyQuotationData">{{$t('objFill.copy')}}</div>
      <div class="DTSaveBtn caogao" :class="{'disClick':!isSubmit}" @click="submitForm(1)">
        <span >{{$t('pub.saveBtn')}}</span>
        <span>{{$t('objFill.caogao')}}</span>
      </div>
    </div>
  </div>
</template>
<script>
import DirectQuotation from "../TravelQuotationCenter/DirectQuotation";

export default {
  data() {
    return {
      postData: "",
      isSubmit: true,
      priceIsDirect: 2, //是否直采报价(1-否-2-是)
      isShow: false //数据请求后再加载组件
    };
  },
  methods: {
    //表单提交
    submitForm(type) {
      this.$refs["QuotationPrice"].submitForm(type);
    },
    changeDirect(value) {
      this.priceIsDirect = value;
      this.postData.PriceIsDirect = value;
      this.isSubmit = true;
      if (this.postData.IsDirect == 1) {
        this.changeTeamLocalOfferValue();
      }
    },
    updateSubmitState(state) {
      this.isSubmit = state;
    },
    changeTeamLocalOfferValue() {
      this.postData.PriceList.forEach(y => {
        let localOfferList = JSON.parse(
          JSON.stringify(y.OfferPrice.FullLocalOfferList)
        );
        y.OfferPrice.LocalOfferList = localOfferList;
      });
    },
    //回到顶部
    backTop() {
      var timer = setInterval(function() {
        var scrollTop = document.getElementsByClassName("flexParent")[0]
          .scrollTop;
        var ispeed = Math.floor(-scrollTop / 6);
        if (scrollTop == 0) {
          clearInterval(timer);
        }
        document.getElementsByClassName("flexParent")[0].scrollTop =
          scrollTop + ispeed;
      }, 30);
    },
    //获取行程信息
    getConfigDayTrip(subConfig) {
      var TrafficList = [];
      var ScenicList = [];
      var HotelList = [];
      var DinnerList = [];
      var FreedomList = [];
      var WarmTipList = [];
      var TitleList = [];
      subConfig.DayList.forEach((item, dayIndex) => {
        var rank = 1;
        if (item.dayArray != null && item.dayArray.length > 0) {
          item.dayArray.forEach(subItem => {
            subItem.childItem.Rank = rank;
            subItem.childItem.dayNum = item.dayNum;
            subItem.Type = subItem.Type.toString();
            switch (subItem.Type) {
              case this.$tripUtils.TypeKey.traffic:
                TrafficList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.scenic:
                ScenicList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.hotel:
                HotelList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.dinner:
                DinnerList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.freedom:
                FreedomList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.warmtip:
                WarmTipList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.title:
                TitleList.push(subItem.childItem);
                break;
            }
            rank++;
          });
        }
      });
      var obj = {
        DinnerList: DinnerList,
        FreedomList: FreedomList,
        HotelList: HotelList,
        ScenicList: ScenicList,
        TrafficList: TrafficList,
        WarmTipList: WarmTipList,
        TitleList: TitleList
      };
      return obj;
    },
    //复制信息
    copyQuotationData() {
      this.$refs.QuotationPrice.copyInfo();
    },
    getPostData() {
      let configId = this.$route.query.configId;
      if (configId > 0) {
        let msg = { ID: configId };
        this.apipost(
          "travel_get_GetMyTravelInfo",
          msg,
          res => {
            if (res.data.resultCode == 1) {
              this.postData = res.data.data;
              let postDaysTrip = this.getConfigDayTrip(this.postData);
              this.postData.DinnerList = postDaysTrip.DinnerList;
              this.postData.FreedomList = postDaysTrip.FreedomList;
              this.postData.HotelList = postDaysTrip.HotelList;
              this.postData.ScenicList = postDaysTrip.ScenicList;
              this.postData.TrafficList = postDaysTrip.TrafficList;
              this.postData.WarmTipList = postDaysTrip.WarmTipList;
              this.postData.TitleList = postDaysTrip.TitleList;
              if (this.postData.OfferList == null) {
                this.postData.OfferList = [];
              }
              if (this.postData.IsDirect == 1) {
                this.priceIsDirect = 2;
                this.postData.PriceIsDirect = 2;
              } else {
                this.priceIsDirect = 1;
                this.postData.PriceIsDirect = 1;
              }
              this.isShow = true;
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      } else {
        let params = { isNoOffer: false };
        this.$router.push({ name: "quoTation", params: params });
      }
    }
  },
  created() {
    this.getPostData();
  },
  components: {
    DirectQuotation: DirectQuotation
  }
};
</script>