en-date.vue 2.1 KB

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