CardGrid.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template lang="pug">
  2. .card-grid-wrapper
  3. .card-grid
  4. add-card(v-if='canAdd' @onClickAdd='onClickAdd')
  5. card(v-for='item in items' :key='item.id' :title='item.name' :image='item.imageMedium' :isSelected='item.id === selectedId' :details='computeDetails(item)' :options='defaultOptions.currency' @onClick='onClickCard(item)')
  6. .no-items(v-show='!items || items.length == 0')
  7. p No hay items
  8. </template>
  9. <script>
  10. import AddCard from '@/components/common/AddCard'
  11. import Card from '@/components/common/Card'
  12. export default {
  13. props: {
  14. items: {
  15. type: Array,
  16. default: []
  17. },
  18. canAdd: {
  19. type: Boolean,
  20. default: false
  21. },
  22. details: {
  23. type: Array,
  24. default: []
  25. },
  26. loading: {
  27. type: Boolean,
  28. default: false
  29. },
  30. options: {
  31. type: Object,
  32. default: {}
  33. }
  34. },
  35. components: {
  36. AddCard,
  37. Card
  38. },
  39. watch: {
  40. options(value) {
  41. this.computeOptions(value)
  42. }
  43. },
  44. methods: {
  45. computeDetails(item) {
  46. if (!this.details) {
  47. return []
  48. }
  49. if (this.details.length === 0) {
  50. return []
  51. }
  52. let results = []
  53. let computableDetails = this.details.map(item => item.split(/:/))
  54. for (let detail of computableDetails) {
  55. for (let field in item) {
  56. if (field === detail[0]) {
  57. results.push({
  58. value: item[field],
  59. format: (() => {
  60. if (!detail[1] || detail[1] === 's') {
  61. return 'string'
  62. }
  63. if (detail[1] === 'c') {
  64. return 'currency'
  65. }
  66. if (detail[1] === 'd') {
  67. return 'date'
  68. }
  69. return 'string'
  70. })()
  71. })
  72. break
  73. }
  74. }
  75. }
  76. return results
  77. },
  78. computeOptions(value) {
  79. if (!value) {
  80. return
  81. }
  82. for(let key in value) {
  83. if(!this.defaultOptions.currency[key]) {
  84. continue
  85. }
  86. this.defaultOptions.currency[key] = value[key]
  87. }
  88. },
  89. onClickAdd() {
  90. this.$emit('onAdd')
  91. },
  92. onClickCard(item) {
  93. this.selectedId = item.id
  94. this.$emit('onSelect', item)
  95. }
  96. },
  97. data() {
  98. return {
  99. selectedId: -1,
  100. defaultOptions: {
  101. currency: {
  102. symbol: '$',
  103. position: 'before',
  104. thousandsSeparator: '.',
  105. decimalPlaces: 2,
  106. decimalSeparator: ','
  107. },
  108. }
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="sass">
  114. .card-grid-wrapper
  115. width: 100%
  116. height: calc(100% - 50px)
  117. margin-top: 10px
  118. overflow-y: auto
  119. &::-webkit-scrollbar
  120. width: 2px
  121. background: #f5f5f5
  122. &::-webkit-scrollbar-thumb
  123. background: #7c7bad
  124. &::-webkit-scrollbar-track
  125. -webkit-box-shadow: inset 0 0 6px #d3d3d3
  126. background: #f5f5f5
  127. .card-grid
  128. width: 100%
  129. .no-items
  130. width: 100%
  131. height: 100%
  132. display: flex
  133. align-items: center
  134. justify-content: center
  135. p
  136. color: #9e9e9e
  137. font-size: 11pt
  138. </style>