en-date.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="box">
  3. <view class="input-box">
  4. <view class="input-box-left" :style="{'letter-spacing':labelWidth}">
  5. {{ label }}
  6. </view>
  7. <uni-datetime-picker
  8. :type="type"
  9. :value="inputValue"
  10. :start="startDate"
  11. :end="endDate"
  12. @change="change"
  13. />
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'en-date',
  20. props: {
  21. type: {
  22. //date/daterange/datetime/datetimerange
  23. type: String,
  24. default: 'date'
  25. },
  26. label: {
  27. type: String,
  28. default: '标题'
  29. },
  30. startDate: {
  31. type: String,
  32. default: '2000-01-01'
  33. },
  34. endDate: {
  35. type: String,
  36. default: '2099-12-13'
  37. },
  38. disabled: {
  39. default: false
  40. },
  41. value: {
  42. default: ''
  43. }
  44. },
  45. data() {
  46. return {
  47. inputValue: '',
  48. labelWidth: 0
  49. }
  50. },
  51. components: {},
  52. mounted() {
  53. this.inputValue = this.value
  54. this.setLabelWidth()
  55. },
  56. watch: {
  57. 'value': function () {
  58. if (this.inputValue !== this.value) {
  59. this.inputValue = this.value
  60. }
  61. },
  62. 'inputValue': function () {
  63. this.$emit('input', this.inputValue)
  64. }
  65. },
  66. methods: {
  67. setLabelWidth() {
  68. let differenceNum = 4 - this.label.length;
  69. if (differenceNum === 2) {
  70. this.labelWidth = '2em'
  71. } else if (differenceNum === 1) {
  72. this.labelWidth = '0.5em'
  73. }
  74. },
  75. change(e){
  76. this.inputValue=e
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. @import url("../../../static/css/en-common.css");
  83. .box {
  84. padding: 20rpx 0 20rpx 0;
  85. .input-box {
  86. display: flex;
  87. align-items: center;
  88. .input-box-left {
  89. width: 210 rpx;
  90. font-size: 32 rpx;
  91. color: #333333;
  92. }
  93. }
  94. }
  95. </style>