<template>
  <div class="container pcContainer orderDetailInfo">
    <div class="order_head">
      <headBar class="mine orderDetail"></headBar>
    </div>
    <div class="w12">
      <p class="w_t"><router-link to="/orderList/all">我的订单 > </router-link> 发票信息</p>
      <orderInfo :orderDetailInfo="orderDetailInfo"></orderInfo>
      <div class="invoiceInfoBox">
        <invoiceInfo pageIndex="orderDetailPage" :invoiceD="invoiceD" :invoiceDetail="form.invoiceDetail" :orderNumber="orderNumber" @getInvoiceInfo="getInvoiceInfo($event)">
        </invoiceInfo>
      </div>
    </div>
    <footB></footB>
  </div>
</template>
<script>
  import invoiceInfo from './invoiceInfo.vue'
  import orderInfo from '../order/orderInfo.vue'
  export default {
    name: '',
    props:{
      pageIndex:''
    },
    data () {
      return {
        refundText:refundText,
        orderNumber:this.$route.params.orderNumber,
        orderDetailInfo:{},
        invoiceT:[{label:'企业',val:1},{label:'非企业性单位',val:2},{label:'个人',val:0}],
        invoiceD:invoiceD,
        provinceList:[],
        cityList:[],
        areaList:[],
        province:"",//收货地址 省份
        city:"",//收货地址 城市
        area:"",//收货地址 区域纸
        errorObj:{
          titleError:'',
          taxpayerNumberError:'',
          provinceError:'',
          cityError:'',
          areaError:'',
          addressError:'',
          recipientNameError:'',
          recipientPhoneError:'',
        },
        form:{
          type:1, //类型 1：纸质发票 2：电子发票
          title:'', //发票抬头
          taxpayerNumber:'', //纳税人识别号
          invoiceDetail:invoiceDetail,//发票明细
          invoiceRemark:'',//发票备注
          invoiceType:1, //发票类型 0：个人 1：企业 2：非企业
          orderNumber:this.$route.params.orderNumber, //订单编号
          province:'',//收货地址 省份
          city:'',//收货地址 城市
          area:'',//收货地址 区域纸
          address:'',//收货地址 详细地址
          recipientName:'', //收货人
          recipientPhone:'',//收货人电话
        }
      }
    },
    methods: {
      getInvoiceInfo(d){
          this.$router.push("/orderList/all");
      },

      /*查询订单信息*/
      getOrderDetailInfo(){
        packageOrderDetail(this.orderNumber).then(data=>{
          this.loading=false;
          if(data.returnCode==200){
            this.orderDetailInfo=data.data;
            //机票
            if(this.orderDetailInfo.flightOrders.length>0){
              this.orderDetailInfo.flightOrders.forEach(flight=>{
                flight.flightOrderDetail.forEach(item=>{
                  let index=flight.flightOrderDetail.indexOf(item);
                  item.flightFlightType=initFlightInfo(item).type;
                  if(index+1<flight.flightOrderDetail.length){
                    item.flightStopTime=getTermTime(flight.flightOrderDetail[index+1].depTime,item.arrTime);
                  }
                  item.specialRuleText=item.specialRuleText || '请致电'+telPhone ;
                  item.stopAddress=item.stopAddress ? JSON.parse(item.stopAddress) : '';
                });
              });
              this.orderDetailInfo.isPast=(new Date().getTime()-new Date(this.orderDetailInfo.flightOrders[0].flightOrderDetail[0].depTime).getTime())>0 ? -1 : 0  ; //-1过期，0没过期
            }
            //酒店
            this.orderDetailInfo.hotelOrders.forEach(item=>{
              item.roomNum=1;
            });
            //发票
            this.orderDetailInfo.invoicesInfo={};
            this.orderDetailInfo.orderInvoiceStatus=-1;
            if(this.orderDetailInfo.invoices && this.orderDetailInfo.invoices.length>0){
              this.orderDetailInfo.orderInvoiceStatus=0;
              this.orderDetailInfo.invoicesInfo=this.orderDetailInfo.invoices[0];
              this.orderDetailInfo.invoicesInfo.detailAddress=this.orderDetailInfo.invoices[0].province+this.orderDetailInfo.invoices[0].city+this.orderDetailInfo.invoices[0].area+this.orderDetailInfo.invoices[0].address;
              this.orderDetailInfo.invoicesInfo.invoiceTypeText=this.getInvoiceTypeText(this.orderDetailInfo.invoices[0].invoiceType);
            }
          }else {
            this.msgAlert(data.returnMsg);
          }
        })

        /*getOrderDetail(this.orderNumber).then(data=>{
          if(data.returnCode==200){
            this.orderDetailInfo=data.data;
            this.orderDetailInfo.expenseDetail=this.orderDetailInfo.expenseDetail ? JSON.parse(this.orderDetailInfo.expenseDetail) : '';
          }
        })*/
      },

      getInvoiceTypeText(type){
        let invoiceText='';
        this.invoiceT.forEach(item=>{
          if(item.val==type){
            invoiceText=item.label;
          }
        });
        return invoiceText;
      },
    },
    components:{
      invoiceInfo,orderInfo
    },
    mounted(){
      this.getOrderDetailInfo();
    },
    filters:{
    }
  }
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus" scoped>
  @import "../order/orderList.styl"
  @import "invoice.styl"
  .invoiceInfoBox{
    margin 50px auto
  }
</style>
