TimeSelector.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. @onChange="onChange"
  18. />
  19. </selector-card>
  20. </template>
  21. <script>
  22. import SelectorCard from '@/components/selector/SelectorCard.vue'
  23. import TimeSelectorContent from '@/components/selector/TimeSelectorContent.vue'
  24. export default {
  25. name: 'time-selector',
  26. components: {
  27. SelectorCard,
  28. TimeSelectorContent
  29. },
  30. props: {
  31. selectorType: {
  32. type: String,
  33. default: 'line'
  34. },
  35. selectorTime: {
  36. type: String,
  37. default: 'default'
  38. },
  39. defaultSelectedKey: String,
  40. showExact: {
  41. type: Boolean,
  42. default: true
  43. },
  44. value: {
  45. type: [Object, String],
  46. default: () => {
  47. return {}
  48. }
  49. }
  50. },
  51. data() {
  52. return {}
  53. },
  54. created() {},
  55. model: {
  56. prop: 'value',
  57. event: 'change'
  58. },
  59. watch: {
  60. value (val) {
  61. if (val) {
  62. this.setState(val)
  63. }
  64. }
  65. },
  66. methods: {
  67. setState(data) {
  68. return this.$refs.content.setState(data)
  69. },
  70. getState() {
  71. return this.$refs.content.getState()
  72. },
  73. onCancel() {
  74. this.$emit('onCancel')
  75. },
  76. onConfirm() {
  77. const state = this.getState()
  78. this.$emit('onConfirm', state)
  79. },
  80. onChange(state) {
  81. this.$emit('onChange', state)
  82. this.$emit('change', state)
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped></style>