heli-mes/mes-ui/mes-ui-admin-vue3/src/views/heli/materialplan/boom.vue

203 lines
7.7 KiB
Vue
Raw Normal View History

2025-01-09 18:29:48 +08:00
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="80%">
<ContentWrap class="borderxx">
<el-form class="-mb-15px" :model="queryReqVo" :inline="true" label-width="108px">
<el-form-item label=" 零件名称:" label-width="150px">
<el-input v-model="queryReqVo.materialName" placeholder="零件名称" class="!w-240px" />
</el-form-item>
<el-form-item label=" 子项目编号:" label-width="150px">
<el-input v-model="queryReqVo.projectSubCode" placeholder="子项目编号" class="!w-240px" />
</el-form-item>
<el-form-item>
<el-button @click="handleQuery" type="primary" >
<Icon icon="ep:search" class="mr-5px" /> 搜索
</el-button><el-button @click="resetQuery" >
<Icon icon="ep:refresh" class="mr-5px" /> 重置
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<el-card class="hl-table">
<el-table ref="multipleTable" :data="list" v-loading="formLoading" class="hl-table" :reserve-selection="true" @selection-change="handleSelectionChange" :row-key="getRowKeys" min-width="1800" @row-click="clickRow">
<el-table-column type="selection" width="55" :selectable="row=>chkboxEnable" />
2025-01-09 18:29:48 +08:00
<!-- <el-table-column prop="no" label="序号" min-width="120" align="center" /> -->
<el-table-column label="序号" type="index" min-width="120" align="center" />
<el-table-column prop="materialName" label="零件名称" min-width="120" align="center" />
<el-table-column prop="boomSpec" label="规格型号" min-width="140" align="center" />
<el-table-column prop="compositionName" label="材质" min-width="120" align="center" />
<el-table-column prop="amount" label="需求数量" min-width="120" align="center" />
<el-table-column prop="boomUnit" label="系统单位" min-width="120" align="center" >
<template #default="scope">
<dict-tag :type="DICT_TYPE.HELI_MATERIAL_UNIT" :value="scope.row.boomUnit" />
</template>
</el-table-column>
<el-table-column prop="projectSubCode" label="子项目编号" min-width="120" align="center" />
</el-table>
<!-- 分页 -->
<Pagination :total="total" v-model:page="queryReqVo.pageNo" v-model:limit="queryReqVo.pageSize" @pagination="handleQuery" />
</el-card>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import * as MaterialPlanBoomApi from '@/api/heli/materialplanboom'
import { ElTable } from 'element-plus'
import { cursorTo } from 'readline'
2025-01-09 18:29:48 +08:00
const chkboxEnable = ref(true)
const { t } = useI18n() // 国际化
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中1修改时的数据加载2提交的按钮禁用
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const planIdInit = ref()
const multipleTable = ref<InstanceType<typeof ElTable>>()
const multipleSelection = ref([])
const nowPageIds = ref([])
const storage = ref(false)
2025-01-09 18:29:48 +08:00
const handleSelectionChange = (val: []) => {
if(selectedRowBeforeKeys.value == null || selectedRowBeforeKeys.value.length == 0 ){
selectedRowNowKeys.value = val;
selectedRowBeforeKeys.value = val;
multipleSelection.value = selectedRowBeforeKeys.value
2025-05-07 11:00:06 +08:00
}else{
if(val != null && val.length > 0){
//对比一下看看多了还是少了多了selectedRowBeforeKeys.value就添加那个多了的元素少了selectedRowBeforeKeys.value就移除不同的元素 然后 selectedRowNowKeys.value = val;
// 提取新数据中的ID数组
const newIds = val.map(item => item.id);
// 提取当前页已选中的ID数组
const currentIds = selectedRowNowKeys.value.map(item => item.id);
// 提取之前所有页已选中的ID数组
const beforeIds = selectedRowBeforeKeys.value.map(item => item.id);
// 找出在新数据中但不在当前页已选中数组中的ID这些是需要添加到之前选中数组中的
const idsToAdd = newIds.filter(id => !currentIds.includes(id));
// 找出在当前页已选中但不在新数据中的ID这些是需要从之前选中数组中移除的
const idsToRemove = currentIds.filter(id => !newIds.includes(id));
// 添加新的ID到之前选中数组中
idsToAdd.forEach(id => {
val.forEach(item =>{
if(item.id == id){
selectedRowBeforeKeys.value.push(item);
}
})
});
// 从之前选中数组中移除不再存在的ID
idsToRemove.forEach(id => {
const index = beforeIds.indexOf(id);
if (index !== -1) {
selectedRowBeforeKeys.value.splice(index, 1);
}
});
multipleSelection.value = selectedRowBeforeKeys.value
selectedRowNowKeys.value = val;
}
2025-05-07 11:00:06 +08:00
}
2025-01-09 18:29:48 +08:00
// if(selectedRowBeforeKeys.value == null || selectedRowBeforeKeys.value.length == 0){
// selectedRowBeforeKeys.value = val
// }else{
// val.forEach(item => {
// const isIdExist = selectedRowKeys.value.some(it => it.id === item.id);
// if (!isIdExist) {
// selectedRowKeys.value.push(item);
// }
// });
// }
// multipleSelection.value = val
}
const selectedRowKeys = ref([]);
const selectedRowBeforeKeys = ref([]);
const selectedRowNowKeys = ref([]);
2025-01-09 18:29:48 +08:00
const clickRow = (row: any) => {
if (chkboxEnable.value) {
if (row) {
multipleTable.value!.toggleRowSelection(row, undefined)
} else {
multipleTable.value!.clearSelection()
}
}
}
//指定key值,数据更新之后保留之前选中的数据
const getRowKeys = (row) => {
return row.id
2025-01-09 18:29:48 +08:00
}
const queryReqVo: any = reactive({
pageNo: 1,
pageSize: 10,
projectSubCode:undefined,
materialName:undefined,
planId:planIdInit.value
})
/** 搜索按钮操作 */
const handleQuery = async () => {
selectedRowNowKeys.value = []
2025-01-09 18:29:48 +08:00
const data = await MaterialPlanBoomApi.getBoomDetailList(queryReqVo)
nowPageIds.value = data.list.map(item => item.id);
storage.value = true;
2025-01-09 18:29:48 +08:00
list.value = data.list
2025-01-09 18:29:48 +08:00
total.value = data.total
nextTick(() => {
multipleSelection.value.forEach((key) => {
const row = list.value.find(item => item.id === key.id);
if (row) {
selectedRowNowKeys.value.push(key)
multipleTable.value!.toggleRowSelection(row, true);
}
});
});
2025-01-09 18:29:48 +08:00
}
/** 重置按钮操作 */
const resetQuery = () => {
queryReqVo.pageNo = 1
queryReqVo.pageSize = 10
queryReqVo.projectSubCode = ''
queryReqVo.materialName = ''
handleQuery()
}
/** 打开弹窗 */
const open = async (planId: number) => {
dialogVisible.value = true
dialogTitle.value = '加工件列表'
planIdInit.value = planId
queryReqVo.planId = planId
formLoading.value = true
const data = await MaterialPlanBoomApi.getBoomDetailList(queryReqVo)
list.value = data.list
total.value = data.total
formLoading.value = false
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const submitForm = async () => {
// 提交请求
formLoading.value = true
try {
dialogVisible.value = false
// 发送操作成功的事件
multipleSelection.value.forEach(item=> item.boomAmount = item.amount)
emit('success', multipleSelection.value)
} finally {
formLoading.value = false
}
}
</script>