mobile.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { ref, computed } from 'vue'
  2. import { Field as VantField, Popup as VanPopup, Picker as VanPicker } from 'vant'
  3. import { useFormInput } from '../../../hooks/form-input'
  4. import { formInputProps } from '../../form-input-props'
  5. import { nextTime, compareTime } from './utils'
  6. export default {
  7. props: formInputProps,
  8. setup (props, context) {
  9. const { emitModelValue, placeholder, width } = useFormInput(props, context)
  10. const start = computed(() => {
  11. return props.config?.start ?? '08:00'
  12. })
  13. const end = computed(() => {
  14. return props.config?.end ?? '20:00'
  15. })
  16. const step = computed(() => {
  17. return props.config?.step ?? '00:30'
  18. })
  19. // picker中的列表值
  20. const columns = computed(() => {
  21. const result = []
  22. if (start.value && end.value && step.value) {
  23. let current = start.value
  24. while (!compareTime(current, end.value)) {
  25. result.push(current)
  26. current = nextTime(current, step.value)
  27. }
  28. }
  29. return result
  30. })
  31. const show = ref(false)
  32. const openPopup = () => {
  33. show.value = true
  34. }
  35. const confirm = (val) => {
  36. emitModelValue(val)
  37. show.value = false
  38. }
  39. const cancel = () => {
  40. show.value = false
  41. }
  42. return () => <div style={{ width: width.value }}>
  43. <VantField modelValue={props.modelValue}
  44. placeholder={placeholder.value}
  45. readonly
  46. is-link
  47. onclick={openPopup}></VantField>
  48. <VanPopup show={show.value} position="bottom" style="height: 40%">
  49. <VanPicker title='选择时间'
  50. modelValue={props.modelValue}
  51. columns={columns.value}
  52. onConfirm={confirm}
  53. onCancel={cancel} />
  54. </VanPopup>
  55. </div>
  56. }
  57. }