popup.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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, { 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. // modelRef.value = data;
  46. //
  47. // });
  48. const [register, { closeModal }] = useModalInner((data) => {
  49. resetFields();
  50. if (data.id) {
  51. role.id = data.id;
  52. updateSchema([
  53. {
  54. field: 'year',
  55. componentProps: {
  56. disabled: true,
  57. },
  58. },
  59. {
  60. field: 'duty',
  61. componentProps: {
  62. disabled: true,
  63. },
  64. },
  65. ]);
  66. } else {
  67. role.id = 0;
  68. data.car = '';
  69. updateSchema([
  70. {
  71. field: 'year',
  72. componentProps: {
  73. disabled: false,
  74. },
  75. },
  76. {
  77. field: 'duty',
  78. componentProps: {
  79. disabled: false,
  80. },
  81. },
  82. ]);
  83. }
  84. // 时间戳处理
  85. data.starttime = data.starttime * 1000;
  86. data.endtime = data.endtime * 1000;
  87. setFieldsValue(data);
  88. });
  89. async function confirm() {
  90. try {
  91. const data = await validate();
  92. console.log(`确定`, data);
  93. data.id = role.id;
  94. if (data.plan && data.plan[0]) {
  95. const plan: any[] = [];
  96. data.plan.map((item) => {
  97. if (item.id) {
  98. plan.push(item.id);
  99. }
  100. });
  101. data.plan = plan.toString();
  102. }
  103. if (data.apply && data.apply[0]) {
  104. const apply: any[] = [];
  105. data.apply.map((item) => {
  106. if (item.id) {
  107. apply.push(item.id);
  108. }
  109. });
  110. data.apply = apply.toString();
  111. }
  112. if (data.actual && data.actual[0]) {
  113. const actual: any[] = [];
  114. data.actual.map((item) => {
  115. if (item.id) {
  116. actual.push(item.id);
  117. }
  118. });
  119. data.actual = actual.toString();
  120. }
  121. if (data.car) {
  122. data.car = JSON.stringify(data.car);
  123. }
  124. data.starttime = moment(data.starttime).unix();
  125. data.endtime = moment(data.endtime).unix();
  126. const popupData = { closeModal, data };
  127. emit('saveData', popupData);
  128. } catch (err: any) {
  129. console.log(`err`, err);
  130. error(err.errorFields[0].errors[0]);
  131. }
  132. }
  133. return {
  134. register,
  135. schemas,
  136. registerForm,
  137. model: modelRef,
  138. confirm,
  139. ...toRefs(popupData),
  140. };
  141. },
  142. });
  143. </script>
  144. <style lang="less">
  145. .ant-form-item-label {
  146. overflow: hidden;
  147. text-align: center !important;
  148. // white-space: pre-wrap !important;
  149. text-overflow: ellipsis;
  150. white-space: nowrap;
  151. }
  152. @media (max-width: 639px) {
  153. .ant-form-item-label {
  154. line-height: 2.5715 !important;
  155. text-align: center !important;
  156. }
  157. }
  158. </style>