2019-10-28 19:00:06 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import { Component, Prop, Watch } from 'vue-property-decorator'
|
|
|
|
|
|
|
|
|
|
import { tools } from '../../store/Modules/tools'
|
|
|
|
|
import { toolsext } from '@src/store/Modules/toolsext'
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
name: 'CMyToggleList'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default class CMyToggleList extends Vue {
|
|
|
|
|
public $t
|
|
|
|
|
@Prop({ required: true }) public options: []
|
|
|
|
|
@Prop({ required: true }) public value
|
|
|
|
|
@Prop({ required: true, default: '' }) public label
|
|
|
|
|
@Prop({ required: false, default: '' }) public myclass
|
|
|
|
|
@Prop({ required: true, default: '' }) public optlab
|
|
|
|
|
@Prop({ required: true, default: '' }) public optval
|
2020-03-10 21:42:30 +01:00
|
|
|
@Prop({ required: false, default: false }) public isarray
|
2019-10-28 19:00:06 +01:00
|
|
|
|
|
|
|
|
public myvalue = ''
|
|
|
|
|
public myarrvalues = []
|
|
|
|
|
|
|
|
|
|
get tools() {
|
|
|
|
|
return tools
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public changeval(newval) {
|
|
|
|
|
// Update value
|
2020-03-10 21:42:30 +01:00
|
|
|
let totale = null
|
|
|
|
|
if (this.isarray) {
|
|
|
|
|
totale = this.myarrvalues.filter((rec) => rec.valbool).map((a) => a.value)
|
|
|
|
|
} else {
|
|
|
|
|
totale = this.myarrvalues.filter((rec) => rec.valbool).reduce((sum, rec) => sum + rec.value, 0)
|
|
|
|
|
}
|
|
|
|
|
console.log('totale', totale)
|
2019-10-28 19:00:06 +01:00
|
|
|
this.myvalue = totale
|
|
|
|
|
|
|
|
|
|
// Refresh value
|
|
|
|
|
this.$emit('update:value', this.myvalue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public mounted() {
|
2021-02-11 02:21:36 +01:00
|
|
|
console.log('mounted')
|
2019-10-28 19:00:06 +01:00
|
|
|
this.myarrvalues = []
|
|
|
|
|
|
2020-03-10 21:42:30 +01:00
|
|
|
// console.log('value', this.value)
|
|
|
|
|
// console.log('optval', this.optval)
|
|
|
|
|
// console.log('optlab', this.optlab)
|
2019-10-28 19:00:06 +01:00
|
|
|
|
2020-03-10 21:42:30 +01:00
|
|
|
if (this.isarray) {
|
|
|
|
|
// console.table(this.options)
|
|
|
|
|
this.options.forEach((rec) => {
|
2021-02-11 02:21:36 +01:00
|
|
|
console.log('rec: ', rec, 'optval', this.optval, 'optlab', this.optlab)
|
2020-03-10 21:42:30 +01:00
|
|
|
const mydata = {
|
2021-02-11 02:21:36 +01:00
|
|
|
label: '',
|
2020-03-10 21:42:30 +01:00
|
|
|
value: rec[this.optval],
|
2021-02-11 02:21:36 +01:00
|
|
|
valbool: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const lab = rec[`${this.optlab}`]
|
|
|
|
|
console.log('lab', lab)
|
|
|
|
|
|
|
|
|
|
if (tools.isObject(this.optlab)) {
|
|
|
|
|
const arr = this.options.filter((myrec) => myrec[this.optval] === mydata.value).map(this.optlab)
|
|
|
|
|
if (arr) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
mydata.label = arr[0]
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mydata.label = this.$t(rec[this.optlab])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.value) {
|
|
|
|
|
mydata.valbool = this.value.includes(rec[this.optval])
|
2020-03-10 21:42:30 +01:00
|
|
|
}
|
|
|
|
|
console.log('mydata ', mydata)
|
|
|
|
|
this.myarrvalues.push(mydata)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// console.table(this.options)
|
|
|
|
|
this.options.forEach((rec) => {
|
|
|
|
|
const mydata = {
|
|
|
|
|
label: this.$t(rec[this.optlab]),
|
|
|
|
|
value: rec[this.optval],
|
|
|
|
|
valbool: tools.isBitActive(this.value, rec[this.optval])
|
|
|
|
|
}
|
|
|
|
|
this.myarrvalues.push(mydata)
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-10-28 19:00:06 +01:00
|
|
|
}
|
|
|
|
|
}
|