en-date.vue 2.1 KB

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