mcalendar.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view>
  3. <view class="mcalendar">
  4. <view class="con">
  5. <text class="icon">&#xe621;</text>
  6. <text class="date" :disabled="true" @click="updateShow()">{{param.data}}</text>
  7. <text class="icon del" @click="clear()" v-if="param.data">&#xe61a;</text>
  8. <text class="label" @click="today()">今天</text>
  9. </view>
  10. </view>
  11. <u-calendar :show="show" mode="range" :minDate="minDate" @confirm="confirm" @close="show = false" :closeOnClickOverlay="true"></u-calendar>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'mcalendar',
  17. props: {
  18. value: {
  19. type: Boolean,
  20. default: false
  21. }
  22. },
  23. data() {
  24. return {
  25. show: false,
  26. minDate: this.util.getDate('lm'),
  27. param: {
  28. data: '选择日期范围'
  29. }
  30. };
  31. },
  32. watch: {
  33. value(newValue) {
  34. this.show = newValue;
  35. }
  36. },
  37. methods: {
  38. confirm(e) {
  39. console.log('==='+e)
  40. console.log('==='+e.length)
  41. this.$emit('input', false);
  42. this.param.dateBegin = e[0];
  43. let end = e.length - 1;
  44. this.param.dateEnd = e[end];
  45. this.param.data = e[0] + ' - ' + e[end];
  46. this.show = false;
  47. this.$emit('confirm', e);
  48. },
  49. updateShow() {
  50. this.show = true;
  51. },
  52. today() {
  53. this.param.dateBegin = this.util.getDate('day');
  54. this.param.dateEnd = this.util.getDate('day');
  55. this.param.data = this.util.getDate('day') + ' - ' + this.util.getDate('day');
  56. this.$forceUpdate();
  57. this.$emit('today', [this.util.getDate('day'), this.util.getDate('day')]);
  58. },
  59. clear() {
  60. this.param.dateBegin = '';
  61. this.param.dateEnd = '';
  62. this.param.data = '选择日期范围';
  63. this.$forceUpdate();
  64. this.$emit('clear');
  65. }
  66. }
  67. };
  68. </script>
  69. <style lang="scss">
  70. .mcalendar {
  71. padding: 10px 10px 0px 10px;
  72. .con {
  73. padding: 10px 15px 10px 15px;
  74. background-color: white;
  75. border-radius: 20px;
  76. color: $font-c;
  77. overflow: hidden;
  78. .icon {
  79. padding-right: 10px;
  80. float: left;
  81. margin-top: 2px;
  82. }
  83. .del {
  84. padding-left: 9px;
  85. }
  86. .date {
  87. float: left;
  88. width: 60%;
  89. }
  90. .label {
  91. float: right;
  92. color: $main-color;
  93. padding-right: 5px;
  94. }
  95. }
  96. }
  97. </style>