wms-antdvue/.svn/pristine/ef/ef0969c9291e0ebf71bb9962f84c0cc8046fe54a.svn-base
2024-11-07 16:33:03 +08:00

109 lines
2.7 KiB
Plaintext

<template>
<a-modal
v-model:visible="props.visible"
:title="props.positionId?'编辑':'新增'"
width="500px"
@cancel="dialogClose"
>
<a-form
class="ls-form"
ref="formRef"
:model="formData"
:label-col="{ style: { width: '85px' }}"
>
<a-form-item
label="岗位名称"
name="name"
:rules="{ required: true, message: '请输入岗位名称', trigger: 'blur' }"
>
<a-input
v-model:value="formData.name"
placeholder="请输入岗位名称"
allow-clear
/>
</a-form-item>
<a-form-item
label="岗位状态"
name="code"
>
<a-radio-group v-model:value="formData.status" name="status">
<a-radio :value="1">正常</a-radio>
<a-radio :value="2">停用</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="排序" name="sort">
<a-input-number v-model:value="formData.sort"/>
</a-form-item>
</a-form>
<template #footer>
<span class="dialog-footer">
<a-button @click="dialogClose">取消</a-button>
<a-button :loading="subLoading" type="primary" @click="submit">
确定
</a-button>
</span>
</template>
</a-modal>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
import {getPositionDetail,positionAdd,positionUpdate} from "@/api/system/position";
import {onMounted, reactive, shallowRef} from "vue";
import { message } from 'ant-design-vue';
import {useLockFn} from "@/utils/useLockFn";
const emit = defineEmits(["success", "update:visible"]);
const formRef = shallowRef<FormInstance>();
const formData = reactive({
id: "",
name: "",
status: 1,
sort: 0
});
const props = defineProps({
visible: {
type: Boolean,
required: true,
default: false
},
positionId: {
type: Number,
required: true,
default: 0
}
});
const handleSubmit = async () => {
await formRef.value?.validate();
props.positionId ? await positionUpdate(formData) : await positionAdd(formData);
message.success("操作成功");
emit("update:visible", false);
emit("success");
};
const dialogClose = () => {
emit("update:visible", false);
};
const { isLock: subLoading,lockFn: submit } = useLockFn(handleSubmit);
const setFormData = async () => {
const data = await getPositionDetail(props.positionId);
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key];
}
}
};
onMounted(() => {
if (props.positionId) {
setFormData();
}
});
</script>