Merge remote-tracking branch 'refs/remotes/origin/dev' into dev

pull/60/head
farid saravi 4 years ago
commit ae2db0d829

@ -30,129 +30,135 @@
</div> </div>
</template> </template>
<script> <script>
import VuePersianDatetimePicker from 'vue-persian-datetime-picker' import VuePersianDatetimePicker from 'vue-persian-datetime-picker'
import moment from 'jalali-moment'; import {convertToJalali, convertNowToJalali} from '@Global/utils/date/jalali-date'
export default { export default {
components: { components: {
datePicker: VuePersianDatetimePicker datePicker: VuePersianDatetimePicker
},
props: {
color: {default: 'black'},
disabled: {default: false},
defaultDate: {
default: 'now',
type: String,
validator: (val) => ['now', 'empty'].includes(val)
}, },
min: {default: null}, props: {
max: {default: null}, color: {default: 'black'},
displayFormat: {default: null}, disabled: {default: false},
inputFormat: {default: null}, defaultDate: {
format: {default: null}, default: 'now',
type: { type: String,
default: 'datetime', validator: (val) => ['now', 'empty'].includes(val)
type: String,
validator: (val) => ['datetime', 'time', 'date'].includes(val)
},
label: {default: 'در تاریخ '},
value: {default: null},
icon: {default: 'calendar-alt'},
},
data: () => ({
localeConfig: {
fa: {
lang: {label: 'شمسی'}
}, },
en: { min: {default: null},
lang: {label: 'Gregorian'} max: {default: null},
} displayFormat: {default: null},
inputFormat: {default: null},
format: {default: null},
type: {
default: 'datetime',
type: String,
validator: (val) => ['datetime', 'time', 'date'].includes(val)
},
label: {default: 'در تاریخ '},
value: {default: null},
icon: {default: 'calendar-alt'},
}, },
show: false, data: () => ({
uniqueId: Math.floor(Math.random() * 10000) localeConfig: {
}), fa: {
computed: { lang: {label: 'شمسی'}
dateShow: { },
get() { en: {
if (this.value) { lang: {label: 'Gregorian'}
return moment(new Date(this.value)).format(this.defaultDisplayFormat); }
} else if (!this.disabled) { },
if (this.defaultDate === 'now') { show: false,
this.$emit('input', moment(new Date()).format(this.defaultFormat)); uniqueId: Math.floor(Math.random() * 10000)
return moment(new Date()).format(this.defaultDisplayFormat); }),
} else { computed: {
return ''; dateShow: {
get() {
if (this.value) {
return convertToJalali(this.value, this.defaultDisplayFormat);
} else if (!this.disabled) {
if (this.defaultDate === 'now') {
this.$emit('input', convertNowToJalali(null, this.defaultFormat));
return convertNowToJalali(null, this.defaultDisplayFormat);
} else {
return '';
}
} }
},
set(value) {
} }
}, },
set(value) { defaultDisplayFormat() {
} if (!this.displayFormat) {
}, if (this.type === 'datetime') {
defaultDisplayFormat() { return 'jDD jMMMM jYYYY ساعت HH:mm';
if (!this.displayFormat) { } else if (this.type === 'date') {
if (this.type === 'datetime') { return 'jDD jMMMM jYYYY';
return 'jDD jMMMM jYYYY ساعت HH:mm'; } else if (this.type === 'time') {
} else if (this.type === 'date') { return 'HH:mm';
return 'jDD jMMMM jYYYY'; }
} else if (this.type === 'time') {
return 'HH:mm';
} }
return this.displayFormat
} }
return this.displayFormat ,
}, defaultInputFormat() {
defaultInputFormat() { if (!this.inputFormat) {
if (!this.inputFormat) { if (this.type === 'datetime') {
if (this.type === 'datetime') { return 'YYYY-MM-DD HH:mm';
return 'YYYY-MM-DD HH:mm'; } else if (this.type === 'date') {
} else if (this.type === 'date') { return 'YYYY-MM-DD';
return 'YYYY-MM-DD'; } else if (this.type === 'time') {
} else if (this.type === 'time') { return 'HH:mm';
return 'HH:mm'; }
} }
return this.inputFormat
} }
return this.inputFormat ,
}, defaultFormat() {
defaultFormat() { if (!this.format) {
if (!this.format) { if (this.type === 'datetime') {
if (this.type === 'datetime') { return 'YYYY-MM-DD HH:mm';
return 'YYYY-MM-DD HH:mm'; } else if (this.type === 'date') {
} else if (this.type === 'date') { return 'YYYY-MM-DD';
return 'YYYY-MM-DD'; } else if (this.type === 'time') {
} else if (this.type === 'time') { return 'HH:mm';
return 'HH:mm'; }
} }
return this.format
} }
return this.format ,
}, minimum() {
minimum() { if (this.min === 'now') {
if (this.min === 'now') { return convertNowToJalali(null, this.defaultInputFormat);
return moment(new Date()).format(this.defaultInputFormat); } else {
} else { return this.min;
return this.min; }
} }
}, ,
maximum() { maximum() {
if (this.max === 'now') { if (this.max === 'now') {
return moment(new Date()).format(this.defaultInputFormat); return convertNowToJalali(null, this.defaultInputFormat);
} else { } else {
return this.max; return this.max;
}
} }
}, ,
}, }
methods: { ,
changeDatePicker(event) { methods: {
if (!this.disabled) { changeDatePicker(event) {
this.$emit('input', event.format(this.defaultFormat)) if (!this.disabled) {
this.$emit('input', event.format(this.defaultFormat));
}
} }
} }
}, ,
watch: { watch: {
disabled(value) { disabled(value) {
if (value) { if (value) {
this.$emit('input', null); this.$emit('input', null);
}
} }
} }
} }
}
</script> </script>

