1
0

persianDatepicker.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {{define "component/persianDatepickerTemplate"}}
  2. <template>
  3. <div>
  4. <a-input :value="value" type="text" v-model="date" data-jdp class="persian-datepicker"
  5. @input="$emit('input', convertToGregorian($event.target.value)); jalaliDatepicker.hide();"
  6. :placeholder="placeholder">
  7. <template #addonAfter>
  8. <a-icon type="calendar" style="font-size: 14px; opacity: 0.5;"/>
  9. </template>
  10. </a-input>
  11. </div>
  12. </template>
  13. {{end}}
  14. {{define "component/persianDatepicker"}}
  15. <link rel="stylesheet" href="{{ .base_path }}assets/persian-datepicker/persian-datepicker.min.css?{{ .cur_ver }}"/>
  16. <script src="{{ .base_path }}assets/moment/moment-jalali.min.js?{{ .cur_ver }}"></script>
  17. <script src="{{ .base_path }}assets/persian-datepicker/persian-datepicker.min.js?{{ .cur_ver }}"></script>
  18. <script>
  19. const persianDatepicker = {};
  20. Vue.component('persian-datepicker', {
  21. props: ['placeholder', 'format', 'value'],
  22. template: `{{template "component/persianDatepickerTemplate"}}`,
  23. data() {
  24. return {
  25. date: '',
  26. persianDatepicker,
  27. };
  28. },
  29. watch: {
  30. value: function (date) {
  31. this.date = this.convertToJalalian(date)
  32. }
  33. },
  34. mounted() {
  35. this.date = this.convertToJalalian(this.value)
  36. this.listenToDatepicker()
  37. },
  38. methods: {
  39. convertToGregorian(date) {
  40. return date ? moment(moment(date, 'jYYYY/jMM/jDD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss')) : null
  41. },
  42. convertToJalalian(date) {
  43. return date && moment.isMoment(date) ? date.format('jYYYY/jMM/jDD HH:mm:ss') : null
  44. },
  45. listenToDatepicker() {
  46. jalaliDatepicker.startWatch({
  47. time: true,
  48. zIndex: '9999',
  49. hideAfterChange: true,
  50. useDropDownYears: false,
  51. changeMonthRotateYear: true,
  52. });
  53. },
  54. }
  55. });
  56. </script>
  57. {{end}}