wk-field-datetime.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view>
  3. <view class="wk-field wk-field-datetime">
  4. <view v-if="_label" class="wk-field__label">
  5. <view v-if="field.isNull === 1" class="line" />
  6. {{ _label }}
  7. </view>
  8. <view class="wk-field__body" @click.stop="handleChoose">
  9. <view class="wk-field__body-core">
  10. {{ formatTime }}
  11. </view>
  12. <image :src="$static('images/icon/calendar.png')" class="icon-pic" />
  13. </view>
  14. </view>
  15. <uni-popup ref="popup" type="picker">
  16. <wk-date-picker
  17. v-model="formValue"
  18. :type="field.formType"
  19. @select="handleSelect" />
  20. </uni-popup>
  21. </view>
  22. </template>
  23. <script>
  24. import mixins from './mixins'
  25. import moment from 'moment'
  26. export default {
  27. name: 'WkFieldDatetime',
  28. mixins: [mixins],
  29. data() {
  30. return {
  31. }
  32. },
  33. computed: {
  34. formatTime() {
  35. if (!this.formValue) return ''
  36. if (this.field.formType === 'date') return moment(this.formValue).format('YYYY-MM-DD')
  37. return this.formValue
  38. }
  39. },
  40. methods: {
  41. handleChoose() {
  42. if (this.field.disabled) {
  43. if (this.config && this.config.disabledMsg) {
  44. this.$toast(this.config.disabledMsg)
  45. }
  46. return
  47. }
  48. this.$refs.popup.open()
  49. },
  50. handleSelect(data, next) {
  51. this.formValue = data
  52. this.$emit('input', data)
  53. this.$emit('change', {
  54. index: this.index,
  55. field: this.field,
  56. value: data
  57. })
  58. next()
  59. }
  60. }
  61. }
  62. </script>
  63. <style scoped lang="scss">
  64. @import './wkField.scss';
  65. .icon-pic {
  66. width: 32rpx;
  67. height: 32rpx;
  68. }
  69. </style>