|
@@ -18,88 +18,91 @@
|
|
@click="clickField('end')"
|
|
@click="clickField('end')"
|
|
:readonly="true"
|
|
:readonly="true"
|
|
/>
|
|
/>
|
|
- <van-popup
|
|
|
|
- v-model="popupShow.start"
|
|
|
|
- round
|
|
|
|
- class="date-time-select-popup"
|
|
|
|
- :position="popup.position"
|
|
|
|
- :safe-area-inset-bottom="true"
|
|
|
|
- get-container="body"
|
|
|
|
- :style="popup.style"
|
|
|
|
- >
|
|
|
|
- <PopupLayout
|
|
|
|
- title="请选择开始时间"
|
|
|
|
- @closeIconClick="popupShow.start = false"
|
|
|
|
|
|
+ <template v-if="!isIOS">
|
|
|
|
+ <van-popup
|
|
|
|
+ v-model="popupShow.start"
|
|
|
|
+ round
|
|
|
|
+ class="date-time-select-popup"
|
|
|
|
+ :position="popup.position"
|
|
|
|
+ :safe-area-inset-bottom="true"
|
|
|
|
+ get-container="body"
|
|
|
|
+ :style="popup.style"
|
|
>
|
|
>
|
|
- <div slot="default">
|
|
|
|
- <van-datetime-picker
|
|
|
|
- class="date-time-picker highlight-active"
|
|
|
|
- ref="startDateTimePicker"
|
|
|
|
- v-model="start.currentDate"
|
|
|
|
- :key="start.timestamp + 'start'"
|
|
|
|
- :show-toolbar="picker.showToolBar"
|
|
|
|
- :swipe-duration="picker.swipeDuration"
|
|
|
|
- :type="picker.type"
|
|
|
|
- :min-date="start.minDate"
|
|
|
|
- :max-date="start.maxDate"
|
|
|
|
- :formatter="formatter"
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- <div slot="footer" class="j-button-group height40">
|
|
|
|
- <button class="j-button-cancel" @click="resetPopup('start')">
|
|
|
|
- 重置
|
|
|
|
- </button>
|
|
|
|
- <button class="j-button-confirm" @click="confirmPicker('start')">
|
|
|
|
- 确定
|
|
|
|
- </button>
|
|
|
|
- </div>
|
|
|
|
- </PopupLayout>
|
|
|
|
- </van-popup>
|
|
|
|
- <van-popup
|
|
|
|
- v-model="popupShow.end"
|
|
|
|
- round
|
|
|
|
- class="date-time-select-popup"
|
|
|
|
- :position="popup.position"
|
|
|
|
- :safe-area-inset-bottom="true"
|
|
|
|
- get-container="body"
|
|
|
|
- :style="popup.style"
|
|
|
|
- >
|
|
|
|
- <PopupLayout
|
|
|
|
- title="请选择结束时间"
|
|
|
|
- @closeIconClick="popupShow.end = false"
|
|
|
|
|
|
+ <PopupLayout
|
|
|
|
+ title="请选择开始时间"
|
|
|
|
+ @closeIconClick="popupShow.start = false"
|
|
|
|
+ >
|
|
|
|
+ <div slot="default">
|
|
|
|
+ <van-datetime-picker
|
|
|
|
+ class="date-time-picker highlight-active"
|
|
|
|
+ ref="startDateTimePicker"
|
|
|
|
+ v-model="start.currentDate"
|
|
|
|
+ :key="start.timestamp + 'start'"
|
|
|
|
+ :show-toolbar="picker.showToolBar"
|
|
|
|
+ :swipe-duration="picker.swipeDuration"
|
|
|
|
+ :type="picker.type"
|
|
|
|
+ :min-date="start.minDate"
|
|
|
|
+ :max-date="start.maxDate"
|
|
|
|
+ :formatter="formatter"
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ <div slot="footer" class="j-button-group height40">
|
|
|
|
+ <button class="j-button-cancel" @click="resetPopup('start')">
|
|
|
|
+ 重置
|
|
|
|
+ </button>
|
|
|
|
+ <button class="j-button-confirm" @click="confirmPicker('start')">
|
|
|
|
+ 确定
|
|
|
|
+ </button>
|
|
|
|
+ </div>
|
|
|
|
+ </PopupLayout>
|
|
|
|
+ </van-popup>
|
|
|
|
+ <van-popup
|
|
|
|
+ v-model="popupShow.end"
|
|
|
|
+ round
|
|
|
|
+ class="date-time-select-popup"
|
|
|
|
+ :position="popup.position"
|
|
|
|
+ :safe-area-inset-bottom="true"
|
|
|
|
+ get-container="body"
|
|
|
|
+ :style="popup.style"
|
|
>
|
|
>
|
|
- <div slot="default">
|
|
|
|
- <van-datetime-picker
|
|
|
|
- class="date-time-picker highlight-active"
|
|
|
|
- ref="endDateTimePicker"
|
|
|
|
- v-model="end.currentDate"
|
|
|
|
- :key="end.timestamp + 'end'"
|
|
|
|
- :show-toolbar="picker.showToolBar"
|
|
|
|
- :swipe-duration="picker.swipeDuration"
|
|
|
|
- :type="picker.type"
|
|
|
|
- :min-date="end.minDate"
|
|
|
|
- :max-date="end.maxDate"
|
|
|
|
- :formatter="formatter"
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- <div slot="footer" class="j-button-group height40">
|
|
|
|
- <button class="j-button-cancel" @click="resetPopup('end')">
|
|
|
|
- 重置
|
|
|
|
- </button>
|
|
|
|
- <button class="j-button-confirm" @click="confirmPicker('end')">
|
|
|
|
- 确定
|
|
|
|
- </button>
|
|
|
|
- </div>
|
|
|
|
- </PopupLayout>
|
|
|
|
- </van-popup>
|
|
|
|
|
|
+ <PopupLayout
|
|
|
|
+ title="请选择结束时间"
|
|
|
|
+ @closeIconClick="popupShow.end = false"
|
|
|
|
+ >
|
|
|
|
+ <div slot="default">
|
|
|
|
+ <van-datetime-picker
|
|
|
|
+ class="date-time-picker highlight-active"
|
|
|
|
+ ref="endDateTimePicker"
|
|
|
|
+ v-model="end.currentDate"
|
|
|
|
+ :key="end.timestamp + 'end'"
|
|
|
|
+ :show-toolbar="picker.showToolBar"
|
|
|
|
+ :swipe-duration="picker.swipeDuration"
|
|
|
|
+ :type="picker.type"
|
|
|
|
+ :min-date="end.minDate"
|
|
|
|
+ :max-date="end.maxDate"
|
|
|
|
+ :formatter="formatter"
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ <div slot="footer" class="j-button-group height40">
|
|
|
|
+ <button class="j-button-cancel" @click="resetPopup('end')">
|
|
|
|
+ 重置
|
|
|
|
+ </button>
|
|
|
|
+ <button class="j-button-confirm" @click="confirmPicker('end')">
|
|
|
|
+ 确定
|
|
|
|
+ </button>
|
|
|
|
+ </div>
|
|
|
|
+ </PopupLayout>
|
|
|
|
+ </van-popup>
|
|
|
|
+ </template>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<script>
|
|
<script>
|
|
import PopupLayout from '@/components/common/PopupLayout'
|
|
import PopupLayout from '@/components/common/PopupLayout'
|
|
import { DatetimePicker, Popup } from 'vant'
|
|
import { DatetimePicker, Popup } from 'vant'
|
|
import { inputDiv } from '@/ui/'
|
|
import { inputDiv } from '@/ui/'
|
|
-import { dateFormatter } from '@/utils/'
|
|
|
|
|
|
+import { dateFormatter, getDeviceInfo } from '@/utils/'
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
|
|
+import EventBus from '@/utils/event'
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: 'DateTimeGroup',
|
|
name: 'DateTimeGroup',
|
|
@@ -162,7 +165,9 @@ export default {
|
|
popupShow: {
|
|
popupShow: {
|
|
start: false,
|
|
start: false,
|
|
end: false
|
|
end: false
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ isIOS: true,
|
|
|
|
+ deviceInfo: {},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
@@ -174,7 +179,51 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ created() {
|
|
|
|
+ this.calcPlatform()
|
|
|
|
+ if (this.isIOS) {
|
|
|
|
+ this.registerEventBus()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
|
|
+ calcPlatform() {
|
|
|
|
+ this.deviceInfo = getDeviceInfo()
|
|
|
|
+ const system = this.deviceInfo.system
|
|
|
|
+ if (system) {
|
|
|
|
+ this.isIOS = system.toLowerCase().includes('ios')
|
|
|
|
+ console.log('是否ios',this.isIOS)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ registerEventBus() {
|
|
|
|
+ // 先移除监听
|
|
|
|
+ EventBus.off('dateTime:popup:sendValueToGroup')
|
|
|
|
+ EventBus.off('dateTime:popup:change')
|
|
|
|
+
|
|
|
|
+ EventBus.on('dateTime:popup:sendValueToGroup', (payload) => {
|
|
|
|
+ const { start, end, popupShow } = payload
|
|
|
|
+ Object.assign(this.start, start)
|
|
|
|
+ Object.assign(this.end, end)
|
|
|
|
+ Object.assign(this.popupShow, popupShow)
|
|
|
|
+ })
|
|
|
|
+ EventBus.on('dateTime:popup:change', () => {
|
|
|
|
+ this.onChange()
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ // 同步数据
|
|
|
|
+ sendValueToPopup() {
|
|
|
|
+ const payload = {
|
|
|
|
+ start: this.start,
|
|
|
|
+ end: this.end,
|
|
|
|
+ popupShow: this.popupShow,
|
|
|
|
+ }
|
|
|
|
+ EventBus.trigger('dateTime:popup:sendValueToPopup', payload)
|
|
|
|
+ },
|
|
|
|
+ startSyncValue() {
|
|
|
|
+ if (this.isIOS) {
|
|
|
|
+ this.registerEventBus() // 重新监听,兼容页面同时存在多组DateTimeGroup的情况
|
|
|
|
+ this.sendValueToPopup()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
formatter(type, val) {
|
|
formatter(type, val) {
|
|
if (type === 'year') {
|
|
if (type === 'year') {
|
|
return val + '年'
|
|
return val + '年'
|
|
@@ -199,9 +248,11 @@ export default {
|
|
} else if (type === 'end') {
|
|
} else if (type === 'end') {
|
|
this.start.maxDate = this.end.currentDate
|
|
this.start.maxDate = this.end.currentDate
|
|
}
|
|
}
|
|
|
|
+ this.startSyncValue()
|
|
},
|
|
},
|
|
popupState(type, state) {
|
|
popupState(type, state) {
|
|
this.popupShow[type] = state
|
|
this.popupShow[type] = state
|
|
|
|
+ this.startSyncValue()
|
|
},
|
|
},
|
|
resetAll() {
|
|
resetAll() {
|
|
this.resetPicker('start')
|
|
this.resetPicker('start')
|
|
@@ -242,6 +293,7 @@ export default {
|
|
}
|
|
}
|
|
// this[type].currentDate = new Date()
|
|
// this[type].currentDate = new Date()
|
|
// this[type].timestamp = Date.now()
|
|
// this[type].timestamp = Date.now()
|
|
|
|
+ this.startSyncValue()
|
|
},
|
|
},
|
|
resetPopup(type) {
|
|
resetPopup(type) {
|
|
this.resetPicker(type)
|
|
this.resetPicker(type)
|
|
@@ -257,6 +309,7 @@ export default {
|
|
this.popupShow.end = true
|
|
this.popupShow.end = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ this.startSyncValue()
|
|
this.onChange()
|
|
this.onChange()
|
|
},
|
|
},
|
|
onChange() {
|
|
onChange() {
|
|
@@ -299,6 +352,7 @@ export default {
|
|
const { end } = this.$options.data()
|
|
const { end } = this.$options.data()
|
|
Object.assign(this.end, end)
|
|
Object.assign(this.end, end)
|
|
}
|
|
}
|
|
|
|
+ this.startSyncValue()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|