|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <template>
- <l-label :class="className" :style="style" :arrow="!disabled" :required="required" :title="title">
- <!-- #ifndef MP-DINGTALK -->
- <picker @change="change" :fields="fields" :disabled="disabled" :value="value" :start="start" :end="end" mode="date">
- <view class="picker">{{ value || displayPlaceholder }}</view>
- </picker>
- <!-- #endif -->
-
- <!-- #ifdef MP-DINGTALK -->
- <text @click="click">{{ value || displayPlaceholder }}</text>
- <!-- #endif -->
- </l-label>
- </template>
-
- <script>
- export default {
- name: 'l-date-picker',
-
- props: {
- title: {},
- start: { default: '1900-01-01' },
- end: { default: '2100-01-01' },
- fields: { default: 'day' },
- disabled: {},
- placeholder: {},
- required: {},
- value: {}
- },
- created() {
- console.log(this.end)
- },
- methods: {
- click(e) {
- if (this.disabled) {
- return
- }
-
- this.$emit('click')
-
- // #ifdef MP-DINGTALK
- const getCurrent = () => {
- const now = new Date()
-
- const year = now.getFullYear().toString()
- const month = (now.getMonth() + 1).toString().padStart(2, '0')
- const date = now
- .getDate()
- .toString()
- .padStart(2, '0')
-
- return `${year}-${month}-${date}`
- }
-
- const currentDate = this.value ? this.value : getCurrent()
- this.$emit('open')
-
- dd.datePicker({
- currentDate,
- format: 'yyyy-MM-dd',
- success: ({ date }) => {
- if (date) {
- this.$emit('input', date)
- this.$emit('change', date)
- }
- },
- complete: () => {
- this.$emit('close')
- }
- })
- // #endif
- },
-
- change(e) {
- this.$emit('input', e.detail.value)
- this.$emit('change', e.detail.value)
- }
- },
-
- computed: {
- displayPlaceholder() {
- if (this.disabled) {
- return ''
- }
-
- if (this.placeholder) {
- return this.placeholder
- }
-
- return this.title ? `请选择${this.title}` : '请选择日期…'
- }
- }
- }
- </script>
|