<template>
|
<div class="app-container">
|
<div class="search_form">
|
<div>
|
<span class="search_title ml10">产品大类:</span>
|
<el-tree-select
|
v-model="searchForm.parentId"
|
style="width: 240px"
|
placeholder="请选择"
|
clearable
|
filterable
|
check-strictly
|
:data="displayProductOptions"
|
:render-after-expand="false"
|
@change="handleParentChange"
|
/>
|
<span class="search_title ml10">规格型号:</span>
|
<el-select
|
v-model="searchForm.productModelId"
|
style="width: 240px"
|
placeholder="请选择"
|
clearable
|
filterable
|
@change="handleModelChange"
|
>
|
<el-option v-for="item in modelOptions"
|
:key="item.id"
|
:label="item.model"
|
:value="item.id" />
|
</el-select>
|
<el-button type="primary" @click="handleQuery" style="margin-left: 10px">搜索</el-button>
|
</div>
|
<div>
|
<el-button type="primary" @click="isShowNewModal = true">新增库存</el-button>
|
<el-button type="info" plain icon="Upload" @click="isShowImportModal = true">
|
导入库存
|
</el-button>
|
<el-button @click="handleOut">导出</el-button>
|
</div>
|
</div>
|
<div class="table_list">
|
<el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
|
:expand-row-keys="expandedRowKeys" :row-key="row => row.id" style="width: 100%"
|
:row-class-name="tableRowClassName" height="calc(100vh - 18.5em)">
|
<el-table-column align="center" type="selection" width="55" />
|
<el-table-column align="center" label="序号" type="index" width="60" />
|
<el-table-column label="产品大类" prop="productName" show-overflow-tooltip />
|
<el-table-column label="规格型号" prop="model" show-overflow-tooltip />
|
<el-table-column label="厚度(mm)" prop="thickness" show-overflow-tooltip />
|
<el-table-column label="单位" prop="unit" show-overflow-tooltip />
|
<el-table-column label="合格库存数量" prop="qualifiedQuantity" show-overflow-tooltip>
|
<template #default="scope">{{ getQualifiedStock(scope.row) }}</template>
|
</el-table-column>
|
<el-table-column label="不合格库存数量" prop="unqualifiedQuantity" show-overflow-tooltip>
|
<template #default="scope">{{ getUnqualifiedStock(scope.row) }}</template>
|
</el-table-column>
|
<el-table-column label="合格冻结数量" prop="qualifiedLockedQuantity" show-overflow-tooltip>
|
<template #default="scope">{{ getQualifiedLockedStock(scope.row) }}</template>
|
</el-table-column>
|
<el-table-column label="不合格冻结数量" prop="unqualifiedLockedQuantity" show-overflow-tooltip>
|
<template #default="scope">{{ getUnqualifiedLockedStock(scope.row) }}</template>
|
</el-table-column>
|
<el-table-column label="库存预警数量" prop="warnNum" show-overflow-tooltip />
|
<el-table-column label="备注" prop="remark" show-overflow-tooltip />
|
<el-table-column label="最近更新时间" prop="updateTime" show-overflow-tooltip />
|
<el-table-column fixed="right" label="操作" min-width="90" align="center">
|
<template #default="scope">
|
<el-button link type="primary" @click="showSubtractModal(scope.row)" :disabled="getQualifiedUnLockedStock(scope.row) <= 0">领用</el-button>
|
<el-button link type="primary" v-if="getQualifiedUnLockedStock(scope.row) > 0" @click="showFrozenModal(scope.row)">冻结</el-button>
|
<el-button link type="primary" v-if="getQualifiedLockedStock(scope.row) > 0" @click="showThawModal(scope.row)">解冻</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
|
:page="page.current" :limit="page.size" @pagination="paginationChange" />
|
</div>
|
<new-stock-inventory v-if="isShowNewModal"
|
v-model:visible="isShowNewModal"
|
type="qualified"
|
:parent-id="props.parentId"
|
@completed="handleQuery" />
|
|
<subtract-stock-inventory v-if="isShowSubtractModal"
|
v-model:visible="isShowSubtractModal"
|
:record="record"
|
type="qualified"
|
@completed="handleQuery" />
|
<!-- 导入库存-->
|
<import-stock-inventory v-if="isShowImportModal"
|
v-model:visible="isShowImportModal"
|
type="qualified"
|
@uploadSuccess="handleQuery" />
|
<!-- 冻结/解冻库存-->
|
<frozen-and-thaw-stock-inventory v-if="isShowFrozenAndThawModal"
|
v-model:visible="isShowFrozenAndThawModal"
|
:record="record"
|
:operation-type="operationType"
|
type="qualified"
|
@completed="handleQuery" />
|
</div>
|
</template>
|
|
<script setup>
|
import pagination from '@/components/PIMTable/Pagination.vue'
|
import { ref, reactive, toRefs, onMounted, getCurrentInstance, watch, computed } from 'vue'
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import { getStockInventoryListPage } from "@/api/inventoryManagement/stockInventory.js";
|
import { modelList, productTreeList } from "@/api/basicData/product.js";
|
const NewStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/New.vue"));
|
const SubtractStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/Subtract.vue"));
|
const ImportStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/Import.vue"));
|
const FrozenAndThawStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/FrozenAndThaw.vue"));
|
const props = defineProps({
|
parentId: {
|
type: [Number, String],
|
default: undefined,
|
},
|
})
|
const { proxy } = getCurrentInstance()
|
const tableData = ref([])
|
const productOptions = ref([])
|
const modelOptions = ref([])
|
const selectedRows = ref([])
|
const record = ref({})
|
const tableLoading = ref(false)
|
const page = reactive({
|
current: 1,
|
size: 100,
|
})
|
const total = ref(0)
|
// 是否显示新增弹框
|
const isShowNewModal = ref(false)
|
// 是否显示领用弹框
|
const isShowSubtractModal = ref(false)
|
// 是否显示冻结/解冻弹框
|
const isShowFrozenAndThawModal = ref(false)
|
// 操作类型
|
const operationType = ref('frozen')
|
// 是否显示导入弹框
|
const isShowImportModal = ref(false)
|
const data = reactive({
|
searchForm: {
|
productName: '',
|
parentId: undefined,
|
productModelId: undefined,
|
model: '',
|
}
|
})
|
const { searchForm } = toRefs(data)
|
|
const displayProductOptions = computed(() => {
|
if (!props.parentId) return productOptions.value
|
const currentParentNode = findNodeById(productOptions.value, props.parentId)
|
return Array.isArray(currentParentNode?.children) ? currentParentNode.children : []
|
})
|
|
// 查询列表
|
/** 搜索按钮操作 */
|
const handleQuery = () => {
|
page.current = 1
|
getList()
|
}
|
const paginationChange = (obj) => {
|
page.current = obj.page;
|
page.size = obj.limit;
|
getList()
|
}
|
const getList = () => {
|
tableLoading.value = true
|
const queryParentId = props.parentId || searchForm.value.parentId
|
getStockInventoryListPage({
|
...page,
|
topParentProductId: queryParentId,
|
productName: searchForm.value.productName,
|
model: searchForm.value.model,
|
}).then(res => {
|
tableLoading.value = false
|
tableData.value = res.data.records
|
total.value = res.data.total
|
// 数据加载完成后检查库存
|
// checkStockAndCreatePurchase();
|
}).catch(() => {
|
tableLoading.value = false
|
})
|
}
|
|
const convertIdToValue = (data) => {
|
return (data || []).map((item) => {
|
const children = Array.isArray(item.children) ? item.children : []
|
return {
|
...item,
|
value: item.id,
|
label: item.label || item.productName || '',
|
children: convertIdToValue(children),
|
}
|
})
|
}
|
|
const findNodeById = (nodes, id) => {
|
for (let i = 0; i < nodes.length; i++) {
|
const node = nodes[i]
|
if (node.value === id) return node
|
if (node.children?.length) {
|
const found = findNodeById(node.children, id)
|
if (found) return found
|
}
|
}
|
return null
|
}
|
|
const loadProductOptions = async () => {
|
try {
|
const res = await productTreeList()
|
productOptions.value = convertIdToValue(res || [])
|
} catch (e) {
|
productOptions.value = []
|
}
|
}
|
|
const loadModelOptions = async (parentId) => {
|
if (!parentId) {
|
modelOptions.value = []
|
return
|
}
|
const res = await modelList({ id: parentId })
|
modelOptions.value = Array.isArray(res) ? res : []
|
}
|
|
const handleParentChange = async (value) => {
|
searchForm.value.productModelId = undefined
|
searchForm.value.model = ''
|
const selected = findNodeById(productOptions.value, value)
|
searchForm.value.productName = selected?.label || ''
|
await loadModelOptions(value || props.parentId)
|
}
|
|
const handleModelChange = (value) => {
|
const selected = modelOptions.value.find((item) => item.id === value)
|
searchForm.value.model = selected?.model || ''
|
}
|
|
const handleFileSuccess = (response) => {
|
const { code, msg } = response;
|
if (code == 200) {
|
ElMessage({ message: "导入成功", type: "success" });
|
upload.open = false;
|
emits("uploadSuccess");
|
} else {
|
ElMessage({ message: msg, type: "error" });
|
}
|
};
|
|
// 点击领用
|
const showSubtractModal = (row) => {
|
record.value = row
|
isShowSubtractModal.value = true
|
}
|
|
// 点击冻结
|
const showFrozenModal = (row) => {
|
record.value = row
|
isShowFrozenAndThawModal.value = true
|
operationType.value = 'frozen'
|
}
|
|
// 点击解冻
|
const showThawModal = (row) => {
|
record.value = row
|
isShowFrozenAndThawModal.value = true
|
operationType.value = 'thaw'
|
}
|
|
// 表格选择数据
|
const handleSelectionChange = (selection) => {
|
// 过滤掉子数据
|
selectedRows.value = selection.filter(item => item.id);
|
console.log('selection', selectedRows.value)
|
}
|
const expandedRowKeys = ref([])
|
|
const toNumber = (value) => {
|
const num = Number(value)
|
return Number.isFinite(num) ? num : 0
|
}
|
|
const getQualifiedStock = (row) => {
|
return toNumber(row?.qualifiedQuantity ?? row?.qualitity ?? row?.unLockedQuantity)
|
}
|
|
const getUnqualifiedStock = (row) => {
|
return toNumber(row?.unQualifiedQuantity ?? row?.unqualifiedQuantity ?? row?.unQualifiedUnLockedQuantity ?? row?.unqualifiedUnLockedQuantity)
|
}
|
|
const getQualifiedLockedStock = (row) => {
|
return toNumber(row?.qualifiedLockedQuantity ?? row?.lockedQuantity)
|
}
|
|
const getUnqualifiedLockedStock = (row) => {
|
return toNumber(row?.unQualifiedLockedQuantity ?? row?.unqualifiedLockedQuantity)
|
}
|
|
const getQualifiedUnLockedStock = (row) => {
|
return toNumber(row?.qualifiedUnLockedQuantity ?? row?.unLockedQuantity ?? row?.qualifiedQuantity ?? row?.qualitity)
|
}
|
|
// 表格行类名
|
const tableRowClassName = ({ row }) => {
|
const stock = getQualifiedUnLockedStock(row);
|
const warn = Number(row?.warnNum ?? 0);
|
if (!Number.isFinite(stock) || !Number.isFinite(warn)) {
|
return '';
|
}
|
return stock < warn ? 'row-low-stock' : '';
|
};
|
|
// 导出
|
const handleOut = () => {
|
ElMessageBox.confirm(
|
'是否确认导出?',
|
'导出', {
|
confirmButtonText: '确认',
|
cancelButtonText: '取消',
|
type: 'warning',
|
}
|
).then(() => {
|
proxy.download("/stockInventory/exportStockInventory", {}, '库存信息.xlsx')
|
}).catch(() => {
|
proxy.$modal.msg("已取消")
|
})
|
}
|
|
onMounted(() => {
|
loadProductOptions()
|
getList()
|
})
|
|
watch(
|
() => props.parentId,
|
async () => {
|
searchForm.value.parentId = undefined
|
searchForm.value.productName = ''
|
searchForm.value.productModelId = undefined
|
searchForm.value.model = ''
|
await loadModelOptions(undefined)
|
handleQuery()
|
},
|
{ immediate: true }
|
)
|
</script>
|
|
<style scoped lang="scss">
|
:deep(.row-low-stock td) {
|
background-color: #fde2e2;
|
color: #c45656;
|
}
|
|
:deep(.row-low-stock:hover > td) {
|
background-color: #fcd4d4;
|
}
|
</style>
|