<template>
    <div class="container scrollHidden">
      <section class="proFixedTop">
        <div class="fixedTop border-bottom">
          <i class="iconfont icon-zuojiantou icon_back" @click="back(-1)"></i>
          <p class="pro-bar bgColor">发票</p>
          <span class="text-finish" @click="finishInvoice">完成</span>
        </div>
      </section>
      <invoiceInfo ref="invoiceInfo" :pageIndex="pageIndex" :invoiceD="invoiceD" :invoiceDetail="invoiceDetail">
      </invoiceInfo>
    </div>
</template>
<script>
  import invoiceInfo from './invoiceInfo.vue'
    export default {
      name: '',
      data () {
          return {
            isInvoive:false,
            params:{},
            pageIndex:'',
            invoiceD:invoiceD,
            invoiceDetail:invoiceDetail,
          }
        },
      methods: {
        /*返回*/
        back(id){
          if(id==-1){  //返回
            this.$router.go(-1);
          }else if(id==-2){ // 不开发票
            this.$router.push(this.params.prevPage);
          }else{
            if(!this.pageIndex){
              this.$router.push(this.params.prevPage+"?invoicedId="+id);
            }else {
                location.href=this.params.prevPage;
            }
          }
        },
        /*保存发票信息*/
        finishInvoice(){
          this.$refs.invoiceInfo.saveInvoice();
        },
        initIvoiceInfo(){
          getInvoiceById(this.params.invoiceId).then(data=>{
            if(data.returnCode==200 && data.data){
              this.$refs.invoiceInfo.isInvoive=true;
              this.$refs.invoiceInfo.form=data.data;
              if(data.data.type==1){
                this.$refs.invoiceInfo.isAddressInfo=true;
              }
            }else {

            }
          });
        }
      },
      mounted(){
        if(Object.keys(urlParse()).length>0){
          this.params=urlParse();
          if(this.params.prevPage.indexOf("wx/orderDetail")!=-1){ //订单详情
            this.pageIndex='weOrderDetail';
            this.$refs.invoiceInfo.isInvoive=true;
            this.$refs.invoiceInfo.form.orderNumber=this.params.orderNumber;
          }else {   //出行人
            if(this.params.invoiceId && this.params.invoiceId!="undefined"){
              this.initIvoiceInfo();
            }
          }
        }
      },
      components:{
        invoiceInfo
      },
      beforeRouteEnter(to, from, next) {
        next();
      },
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus" scoped>
@import "invoice.styl"
</style>
