popup.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 { createMessage } = useMessage();
  30. const { error } = createMessage;
  31. const popupData = props.popupData as PopupData;
  32. const modelRef = ref({});
  33. const role = reactive<Role>({
  34. id: 0,
  35. });
  36. const [registerForm, { updateSchema, 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. resetFields();
  46. if (data.id) {
  47. role.id = data.id;
  48. updateSchema([
  49. {
  50. field: 'type',
  51. componentProps: {
  52. disabled: true,
  53. options: [
  54. { label: '个人', value: '2' },
  55. { label: '单位', value: '1' },
  56. ],
  57. },
  58. },
  59. ]);
  60. // data.username = data.admin.username;
  61. setFieldsValue(data);
  62. } else {
  63. role.id = 0;
  64. updateSchema([
  65. {
  66. field: 'type',
  67. componentProps: {
  68. disabled: false,
  69. options: [
  70. { label: '个人', value: '2' },
  71. { label: '单位', value: '1' },
  72. ],
  73. },
  74. },
  75. ]);
  76. }
  77. });
  78. async function confirm() {
  79. try {
  80. const data = await validate();
  81. console.log(`确定`, data);
  82. data.id = role.id;
  83. if (data.name) {
  84. data.fromId = data.name.id;
  85. } else {
  86. data.fromId = data.unitName.id;
  87. }
  88. data.jointime = moment(data.jointime).format('YYYY-MM-DD');
  89. delete data.relation;
  90. delete data.relationUnit;
  91. delete data.unitName;
  92. delete data.name;
  93. const popupData = { closeModal, data };
  94. emit('saveData', popupData);
  95. } catch (err: any) {
  96. error(err.errorFields[0].errors[0]);
  97. }
  98. }
  99. return {
  100. register,
  101. schemas,
  102. registerForm,
  103. model: modelRef,
  104. confirm,
  105. ...toRefs(popupData),
  106. };
  107. },
  108. });
  109. </script>
  110. <style lang="less">
  111. .ant-form-item-label {
  112. overflow: hidden;
  113. text-align: center !important;
  114. // white-space: pre-wrap !important;
  115. text-overflow: ellipsis;
  116. white-space: nowrap;
  117. }
  118. @media (max-width: 639px) {
  119. .ant-form-item-label {
  120. line-height: 2.5715 !important;
  121. text-align: center !important;
  122. }
  123. }
  124. </style>