| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <template>
- <view class="box p-tb30" :class="{'no-box':noBox}">
- <uni-datetime-picker class="flex" :type="type" :value="inputValue" :start="startDate" :end="endDate"
- :border="border" :placeholder="placeholder" @change="change">
- <view class="input-box">
- <view class="input-box-left" :style="{'letter-spacing':labelWidth}">
- {{ label }}
- </view>
- <view class="row-c">
- <text class="size-28 p-r10"
- :style="{color:!inputValue?'#999':''}">{{!inputValue?'请选择':inputValue}}</text>
- <uni-icons type="forward" size="18" color="#D8D8D8"></uni-icons>
- </view>
- </view>
- </uni-datetime-picker>
- </view>
- </template>
- <script>
- export default {
- name: 'en-date',
- props: {
- type: {
- //date/daterange/datetime/datetimerange
- type: String,
- default: 'date'
- },
- label: {
- type: String,
- default: '标题'
- },
- placeholder: {
- type: String,
- default: '选择日期'
- },
- startDate: {
- type: String,
- default: '1950-01-01'
- },
- endDate: {
- type: String,
- default: '2099-12-13'
- },
- disabled: {
- default: false
- },
- border: {
- default: false
- },
- value: {
- default: ''
- },
- noBox: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- inputValue: '',
- labelWidth: 0
- }
- },
- components: {},
- mounted() {
- this.inputValue = this.value
- this.setLabelWidth()
- },
- watch: {
- 'value': function() {
- if (this.inputValue !== this.value) {
- console.log('this.value:' + this.value)
- this.inputValue = this.value
- }
- },
- 'inputValue': function() {
- this.$emit('input', this.inputValue)
- }
- },
- methods: {
- setLabelWidth() {
- let differenceNum = 4 - this.label.length;
- if (differenceNum === 2) {
- this.labelWidth = '2em'
- } else if (differenceNum === 1) {
- this.labelWidth = '0.5em'
- }
- },
- change(e) {
- this.inputValue = e
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import url("../../static/css/en-common.css");
- .box {
- .input-box {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .input-box-left {
- font-size: 28rpx;
- color: #333333;
- }
- }
- }
- </style>
|