Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

83 wiersze
1.6 KiB

  1. <template>
  2. <div id="pdf-doc" ref="doc" v-if="estimate">
  3. <header class="heading">
  4. <img :src="letterhead" />
  5. <div>
  6. <div class="user-info">
  7. <h4>{{user.firstName + " " + user.lastName}}</h4>
  8. <span>{{user.email}}</span>
  9. <span>{{user.phone}}</span>
  10. <small>{{user.phone}}</small>
  11. </div>
  12. <img :src="avatar"/>
  13. </div>
  14. </header>
  15. <button @click="makePDF">Generate</button>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { ref, computed, onMounted } from "vue"
  20. import html2pdf from "html2pdf.js";
  21. const doc = ref(null)
  22. const props = defineProps(['token', 'estimate', 'user'])
  23. const estimate = ref(null)
  24. const estimates = ref(null)
  25. const letterhead = computed(() => {
  26. if (!props.user.letterhead) return null
  27. return URL.createObjectURL(props.user.letterhead)
  28. })
  29. const avatar = computed(() => {
  30. if (!props.user.letterhead) return null
  31. console.log(props.user)
  32. return URL.createObjectURL(props.user.avatar)
  33. })
  34. function makePDF() {
  35. html2pdf(doc.value)
  36. }
  37. function getEstimates() {
  38. return fetch(`/api/estimates`,
  39. {method: 'GET',
  40. headers: {
  41. "Accept": "application/json",
  42. "Authorization": `Bearer ${props.token}`,
  43. },
  44. }).then(response => {
  45. if (response.ok) { return response.json() } else {
  46. response.text().then(t => console.log(t))
  47. }
  48. }).then (result => {
  49. if (!result || !result.length) return // Exit if token is invalid or no fees are saved
  50. estimates.value = result
  51. // console.log(result)
  52. })
  53. }
  54. onMounted(() => {
  55. getEstimates().then(() => estimate.value = estimates.value[0])
  56. })
  57. </script>
  58. <style scoped>
  59. header.heading {
  60. display: flex;
  61. }
  62. .user-info {
  63. display: flex;
  64. flex-flow: column;
  65. }
  66. </style>