|
|
@@ -1,56 +1,35 @@
|
|
|
<!-- 编辑弹窗 -->
|
|
|
<template>
|
|
|
- <ele-modal
|
|
|
- form
|
|
|
- :width="width"
|
|
|
- v-model="visible"
|
|
|
- :title="title"
|
|
|
- position="center"
|
|
|
- :body-style="{ maxHeight: '84vh', position: 'relative', ...bodyStyle }"
|
|
|
- >
|
|
|
- <slot name="other"></slot>
|
|
|
+ <ele-modal form :width="width" v-model="visible" :title="title" position="center"
|
|
|
+ :body-style="{ maxHeight: '84vh', position: 'relative', ...bodyStyle }">
|
|
|
+ <slot name="other"></slot>
|
|
|
|
|
|
- <SimpleForm
|
|
|
- :items="items"
|
|
|
- :labelWidth="labelWidth"
|
|
|
- ref="formRef"
|
|
|
- v-bind="formProps"
|
|
|
- :disabled="type === 'detail'"
|
|
|
- >
|
|
|
- <template
|
|
|
- v-for="(val, key) in slotArray"
|
|
|
- v-slot:[key]="{ item, model, updateValue }"
|
|
|
- >
|
|
|
- <slot
|
|
|
- :name="key"
|
|
|
- :item="item"
|
|
|
- :model="model"
|
|
|
- :updateValue="updateValue"
|
|
|
- ></slot>
|
|
|
- </template>
|
|
|
- </SimpleForm>
|
|
|
+ <SimpleForm :items="items" :labelWidth="labelWidth" ref="formRef" v-bind="formProps"
|
|
|
+ :disabled="type === 'detail'">
|
|
|
+ <template v-for="(val, key) in slotArray" v-slot:[key]="{ item, model, updateValue }">
|
|
|
+ <slot :name="key" :item="item" :model="model" :updateValue="updateValue"></slot>
|
|
|
+ </template>
|
|
|
+ </SimpleForm>
|
|
|
|
|
|
- <template #footer>
|
|
|
- <el-button @click="handleCancel">关闭</el-button>
|
|
|
- <el-button type="primary" @click="handleSumbit" v-if="type !== 'detail'"
|
|
|
- >确定</el-button
|
|
|
- >
|
|
|
- </template>
|
|
|
- </ele-modal>
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="handleCancel">关闭</el-button>
|
|
|
+ <el-button type="primary" @click="handleSumbit" v-if="type !== 'detail'">确定</el-button>
|
|
|
+ </template>
|
|
|
+ </ele-modal>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
- import { ref, reactive, nextTick, getCurrentInstance, useSlots } from 'vue';
|
|
|
- import { Flag, ChatDotSquare } from '@element-plus/icons-vue';
|
|
|
- import orderTimeline from '@/views/recycleOrder/components/order-timeline.vue';
|
|
|
- import SimpleForm from '@/components/CommonPage/SimpleForm.vue';
|
|
|
- import validators from '@/utils/validators';
|
|
|
- import { EleMessage } from 'ele-admin-plus/es';
|
|
|
- let { proxy } = getCurrentInstance();
|
|
|
+import { ref, reactive, nextTick, getCurrentInstance, useSlots } from 'vue';
|
|
|
+import { Flag, ChatDotSquare } from '@element-plus/icons-vue';
|
|
|
+import orderTimeline from '@/views/recycleOrder/components/order-timeline.vue';
|
|
|
+import SimpleForm from '@/components/CommonPage/SimpleForm.vue';
|
|
|
+import validators from '@/utils/validators';
|
|
|
+import { EleMessage } from 'ele-admin-plus/es';
|
|
|
+let { proxy } = getCurrentInstance();
|
|
|
|
|
|
- const slotArray = useSlots();
|
|
|
+const slotArray = useSlots();
|
|
|
|
|
|
- const props = defineProps({
|
|
|
+const props = defineProps({
|
|
|
items: { type: Array, default: () => [] },
|
|
|
title: { type: String, default: '编辑' },
|
|
|
type: { type: String },
|
|
|
@@ -62,75 +41,80 @@
|
|
|
//是否需要合并打开时传入的参数
|
|
|
isMerge: { type: Boolean, default: false },
|
|
|
formatData: {
|
|
|
- type: Function,
|
|
|
- default: (data) => data
|
|
|
+ type: Function,
|
|
|
+ default: (data) => data
|
|
|
}, //格式化提交数据
|
|
|
fallbackData: { type: Function, default: (data) => data } //回填数据
|
|
|
- });
|
|
|
- const emit = defineEmits(['success']);
|
|
|
- /** 弹窗是否打开 */
|
|
|
- const visible = defineModel({ type: Boolean });
|
|
|
+});
|
|
|
+const emit = defineEmits(['success']);
|
|
|
+/** 弹窗是否打开 */
|
|
|
+const visible = defineModel({ type: Boolean });
|
|
|
|
|
|
- /** 关闭弹窗 */
|
|
|
- const handleCancel = () => {
|
|
|
+/** 关闭弹窗 */
|
|
|
+const handleCancel = () => {
|
|
|
visible.value = false;
|
|
|
- };
|
|
|
+};
|
|
|
|
|
|
- const form = ref({});
|
|
|
- const mergeData = ref({});
|
|
|
- /** 弹窗打开事件 */
|
|
|
- const handleOpen = async (data) => {
|
|
|
+const form = ref({});
|
|
|
+const mergeData = ref({});
|
|
|
+/** 弹窗打开事件 */
|
|
|
+const handleOpen = async (data) => {
|
|
|
visible.value = true;
|
|
|
nextTick(() => {
|
|
|
- formRef.value?.resetForm();
|
|
|
- mergeData.value = data;
|
|
|
- if (!props.baseUrl.detail) {
|
|
|
- form.value = data;
|
|
|
- formRef.value?.setData(data);
|
|
|
- } else {
|
|
|
- getDetail(data.id).then((res) => {
|
|
|
- form.value = res.data;
|
|
|
- let data = props.fallbackData(res.data);
|
|
|
- formRef.value?.setData(data);
|
|
|
- });
|
|
|
- }
|
|
|
+ formRef.value?.resetForm();
|
|
|
+ mergeData.value = data;
|
|
|
+ if (!props.baseUrl.detail) {
|
|
|
+ form.value = data;
|
|
|
+ formRef.value?.setData(data);
|
|
|
+ } else {
|
|
|
+ getDetail(data.id).then((res) => {
|
|
|
+ form.value = res.data;
|
|
|
+ let data = props.fallbackData(res.data);
|
|
|
+ formRef.value?.setData(data);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
- };
|
|
|
+};
|
|
|
|
|
|
- //获取详情数据
|
|
|
- const getDetail = (id) => {
|
|
|
+//获取详情数据
|
|
|
+const getDetail = (id) => {
|
|
|
if (!props.baseUrl.detail || !id) return;
|
|
|
let url = `${props.baseUrl.detail}/${id}`;
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- proxy.$http.get(url).then((res) => {
|
|
|
- if (res.data.code !== 200) return EleMessage.error(res.data.msg);
|
|
|
- resolve(res.data || {});
|
|
|
- });
|
|
|
+ proxy.$http.get(url).then((res) => {
|
|
|
+ if (res.data.code !== 200) return EleMessage.error(res.data.msg);
|
|
|
+ resolve(res.data || {});
|
|
|
+ });
|
|
|
});
|
|
|
- };
|
|
|
+};
|
|
|
|
|
|
- const formRef = ref();
|
|
|
- const handleSumbit = () => {
|
|
|
+const formRef = ref();
|
|
|
+const handleSumbit = () => {
|
|
|
console.log(props.formatData, '格式化数据');
|
|
|
|
|
|
formRef.value?.submitForm().then((data) => {
|
|
|
- console.log(data, '格式化数据data');
|
|
|
+ console.log(data, '格式化数据data');
|
|
|
|
|
|
- data.id = form.value?.id;
|
|
|
- let url = data.id ? props.baseUrl.update : props.baseUrl.add;
|
|
|
- data = props.isMerge ? { ...mergeData.value, ...data } : data;
|
|
|
- let format = props.formatData(data);
|
|
|
- proxy.$http.post(url, format).then((res) => {
|
|
|
- if (res.data.code !== 200) return EleMessage.error(res.data.msg);
|
|
|
- visible.value = false;
|
|
|
- emit('success', data);
|
|
|
- EleMessage.success(format.id ? '编辑成功' : '操作成功');
|
|
|
- });
|
|
|
+ data.id = form.value?.id;
|
|
|
+ let url = data.id ? props.baseUrl.update : props.baseUrl.add;
|
|
|
+ data = props.isMerge ? { ...mergeData.value, ...data } : data;
|
|
|
+ let format = props.formatData(data);
|
|
|
+ proxy.$http.post(url, format).then((res) => {
|
|
|
+ if (res.data.code !== 200) return EleMessage.error(res.data.msg);
|
|
|
+ visible.value = false;
|
|
|
+ emit('success', data);
|
|
|
+ EleMessage.success(format.id ? '编辑成功' : '操作成功');
|
|
|
+ });
|
|
|
});
|
|
|
- };
|
|
|
+};
|
|
|
+
|
|
|
+const setData = (data) => {
|
|
|
+ formRef.value?.setData(data);
|
|
|
+};
|
|
|
|
|
|
- defineExpose({
|
|
|
+defineExpose({
|
|
|
handleOpen,
|
|
|
- handleSumbit
|
|
|
- });
|
|
|
+ handleSumbit,
|
|
|
+ setData
|
|
|
+});
|
|
|
</script>
|