|
@@ -4,7 +4,7 @@
|
|
|
spinner(type='wave')
|
|
|
.card-grid(v-else)
|
|
|
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' :description='getDescription(item)' @onClick='onClickCard(item)')
|
|
|
+ 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)')
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
@@ -22,13 +22,17 @@
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
},
|
|
|
- description: {
|
|
|
- type: String,
|
|
|
- default: ''
|
|
|
+ details: {
|
|
|
+ type: Array,
|
|
|
+ default: []
|
|
|
},
|
|
|
loading: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ type: Object,
|
|
|
+ default: {}
|
|
|
}
|
|
|
},
|
|
|
components: {
|
|
@@ -36,9 +40,65 @@
|
|
|
Card,
|
|
|
Spinner
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ options(value) {
|
|
|
+ this.computeOptions(value)
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
- getDescription(item) {
|
|
|
- return (!!this.description && item[this.description]) || ''
|
|
|
+ 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')
|
|
@@ -50,7 +110,16 @@
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- selectedId: -1
|
|
|
+ selectedId: -1,
|
|
|
+ defaultOptions: {
|
|
|
+ currency: {
|
|
|
+ symbol: '$',
|
|
|
+ position: 'before',
|
|
|
+ thousandsSeparator: '.',
|
|
|
+ decimalPlaces: 2,
|
|
|
+ decimalSeparator: ','
|
|
|
+ },
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|