popup.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <BasicModal width="800px" v-bind="$attrs" @register="register" @ok="confirm" :title="title">
  3. <BasicForm @register="registerForm" :model="model" />
  4. </BasicModal>
  5. </template>
  6. <script lang="ts">
  7. import { defineComponent, PropType, reactive, ref, toRefs } from 'vue';
  8. import { BasicModal, useModalInner } from '/@/components/Modal';
  9. import { BasicForm, useForm } from '/@/components/Form/index';
  10. import { useMessage } from '/@/hooks/web/useMessage';
  11. import { schemas } from './data';
  12. import moment from 'moment';
  13. interface PopupData {
  14. title: string;
  15. }
  16. interface Role {
  17. id: string | number;
  18. }
  19. export default defineComponent({
  20. components: { BasicModal, BasicForm },
  21. props: {
  22. popupData: {
  23. type: Object as PropType<PopupData>,
  24. default: () => {},
  25. },
  26. },
  27. emits: ['saveData'],
  28. setup(props, { emit }) {
  29. const popupData = props.popupData as PopupData;
  30. const modelRef = ref({});
  31. const role = reactive<Role>({
  32. id: 0,
  33. });
  34. const { createMessage } = useMessage();
  35. const { error } = createMessage;
  36. const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
  37. labelWidth: 120,
  38. schemas,
  39. showActionButtonGroup: false,
  40. actionColOptions: {
  41. span: 24,
  42. },
  43. });
  44. // const [register, { closeModal }] = useModalInner((data) => {
  45. // modelRef.value = data;
  46. //
  47. // });
  48. const [register, { closeModal }] = useModalInner((data) => {
  49. resetFields();
  50. console.log(`data ----id?`, data.id);
  51. if (data.id) {
  52. role.id = data.id;
  53. } else {
  54. role.id = 0;
  55. }
  56. setFieldsValue(data);
  57. });
  58. async function confirm() {
  59. const data = await validate();
  60. console.log(`确定`, data);
  61. const not_validate = data.family.some((item) => {
  62. if (item.relation === '' || item.age === '' || item.job === '' || item.company === '') {
  63. error('家庭成员信息不能为空');
  64. return true;
  65. }
  66. });
  67. if (not_validate) {
  68. return;
  69. }
  70. data.id = role.id;
  71. data.birthday = moment(data.birthday).format('YYYY-MM-DD');
  72. data.family = JSON.stringify(data.family);
  73. const popupData = { closeModal, data };
  74. emit('saveData', popupData);
  75. // closeModal(); // 关闭弹窗
  76. }
  77. return {
  78. register,
  79. schemas,
  80. registerForm,
  81. model: modelRef,
  82. confirm,
  83. ...toRefs(popupData),
  84. };
  85. },
  86. });
  87. </script>
  88. <style lang="less">
  89. .ant-form-item-label {
  90. overflow: hidden;
  91. text-align: center !important;
  92. // white-space: pre-wrap !important;
  93. text-overflow: ellipsis;
  94. white-space: nowrap;
  95. }
  96. @media (max-width: 639px) {
  97. .ant-form-item-label {
  98. line-height: 2.5715 !important;
  99. text-align: center !important;
  100. }
  101. }
  102. </style>