jp-datetime-picker.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view style="width: 100%;"
  3. @tap="show=true"
  4. :disabled="disabled"
  5. >
  6. <u-datetime-picker
  7. :show="show"
  8. v-model="value1"
  9. :mode="mode"
  10. @cancel="show=false"
  11. @confirm="TimeChange"
  12. ></u-datetime-picker>
  13. <u--input
  14. v-model="label"
  15. suffixIcon="calendar"
  16. suffixIconStyle="color: #17a2f8"
  17. disabled
  18. disabledColor="#ffffff"
  19. :placeholder="placeholder"
  20. border="none"
  21. ></u--input>
  22. </view>
  23. </template>
  24. <script>
  25. import moment from 'moment'
  26. export default {
  27. data () {
  28. return {
  29. show: false,
  30. value1: Number(new Date()),
  31. label: ''
  32. }
  33. },
  34. props: {
  35. value: {
  36. type: String,
  37. default: null
  38. },
  39. mode: String,
  40. placeholder: String,
  41. disabled: {
  42. type: Boolean,
  43. default: false
  44. }
  45. },
  46. watch:{
  47. value:{
  48. handler (val) {
  49. if(val === 0) {
  50. this.label = ''
  51. return
  52. }
  53. const timeFormat = uni.$u.timeFormat
  54. if(this.mode === 'date') {
  55. this.label = val
  56. this.value1 = Number(new Date());
  57. }else if(this.mode === 'time'){
  58. this.label = val
  59. this.value1 = val;
  60. }else if(this.mode === 'datetime'){
  61. this.label = val
  62. this.value1 = Number(new Date())
  63. }
  64. },
  65. immediate: true,
  66. deep: false
  67. }
  68. },
  69. methods:{
  70. TimeChange(e) {
  71. const timeFormat = uni.$u.timeFormat
  72. if(this.mode === 'date') {
  73. this.label = timeFormat(e.value, 'yyyy-mm-dd')
  74. }else if(this.mode === 'time'){
  75. this.label = e.value
  76. }else if(this.mode === 'datetime'){
  77. this.label = timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss')
  78. }
  79. this.$emit('input', this.label)
  80. this.show = false
  81. }
  82. }
  83. }
  84. </script>