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.
 
 
 
 
 
 

92 lines
2.0 KiB

  1. <template>
  2. <l-label :class="className" :style="style" :arrow="!disabled" :required="required" :title="title">
  3. <!-- #ifndef MP-DINGTALK -->
  4. <picker @change="change" :fields="fields" :disabled="disabled" :value="value" :start="start" :end="end" mode="date">
  5. <view class="picker">{{ value || displayPlaceholder }}</view>
  6. </picker>
  7. <!-- #endif -->
  8. <!-- #ifdef MP-DINGTALK -->
  9. <text @click="click">{{ value || displayPlaceholder }}</text>
  10. <!-- #endif -->
  11. </l-label>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'l-date-picker',
  16. props: {
  17. title: {},
  18. start: { default: '1900-01-01' },
  19. end: { default: '2100-01-01' },
  20. fields: { default: 'day' },
  21. disabled: {},
  22. placeholder: {},
  23. required: {},
  24. value: {}
  25. },
  26. methods: {
  27. click(e) {
  28. if (this.disabled) {
  29. return
  30. }
  31. this.$emit('click')
  32. // #ifdef MP-DINGTALK
  33. const getCurrent = () => {
  34. const now = new Date()
  35. const year = now.getFullYear().toString()
  36. const month = (now.getMonth() + 1).toString().padStart(2, '0')
  37. const date = now
  38. .getDate()
  39. .toString()
  40. .padStart(2, '0')
  41. return `${year}-${month}-${date}`
  42. }
  43. const currentDate = this.value ? this.value : getCurrent()
  44. this.$emit('open')
  45. dd.datePicker({
  46. currentDate,
  47. format: 'yyyy-MM-dd',
  48. success: ({ date }) => {
  49. if (date) {
  50. this.$emit('input', date)
  51. this.$emit('change', date)
  52. }
  53. },
  54. complete: () => {
  55. this.$emit('close')
  56. }
  57. })
  58. // #endif
  59. },
  60. change(e) {
  61. this.$emit('input', e.detail.value)
  62. this.$emit('change', e.detail.value)
  63. }
  64. },
  65. computed: {
  66. displayPlaceholder() {
  67. if (this.disabled) {
  68. return ''
  69. }
  70. if (this.placeholder) {
  71. return this.placeholder
  72. }
  73. return this.title ? `请选择${this.title}` : '请选择日期…'
  74. }
  75. }
  76. }
  77. </script>