2
0

CloudRecordDatePicker.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <input type="text" placeholder="选择日期">
  3. </template>
  4. <script>
  5. import moment from 'moment'
  6. import 'assets/bootstrap-datepicker-1.7.1/css/bootstrap-datepicker3.css'
  7. import 'assets/bootstrap-datepicker-1.7.1/js/bootstrap-datepicker.js'
  8. import 'assets/bootstrap-datepicker-1.7.1/locales/bootstrap-datepicker.zh-CN.min.js'
  9. export default {
  10. data() {
  11. return {
  12. flags : {},
  13. defaultFlags : "0000000000000000000000000000000"
  14. }
  15. },
  16. props: {
  17. serial: {
  18. default: ""
  19. },
  20. code: {
  21. default: ""
  22. },
  23. day: {
  24. default: () => moment().format("YYYYMMDD")
  25. }
  26. },
  27. mounted() {
  28. $(this.$el).datepicker({
  29. language : "zh-CN",
  30. autoclose : true,
  31. format : "yyyy-mm-dd",
  32. todayHighlight : false,
  33. beforeShowDay: date => {
  34. var period = moment(date).format("YYYYMM");
  35. var flags = this.getFlagsByMonth(period);
  36. var d = moment(date).date();
  37. var flag = flags[d - 1];
  38. if(flag == '0'){
  39. return {classes : "text-gray", tooltip : "没有录像", enabled : false};
  40. } else {
  41. return {classes : "text-primary text-bold", tooltip : "有录像"};
  42. }
  43. }
  44. }).datepicker("setDate", moment(this.day,"YYYYMMDD").toDate()).on("changeDate",e => {
  45. this.$emit("update:day", moment(e.date).format('YYYYMMDD'));
  46. })
  47. this.update();
  48. },
  49. watch: {
  50. day: function(val){
  51. let d = $(this.$el).datepicker("getDate");
  52. if(val != moment(d).format("YYYYMMDD")){
  53. $(this.$el).datepicker("setDate", moment(val,"YYYYMMDD").toDate());
  54. }
  55. },
  56. id: function(val) {
  57. this.update();
  58. }
  59. },
  60. computed: {
  61. id() {
  62. return `${this.serial}_${this.code}`;
  63. }
  64. },
  65. methods: {
  66. update() {
  67. this.getFlagMap();
  68. },
  69. getFlagMap() {
  70. if(!this.serial || !this.code) return;
  71. $.get('/api/v1/cloudrecord/queryflags',{
  72. serial: this.serial,
  73. code: this.code,
  74. }).then(data => {
  75. this.flags = data;
  76. $(this.$el).datepicker('update');
  77. })
  78. },
  79. getFlagsByMonth(period) {
  80. return this.flags[period] || this.defaultFlags;
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="less">
  86. .datepicker {
  87. z-index: 9999 !important;
  88. }
  89. </style>