@ -1,11 +1,11 @@
import chart from "../chart"; import chart from "../chart";
import {seperator, price} from '@Global/utils/common/format'
export default class extends chart { export default class extends chart {
constructor(options) { constructor(options) {
super(options); super(options);
this.type = options.type ? options.type : 'daily'; this.type = options.type ? options.type : 'daily';
this.formatCount = 'number';
this.options = { this.options = {
fill: { fill: {
colors: ["#e6e6e6"] colors: ["#e6e6e6"]
@ -15,16 +15,35 @@ export default class extends chart {
fontFamily: '"iranyekan-regular-en-num", "Montserrat-Regular"' fontFamily: '"iranyekan-regular-en-num", "Montserrat-Regular"'
}, },
xaxis: { xaxis: {
categories: [] categories: [],
},
yaxis: {
labels: {
formatter: (val) => {
if (this.formatCount === 'number') {
return seperator(val)
} else if(this.formatCount === 'price') {
return price(val)
}
}
},
}, },
dataLabels: { dataLabels: {
style: { style: {
colors: ["#000", "#000", "#000"] colors: ["#000", "#000", "#000"]
} },
enabled: true,
formatter: (val, opt) => {
if (this.formatCount === 'number') {
return seperator(val)
} else if(this.formatCount === 'price') {
return price(val)
}
},
}, },
series: [ series: [
{ {
name: "bar chart", name: this.formatCount === 'number' ? "تعداد" : "قیمت",
data: [] data: []
} }
] ]
@ -41,13 +60,22 @@ export default class extends chart {
setOptions() { setOptions() {
switch (this.type) { switch (this.type) {
case 'weekly': case 'weekly':
this.formatCount = 'number';
return this.setWeekly();
case 'cost-weekly': case 'cost-weekly':
this.formatCount = 'price';
return this.setWeekly(); return this.setWeekly();
case 'monthly': case 'monthly':
this.formatCount = 'number';
return this.setMonthly();
case 'cost-monthly': case 'cost-monthly':
this.formatCount = 'price';
return this.setMonthly(); return this.setMonthly();
case 'daily': case 'daily':
this.formatCount = 'number';
return this.setDaily();
case 'cost-daily': case 'cost-daily':
this.formatCount = 'price';
return this.setDaily(); return this.setDaily();
} }
} }

@ -41,7 +41,7 @@ export default class extends chart {
this.options.fill.label = this.responseChart.map(x => x.category.name); this.options.fill.label = this.responseChart.map(x => x.category.name);
this.options['colors'] = this.responseChart.map( x =>{ this.options['colors'] = this.responseChart.map( x =>{
let colorText = x.category.color ? x.category.color : color[parseInt((Math.random() * 100) % 14)].color; let colorText = x.category.color ? x.category.color : color[parseInt((Math.random() * 100) % 14)].color;
return color.find(x => x.color == colorText).hex; return color.find(x => x.color === colorText).hex;
} ); } );
} }
} }

@ -40,3 +40,4 @@ Array.prototype.matchItems = function (array) {
} }
// Hide method from for-in loops // Hide method from for-in loops
Object.defineProperty(Array.prototype, "matchItems", {enumerable: false}); Object.defineProperty(Array.prototype, "matchItems", {enumerable: false});

@ -0,0 +1,6 @@
export const price = (number, currency = 'تومان') => {
return Intl.NumberFormat().format(number) + ' ' + currency;
}
export const seperator = (number) => {
return new Intl.NumberFormat().format(number);
}
Loading…
Cancel
Save