feat(select): 增加批次和仓库过滤功能,优化库存选择器

pull/871/MERGE
YunaiV 2026-04-08 13:59:14 +08:00
parent 5cc0a96db0
commit b0fc3b05f2
2 changed files with 44 additions and 73 deletions

View File

@ -3,11 +3,11 @@
<div> <div>
<!-- 操作栏 --> <!-- 操作栏 -->
<el-button <el-button
v-if="!readonly" v-if="!isDetail"
type="primary" type="primary"
plain plain
size="small" size="small"
@click="openForm('create')" @click="openTeamSelect"
class="mb-10px" class="mb-10px"
> >
<Icon icon="ep:plus" class="mr-5px" /> 添加班组 <Icon icon="ep:plus" class="mr-5px" /> 添加班组
@ -28,7 +28,7 @@
<el-table-column label="班组编码" align="center" prop="teamCode" min-width="100" /> <el-table-column label="班组编码" align="center" prop="teamCode" min-width="100" />
<el-table-column label="班组名称" align="center" prop="teamName" min-width="100" /> <el-table-column label="班组名称" align="center" prop="teamName" min-width="100" />
<el-table-column label="备注" align="center" prop="remark" min-width="120" /> <el-table-column label="备注" align="center" prop="remark" min-width="120" />
<el-table-column v-if="!readonly" label="操作" align="center" width="80"> <el-table-column v-if="!isDetail" label="操作" align="center" width="80">
<template #default="scope"> <template #default="scope">
<el-button link type="danger" @click="handleDelete(scope.row.id)"></el-button> <el-button link type="danger" @click="handleDelete(scope.row.id)"></el-button>
</template> </template>
@ -69,42 +69,26 @@
</el-col> </el-col>
</el-row> </el-row>
<!-- 表单弹窗添加/修改 --> <!-- 班组多选弹窗 -->
<Dialog :title="dialogTitle" v-model="dialogVisible" width="500px"> <CalTeamSelectDialog ref="teamDialogRef" :multiple="true" @selected="handleTeamsSelected" />
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="80px"
v-loading="formLoading"
>
<el-form-item label="班组" prop="teamId">
<CalTeamSelect v-model="formData.teamId" class="!w-1/1" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { CalPlanTeamApi, CalPlanTeamVO } from '@/api/mes/cal/plan/team' import { CalPlanTeamApi, CalPlanTeamVO } from '@/api/mes/cal/plan/team'
import { CalTeamMemberApi, CalTeamMemberVO } from '@/api/mes/cal/team/member' import { CalTeamMemberApi, CalTeamMemberVO } from '@/api/mes/cal/team/member'
import CalTeamSelect from '@/views/mes/cal/team/components/CalTeamSelect.vue' import { CalTeamVO } from '@/api/mes/cal/team'
import CalTeamSelectDialog from '@/views/mes/cal/team/components/CalTeamSelectDialog.vue'
defineOptions({ name: 'CalPlanTeamList' }) defineOptions({ name: 'CalPlanTeamList' })
const props = defineProps<{ const props = defineProps<{
planId: number // planId: number //
readonly?: boolean // TODO @AI formType formType: string // 表单的类型create / update / detail
}>() }>()
const isDetail = computed(() => props.formType === 'detail') // DONE @AI formType
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -145,59 +129,44 @@ const handleTeamSelect = async (row: CalPlanTeamVO | null) => {
} }
} }
// ==================== / ==================== // ==================== ====================
const dialogVisible = ref(false) // const teamDialogRef = ref()
const dialogTitle = ref('') //
const formLoading = ref(false) //
const formRef = ref() // Ref
const formData = ref({
id: undefined as number | undefined,
planId: undefined as number | undefined,
teamId: undefined as number | undefined,
remark: undefined as string | undefined
})
const formRules = reactive({
teamId: [{ required: true, message: '班组不能为空', trigger: 'blur' }]
})
/** 打开表单弹窗 */ /** 打开班组多选弹窗 */
const openForm = async (type: string) => { const openTeamSelect = () => {
dialogVisible.value = true // ID 便
dialogTitle.value = t('action.' + type) const existingTeamIds = list.value.map((item) => item.teamId)
resetForm() teamDialogRef.value.open(existingTeamIds)
} }
/** 提交表单 */ /** 多选班组确认后,批量创建关联 */
const submitForm = async () => { const handleTeamsSelected = async (rows: CalTeamVO[]) => {
// if (!rows || rows.length === 0) {
if (!formRef) return return
const valid = await formRef.value.validate() }
if (!valid) return //
// const existingTeamIds = new Set(list.value.map((item) => item.teamId))
formLoading.value = true const newTeams = rows.filter((team) => !existingTeamIds.has(team.id))
if (newTeams.length === 0) {
message.warning('所选班组已全部添加过')
return
}
//
loading.value = true
try { try {
const data = formData.value as unknown as CalPlanTeamVO for (const team of newTeams) {
await CalPlanTeamApi.createPlanTeam(data) await CalPlanTeamApi.createPlanTeam({
message.success(t('common.createSuccess')) planId: props.planId,
dialogVisible.value = false teamId: team.id
// } as unknown as CalPlanTeamVO)
}
message.success(`成功添加 ${newTeams.length} 个班组`)
await getList() await getList()
} finally { } finally {
formLoading.value = false loading.value = false
} }
} }
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
planId: props.planId,
teamId: undefined,
remark: undefined
}
formRef.value?.resetFields()
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
try { try {

View File

@ -3,7 +3,7 @@
<div> <div>
<!-- 操作栏 --> <!-- 操作栏 -->
<el-button <el-button
v-if="!readonly" v-if="!isDetail"
type="primary" type="primary"
plain plain
size="small" size="small"
@ -19,7 +19,7 @@
<el-table-column label="开始时间" align="center" prop="startTime" width="100" /> <el-table-column label="开始时间" align="center" prop="startTime" width="100" />
<el-table-column label="结束时间" align="center" prop="endTime" width="100" /> <el-table-column label="结束时间" align="center" prop="endTime" width="100" />
<el-table-column label="备注" align="center" prop="remark" min-width="150" /> <el-table-column label="备注" align="center" prop="remark" min-width="150" />
<el-table-column v-if="!readonly" label="操作" align="center" width="120"> <el-table-column v-if="!isDetail" label="操作" align="center" width="120">
<template #default="scope"> <template #default="scope">
<el-button link type="primary" @click="openForm('update', scope.row)">编辑</el-button> <el-button link type="primary" @click="openForm('update', scope.row)">编辑</el-button>
<el-button link type="danger" @click="handleDelete(scope.row.id)"></el-button> <el-button link type="danger" @click="handleDelete(scope.row.id)"></el-button>
@ -84,9 +84,11 @@ defineOptions({ name: 'CalShiftList' })
const props = defineProps<{ const props = defineProps<{
planId: number // planId: number //
readonly?: boolean // TODO @AI formType formType: string // 表单的类型create / update / detail
}>() }>()
const isDetail = computed(() => props.formType === 'detail') // DONE @AI formType
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //