2023-01-18 16:23:39 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
2023-02-08 20:29:34 +08:00
|
|
|
<n-spin :show="loading" description="请稍候...">
|
|
|
|
<n-modal
|
|
|
|
v-model:show="isShowModal"
|
|
|
|
:show-icon="false"
|
|
|
|
preset="dialog"
|
|
|
|
:title="params?.@{.pk.TsName} > 0 ? '编辑 #' + params?.@{.pk.TsName} : '添加'"
|
|
|
|
:style="{
|
|
|
|
width: dialogWidth,
|
|
|
|
}"
|
2023-01-18 16:23:39 +08:00
|
|
|
>
|
2023-02-08 20:29:34 +08:00
|
|
|
<n-form
|
|
|
|
:model="params"
|
|
|
|
:rules="rules"
|
|
|
|
ref="formRef"
|
|
|
|
label-placement="left"
|
|
|
|
:label-width="80"
|
|
|
|
class="py-4"
|
|
|
|
>
|
2023-01-18 16:23:39 +08:00
|
|
|
@{.formItem}
|
2023-02-08 20:29:34 +08:00
|
|
|
</n-form>
|
2023-01-18 16:23:39 +08:00
|
|
|
<template #action>
|
|
|
|
<n-space>
|
|
|
|
<n-button @click="closeForm">取消</n-button>
|
|
|
|
<n-button type="info" :loading="formBtnLoading" @click="confirmForm">确定</n-button>
|
|
|
|
</n-space>
|
|
|
|
</template>
|
2023-02-08 20:29:34 +08:00
|
|
|
</n-modal>
|
|
|
|
</n-spin>
|
2023-01-18 16:23:39 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
@{.script.import} import { rules, options, State, newState } from './model';
|
|
|
|
import { useMessage } from 'naive-ui';
|
|
|
|
import { adaModalWidth } from '@/utils/hotgo';
|
|
|
|
|
|
|
|
const emit = defineEmits(['reloadTable', 'updateShowModal']);
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
showModal: boolean;
|
|
|
|
formParams?: State;
|
|
|
|
}
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
showModal: false,
|
|
|
|
formParams: () => {
|
|
|
|
return newState(null);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const isShowModal = computed({
|
|
|
|
get: () => {
|
|
|
|
return props.showModal;
|
|
|
|
},
|
|
|
|
set: (value) => {
|
|
|
|
emit('updateShowModal', value);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-02-08 20:29:34 +08:00
|
|
|
const loading = ref(false);
|
|
|
|
const params = ref<State>(props.formParams);
|
2023-01-18 16:23:39 +08:00
|
|
|
const message = useMessage();
|
|
|
|
const formRef = ref<any>({});
|
|
|
|
const dialogWidth = ref('75%');
|
|
|
|
const formBtnLoading = ref(false);
|
|
|
|
|
|
|
|
function confirmForm(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
formBtnLoading.value = true;
|
|
|
|
formRef.value.validate((errors) => {
|
|
|
|
if (!errors) {
|
|
|
|
Edit(params.value).then((_res) => {
|
|
|
|
message.success('操作成功');
|
|
|
|
setTimeout(() => {
|
|
|
|
isShowModal.value = false;
|
|
|
|
emit('reloadTable');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
message.error('请填写完整信息');
|
|
|
|
}
|
|
|
|
formBtnLoading.value = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
adaModalWidth(dialogWidth);
|
|
|
|
});
|
|
|
|
|
|
|
|
function closeForm() {
|
|
|
|
isShowModal.value = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@{.script.setup}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less"></style>
|