123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <template lang="pug">
- .card-grid-wrapper
- .card-grid
- add-card(v-if='canAdd' @onClickAdd='onClickAdd')
- 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)')
- .no-items(v-show='!items || items.length == 0')
- p No hay items
- </template>
- <script>
- import AddCard from '@/components/common/AddCard'
- import Card from '@/components/common/Card'
- export default {
- props: {
- items: {
- type: Array,
- default: []
- },
- canAdd: {
- type: Boolean,
- default: false
- },
- details: {
- type: Array,
- default: []
- },
- loading: {
- type: Boolean,
- default: false
- },
- options: {
- type: Object,
- default: {}
- }
- },
- components: {
- AddCard,
- Card
- },
- watch: {
- options(value) {
- this.computeOptions(value)
- }
- },
- methods: {
- computeDetails(item) {
- if (!this.details) {
- return []
- }
- if (this.details.length === 0) {
- return []
- }
- let results = []
- let computableDetails = this.details.map(item => item.split(/:/))
- for (let detail of computableDetails) {
- for (let field in item) {
- if (field === detail[0]) {
- results.push({
- value: item[field],
- format: (() => {
- if (!detail[1] || detail[1] === 's') {
- return 'string'
- }
-
- if (detail[1] === 'c') {
- return 'currency'
- }
- if (detail[1] === 'd') {
- return 'date'
- }
- return 'string'
- })()
- })
- break
- }
- }
- }
- return results
- },
- computeOptions(value) {
- if (!value) {
- return
- }
- for(let key in value) {
- if(!this.defaultOptions.currency[key]) {
- continue
- }
- this.defaultOptions.currency[key] = value[key]
- }
- },
- onClickAdd() {
- this.$emit('onAdd')
- },
- onClickCard(item) {
- this.selectedId = item.id
- this.$emit('onSelect', item)
- }
- },
- data() {
- return {
- selectedId: -1,
- defaultOptions: {
- currency: {
- symbol: '$',
- position: 'before',
- thousandsSeparator: '.',
- decimalPlaces: 2,
- decimalSeparator: ','
- },
- }
- }
- }
- }
- </script>
- <style lang="sass">
- .card-grid-wrapper
- width: 100%
- height: calc(100% - 50px)
- margin-top: 10px
- overflow-y: auto
- &::-webkit-scrollbar
- width: 2px
- background: #f5f5f5
- &::-webkit-scrollbar-thumb
- background: #7c7bad
- &::-webkit-scrollbar-track
- -webkit-box-shadow: inset 0 0 6px #d3d3d3
- background: #f5f5f5
- .card-grid
- width: 100%
- .no-items
- width: 100%
- height: 100%
- display: flex
- align-items: center
- justify-content: center
- p
- color: #9e9e9e
- font-size: 11pt
- </style>
|