TimeSelector.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <selector-card
  3. class="time-selector"
  4. :cardType="selectorType"
  5. @onConfirm="onConfirm"
  6. @onCancel="onCancel"
  7. >
  8. <div slot="header" :class="{ 's-header': selectorType === 'line' }">
  9. <slot name="header">选择时间</slot>
  10. </div>
  11. <TimeSelectorContent
  12. ref="content"
  13. :selectorTime="selectorTime"
  14. :selectorType="selectorType"
  15. :defaultSelectedKey="defaultSelectedKey"
  16. :showExact="showExact"
  17. :startPlaceholder="startPlaceholder"
  18. :endPlaceholder="endPlaceholder"
  19. @onChange="onChange"
  20. />
  21. </selector-card>
  22. </template>
  23. <script>
  24. import SelectorCard from '@/components/selector/SelectorCard.vue'
  25. import TimeSelectorContent from '@/components/selector/TimeSelectorContent.vue'
  26. export default {
  27. name: 'time-selector',
  28. components: {
  29. SelectorCard,
  30. TimeSelectorContent
  31. },
  32. props: {
  33. selectorType: {
  34. type: String,
  35. default: 'line'
  36. },
  37. selectorTime: {
  38. type: String,
  39. default: 'default'
  40. },
  41. defaultSelectedKey: String,
  42. showExact: {
  43. type: Boolean,
  44. default: true
  45. },
  46. startPlaceholder: {
  47. type: String,
  48. default: ''
  49. },
  50. endPlaceholder: {
  51. type: String,
  52. default: ''
  53. },
  54. value: {
  55. type: [Object, String],
  56. default: () => {
  57. return {}
  58. }
  59. }
  60. },
  61. data() {
  62. return {}
  63. },
  64. created() {},
  65. model: {
  66. prop: 'value',
  67. event: 'change'
  68. },
  69. watch: {
  70. value (val) {
  71. if (val) {
  72. this.setState(val)
  73. }
  74. }
  75. },
  76. methods: {
  77. setState(data) {
  78. return this.$refs.content.setState(data)
  79. },
  80. getState() {
  81. return this.$refs.content.getState()
  82. },
  83. onCancel() {
  84. this.$emit('onCancel')
  85. },
  86. onConfirm() {
  87. const state = this.getState()
  88. this.$emit('onConfirm', state)
  89. },
  90. onChange(state) {
  91. this.$emit('onChange', state)
  92. this.$emit('change', state)
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped></style>