SimpleFormModal.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!-- 编辑弹窗 -->
  2. <template>
  3. <ele-modal form :width="width" v-model="visible" :title="title">
  4. <SimpleForm
  5. :items="items"
  6. :labelWidth="labelWidth"
  7. ref="formRef"
  8. v-bind="formProps"
  9. ></SimpleForm>
  10. <template #footer>
  11. <el-button @click="handleCancel">关闭</el-button>
  12. <el-button type="primary" @click="handleSumbit">确定</el-button>
  13. </template>
  14. </ele-modal>
  15. </template>
  16. <script setup>
  17. import { ref, reactive, nextTick, getCurrentInstance } from 'vue';
  18. import { Flag, ChatDotSquare } from '@element-plus/icons-vue';
  19. import orderTimeline from '@/views/recycleOrder/components/order-timeline.vue';
  20. import SimpleForm from '@/components/CommonPage/SimpleForm.vue';
  21. import validators from '@/utils/validators';
  22. import { EleMessage } from 'ele-admin-plus/es';
  23. let { proxy } = getCurrentInstance();
  24. const props = defineProps({
  25. items: { type: Array, default: () => [] },
  26. title: { type: String, default: '编辑' },
  27. width: { type: String, default: '520px' },
  28. labelWidth: { type: String, default: '90px' },
  29. formProps: { type: Object, default: () => ({}) },
  30. baseUrl: { type: Object, default: () => ({}) }
  31. });
  32. const emit = defineEmits(['success']);
  33. /** 弹窗是否打开 */
  34. const visible = defineModel({ type: Boolean });
  35. /** 关闭弹窗 */
  36. const handleCancel = () => {
  37. visible.value = false;
  38. nextTick(() => {
  39. formRef.value?.resetForm();
  40. });
  41. };
  42. const form = ref({});
  43. /** 弹窗打开事件 */
  44. const handleOpen = (data) => {
  45. visible.value = true;
  46. nextTick(() => {
  47. form.value = data;
  48. formRef.value?.assignFields(data);
  49. });
  50. };
  51. const formRef = ref();
  52. const handleSumbit = () => {
  53. formRef.value?.submitForm().then((data) => {
  54. data.id = form.value?.id;
  55. let url = data.id ? props.baseUrl.update : props.baseUrl.add;
  56. proxy.$http.post(url, data).then((res) => {
  57. if (res.data.code !== 200) return;
  58. visible.value = false;
  59. emit('success', data);
  60. EleMessage.success(form.id ? '编辑成功' : '新增成功');
  61. });
  62. });
  63. };
  64. defineExpose({
  65. handleOpen,
  66. handleSumbit
  67. });
  68. </script>