timeChoose.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div>
  3. <div style="width:100%">
  4. <el-popover
  5. v-if="!showTime && !showDate"
  6. ref="popover"
  7. placement="bottom"
  8. width="400"
  9. trigger="click">
  10. <div style="display:flex;width:100%" >
  11. <el-input v-model="day" placeholder="选择时间" style="margin-right:10px;width:100%"></el-input>
  12. <el-time-picker
  13. @change="changeTime"
  14. @blur="changeTime"
  15. v-model="time"
  16. value-format="HH:mm:ss"
  17. placeholder="选择时间">
  18. </el-time-picker>
  19. </div>
  20. <div style="display:flex;flex-wrap:wrap;width:100% " >
  21. <p style="min-width:50px;width:calc(100% / 7);text-align:center;cursor:pointer" v-for="(item,index) in list[type]" :key="index" @click="check(item)">{{ item }}</p>
  22. </div>
  23. <el-input slot="reference" v-model="value1" placeholder="选择时间" style="width:100%"></el-input>
  24. </el-popover>
  25. <el-time-picker
  26. v-if="showTime"
  27. @change="changeTime"
  28. v-model="value1"
  29. style="width:100%"
  30. value-format="HH:mm:ss"
  31. placeholder="选择时间">
  32. </el-time-picker>
  33. <el-date-picker
  34. popper-class="picker-date"
  35. format="MM-dd HH:mm:ss"
  36. v-if="showDate"
  37. @change="changeTime"
  38. v-model="value1"
  39. type="datetime"
  40. placeholder="选择日期时间">
  41. </el-date-picker>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import { cron } from "./mixins";
  47. export default {
  48. mixins:[cron],
  49. props:{
  50. type:{
  51. default:'day'
  52. },
  53. cron:{},
  54. value:{
  55. default:''
  56. }
  57. },
  58. data() {
  59. return {
  60. value1:'',
  61. day:'',
  62. time:'',
  63. list:{
  64. week:['周一','周二','周三','周四','周五','周六','周日'],
  65. month:[]
  66. },
  67. showDate:false,
  68. showTime:false,
  69. }
  70. },
  71. watch: {
  72. type(val) {
  73. this.init()
  74. },
  75. },
  76. mounted() {
  77. this.init()
  78. },
  79. methods: {
  80. init() {
  81. this.value1 = ''
  82. this.day = ''
  83. this.time = ''
  84. this.showTime =this.type=='day'? true:false
  85. this.showDate = this.type == 'year' ? true : false
  86. switch (this.type) {
  87. case 'day':
  88. break;
  89. case 'week':
  90. break;
  91. case 'month':
  92. for(let i = 1;i < 32;i++){
  93. this.list.month.push(i+'日')
  94. }
  95. break;
  96. case 'year':
  97. break;
  98. }
  99. if (this.type) {
  100. let cron = this.getCron(this.type)
  101. this.$emit('value', cron)
  102. } else if(this.cron && this.type){
  103. this.cronChangeDate(this.cron)
  104. }
  105. },
  106. check(item){
  107. this.$set(this,'day',item)
  108. if(!this.time){
  109. this.$set(this,'time','18:30:00')
  110. }
  111. this.changeTime()
  112. },
  113. changeTime(){
  114. if(!this.showDate && !this.showTime){
  115. this.$set(this,'value1',this.day+" "+this.time)
  116. }
  117. // console.log(this.value1)
  118. let cron=this.getCron()
  119. this.$emit('value', cron)
  120. }
  121. },
  122. }
  123. </script>
  124. <style lang="scss">
  125. .el-time-panel{
  126. margin-top:20px;
  127. z-index: 9999 !important;
  128. }
  129. .el-picker-panel{
  130. z-index: 9999 !important;
  131. }
  132. .picker-date {
  133. .el-date-picker__header {
  134. span:nth-child(3) {
  135. display: none;
  136. }
  137. button:nth-child(1) {
  138. display: none;
  139. }
  140. button:nth-child(5) {
  141. display: none;
  142. }
  143. }
  144. }
  145. </style>