drop-down-modal.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Button, Picker, PickerColumn } from 'vant';
  2. import { PropType, defineComponent, onMounted, reactive, watch } from 'vue';
  3. export default defineComponent({
  4. name: 'drop-down-modal',
  5. props: {
  6. selectValues: {
  7. type: [String, Number],
  8. default: null
  9. },
  10. columns: {
  11. type: Array as PropType<PickerColumn>,
  12. default: () => []
  13. },
  14. open: {
  15. type: Boolean,
  16. default: false
  17. }
  18. },
  19. emits: ['dropDownClose', 'dropDownConfirm'],
  20. setup(props, { emit }) {
  21. const forms = reactive({
  22. values: [] as any
  23. });
  24. onMounted(() => {
  25. forms.values = [props.selectValues];
  26. });
  27. watch(
  28. () => props.selectValues,
  29. () => {
  30. forms.values = [props.selectValues];
  31. }
  32. );
  33. watch(
  34. () => props.open,
  35. () => {
  36. setTimeout(() => {
  37. forms.values = [props.selectValues];
  38. }, 100);
  39. }
  40. );
  41. return () => (
  42. <>
  43. <Picker
  44. v-model={forms.values}
  45. showToolbar={false}
  46. visibleOptionNum={5}
  47. columns={props.columns}
  48. />
  49. <div class={['btnGroupPopup', 'van-hairline--top']}>
  50. <Button round onClick={() => emit('dropDownClose')}>
  51. 取消
  52. </Button>
  53. <Button
  54. type="primary"
  55. round
  56. onClick={() => {
  57. emit('dropDownConfirm', forms.values);
  58. }}>
  59. 确定
  60. </Button>
  61. </div>
  62. </>
  63. );
  64. }
  65. });