简体   繁体   English

如何在发票模板中显示我的发票数据

[英]How To Display My Invoice Data In Invoice Template

I'm using Laravel 5.7 & VueJs 2.5.* ...我正在使用Laravel 5.7VueJs 2.5.* ...

I have invoices table, i need to display specific invoice in a new component, so user can see whatever invoice he wants or print that invoice.我有发票表,我需要在新组件中显示特定发票,以便用户可以查看他想要的任何发票或打印该发票。

I don't know how to do that, i'm just playing around, if you could help me out, i'll be very grateful to you.我不知道该怎么做,我只是在玩,如果你能帮助我,我会非常感谢你。

<router-link> to the component <router-link>到组件

<router-link to="/ct-invoice-view" @click="openInvoice(ctInvoice)">
  <i class="fas fa-eye fa-lg text-blue"></i>
</router-link>

Displaying Customer information here like this:在此处显示Customer信息,如下所示:

<div class="col-sm-4 invoice-col">
  <address v-for="ctInvoice in ctInvoices" :key="ctInvoice.id">
     <strong>Customer Info</strong><br>
     Name: <span>{{ ctInvoice.customer.customer_name }}</span>

Invoice view component data() & method{}发票视图组件data() & method{}

data() {
    return {
      ctInvoices: {},
      customers: null
    };
  },
  methods: {
    openInvoice(ctInvoice) {
      axios
        .get("api/ct-invoice/show/" + this.viewInvoice)
        .then(({
          data
        }) => (this.ctInvoices = data.data));
    },

Image for Better Understanding更好理解的图像在此处输入图像描述

You need to look at Dynamic Route matching: https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes您需要查看动态路由匹配: https ://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes

Then you need to use axios.get in invoice views beforeMount function where this.$route.params.id will hold the invoice ID you want to load if the link is applied like so:然后,您需要在发票视图beforeMount函数中使用axios.get ,其中this.$route.params.id将保存您要加载的发票 ID,如果链接应用如下:

<router-link :to="`/ct-invoice-view/${ctInvoice.id}`">
  <i class="fas fa-eye fa-lg text-blue"></i>
</router-link>

Alternatively...或者...

I suggest not navigating away from the list, it can be irritating for users having filtered the list then returning to it to look at more invoices and having to filter again unless the filter options and current results are sticky我建议不要离开列表,这对于过滤列表然后返回它以查看更多发票并不得不再次过滤的用户来说可能会很烦人,除非过滤选项和当前结果很粘

There are a number of ways of doing this and they are lengthy to example, Typically I would make proper use of a modal and the invoice view load the data on display but to get you started a basic in page solution to experiment with, then try adapting in a reusable modal component later:有很多方法可以做到这一点,它们的例子很长,通常我会正确使用模式和发票视图加载显示的数据,但要让你开始一个基本的页面解决方案来试验,然后尝试稍后适应可重用的模态组件:

<button @click="showInvoice = ctInvoice.id">
  <i class="fas fa-eye fa-lg text-blue"></i>
</button>

data() {
    return {
        loading: false,
        invoice: {},
        customers: null
    };
},
computed: {
    showInvoice: {
        get: function() {
            return this.invoice.hasOwnProperty('id');
        },
        set: function(value) {

            if(value === false) {
                this.invoice = {};
                return;
            }

            // could check a cache first and push the cached item into this.invoice else load it:

            this.loading = true;

            axios.get("api/ct-invoice/show/" + value).then(response => {
                 // you could push the invoice into a cache
                this.invoice = response.data;

            }).cache(error => {
                // handle error
            }).finally(() => {
                this.loading = false;
            });
        }
    }
}

In view-invoice component have a close button with bind @click="$emit('close')" Check this article for how $emit works: https://v2.vuejs.org/v2/guide/components-custom-events.html在 view-invoice 组件中有一个带有 bind @click="$emit('close')"的关闭按钮查看这篇文章以了解 $emit 的工作原理: https ://v2.vuejs.org/v2/guide/components-custom-事件.html

<div v-if="loading" class="loading-overlay"></div>
<view-invoice v-if="showInvoice" :invoice="invoice" @close="showInvoice = false" />
<table v-else>....</table>

Hide the table when displaying the invoice, experiment with using v-show instead of v-if upon loosing table content state.显示发票时隐藏表格,在失去表格内容状态时尝试使用 v-show 而不是 v-if。

Inside your invoice view, property called invoice will contain the invoice data.在您的发票视图中,名为 invoice 的属性将包含发票数据。 Check this article for how to use props: https://v2.vuejs.org/v2/guide/components-props.html查看这篇文章了解如何使用道具: https ://v2.vuejs.org/v2/guide/components-props.html

Hint: The @close listens to the $emit('close')提示:@close 监听 $emit('close')

Could also make use of when switching between table and invoice view.在表格和发票视图之间切换时也可以使用。 https://v2.vuejs.org/v2/guide/transitions.html https://v2.vuejs.org/v2/guide/transitions.html

@MarcNewton @马克牛顿

I did something like this, it's working for me, can u just review it for me:我做了这样的事情,它对我有用,你能帮我回顾一下吗:

<router-link> to the Invoice View component <router-link>到发票视图组件

<router-link v-bind:to="{name: 'ctInvoiceView', params: {id: ctInvoice.id}}">
  <i class="fas fa-eye fa-lg text-blue"></i>
</router-link>

Getting Data of Specific Invoice ID Like This:像这样获取特定发票 ID 的数据:

created: function() {
  axios
    .get("/api/ct-invoice/" + this.$route.params.id)
    .then(({
      data
    }) => {
      console.log(data);
      this.form = new Form(data);
    })
    .catch(error => {
      console.log(error.response);
    });
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM