You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
1.5 KiB

  1. <template>
  2. <l-label @click="click" :arrow="!disabled" :required="required" :title="title">
  3. {{ value || displayPlaceholder }}
  4. <l-datetime-panel
  5. v-if="datetimeModal"
  6. @confirm="confirm"
  7. @cancel="cancel"
  8. :val="value"
  9. :startYear="1900"
  10. ref="datetime"
  11. isAll
  12. />
  13. </l-label>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'l-datetime-picker',
  18. props: {
  19. title: {},
  20. disabled: {},
  21. placeholder: {},
  22. required: {},
  23. value: {}
  24. },
  25. data() {
  26. return {
  27. datetimeModal: false
  28. }
  29. },
  30. methods: {
  31. click(e) {
  32. if (this.disabled || this.datetimeModal) {
  33. return
  34. }
  35. this.datetimeModal = true
  36. this.$nextTick(() => {
  37. this.$refs.datetime.setDate(this.value)
  38. this.$refs.datetime.show()
  39. uni.$emit('modal', true)
  40. this.$emit('open')
  41. })
  42. },
  43. confirm({ selectRes }) {
  44. setTimeout(() => {
  45. this.datetimeModal = false
  46. this.$emit('input', selectRes)
  47. this.$emit('change', selectRes)
  48. uni.$emit('modal', false)
  49. this.$emit('close')
  50. }, 300)
  51. },
  52. cancel() {
  53. setTimeout(() => {
  54. this.datetimeModal = false
  55. }, 300)
  56. uni.$emit('modal', false)
  57. this.$emit('close')
  58. }
  59. },
  60. computed: {
  61. displayPlaceholder() {
  62. if (this.disabled) {
  63. return ''
  64. }
  65. if (this.placeholder) {
  66. return this.placeholder
  67. }
  68. return this.title ? `请选择${this.title}` : '请选择…'
  69. }
  70. }
  71. }
  72. </script>