feat(组件): 重构产品和原材料选择器为卡片布局
- 将产品和原材料选择器的表格布局替换为卡片布局,提升用户体验 - 添加卡片选中状态样式和交互逻辑 - 优化多选功能,使用复选框代替表格选择列 - 增加空数据提示和加载状态 - 移除未使用的分类数据初始化代码
This commit is contained in:
@@ -15,8 +15,8 @@ export default {
|
|||||||
// 应用启动时全局初始化分类数据
|
// 应用启动时全局初始化分类数据
|
||||||
if (this.$store.getters.token) {
|
if (this.$store.getters.token) {
|
||||||
// this.$store.dispatch('category/getCategoryList');
|
// this.$store.dispatch('category/getCategoryList');
|
||||||
this.$store.dispatch('category/getProductMap');
|
// this.$store.dispatch('category/getProductMap');
|
||||||
this.$store.dispatch('category/getRawMaterialMap');
|
// this.$store.dispatch('category/getRawMaterialMap');
|
||||||
// this.$store.dispatch('category/getBomMap');
|
// this.$store.dispatch('category/getBomMap');
|
||||||
// this.$store.dispatch('finance/getFinancialAccounts');
|
// this.$store.dispatch('finance/getFinancialAccounts');
|
||||||
// this.$store.dispatch('craft/getProcessList');
|
// this.$store.dispatch('craft/getProcessList');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<!-- 搜索区域 -->
|
<!-- 搜索区域(保持不变) -->
|
||||||
<el-form :inline="true" :model="queryParams" class="search-form" size="small">
|
<el-form :inline="true" :model="queryParams" class="search-form" size="small">
|
||||||
<el-form-item label="产品编号">
|
<el-form-item label="产品编号">
|
||||||
<el-input
|
<el-input
|
||||||
@@ -68,37 +68,54 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<!-- 数据表格 -->
|
<!-- 卡片布局(替换原表格) -->
|
||||||
<el-table
|
<div v-loading="loading" class="card-container">
|
||||||
v-loading="loading"
|
<div
|
||||||
:data="productList"
|
v-for="(item, index) in productList"
|
||||||
@row-click="handleRowClick"
|
:key="index + item.productId"
|
||||||
@selection-change="handleSelectionChange"
|
class="product-card"
|
||||||
:select-on-indeterminate="multiple"
|
:class="{ 'selected-card': isSelected(item.productId) }"
|
||||||
highlight-current-row
|
@click="handleRowClick(item)"
|
||||||
height="400px"
|
|
||||||
style="width: 100%"
|
|
||||||
>
|
>
|
||||||
<el-table-column
|
<!-- 多选勾选框 -->
|
||||||
type="selection"
|
<el-checkbox
|
||||||
width="55"
|
|
||||||
align="center"
|
|
||||||
v-if="multiple"
|
v-if="multiple"
|
||||||
|
:checked="isSelected(item.productId)"
|
||||||
|
@change="(val) => handleCardSelection(val, item)"
|
||||||
|
class="card-checkbox"
|
||||||
/>
|
/>
|
||||||
<el-table-column type="index" width="50" align="center" label="序号" />
|
|
||||||
<el-table-column label="产品编号" align="center" prop="productCode" :show-overflow-tooltip="true" />
|
|
||||||
<el-table-column label="产品名称" align="center" prop="productName" :show-overflow-tooltip="true" width="180" />
|
|
||||||
<el-table-column label="负责人" align="center" prop="owner" width="100" />
|
|
||||||
<el-table-column label="规格" align="center" prop="specification" width="120" />
|
|
||||||
<el-table-column label="材质" align="center" prop="material" width="100" />
|
|
||||||
<el-table-column label="操作" align="center" width="100">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button type="text" size="small" @click.stop="handleSelect(scope.row)">选择</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<!-- 分页 -->
|
<!-- 卡片内容(包含所有原表格字段) -->
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="card-title">
|
||||||
|
<span class="name">{{ item.productName }}</span>
|
||||||
|
<span class="code">[{{ item.productCode }}]</span>
|
||||||
|
</div>
|
||||||
|
<div class="card-info">
|
||||||
|
<div class="info-item">负责人:<span>{{ item.owner || '-' }}</span></div>
|
||||||
|
<div class="info-item">规格:<span>{{ item.specification || '-' }}</span></div>
|
||||||
|
<div class="info-item">材质:<span>{{ item.material || '-' }}</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 选择按钮 -->
|
||||||
|
<el-button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
class="select-btn"
|
||||||
|
@click.stop="handleSelect(item)"
|
||||||
|
>
|
||||||
|
选择
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 空数据提示 -->
|
||||||
|
<div class="empty-tip" v-if="productList.length === 0 && !loading">
|
||||||
|
暂无匹配的产品数据
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 分页(保持不变) -->
|
||||||
<pagination
|
<pagination
|
||||||
v-show="total>0"
|
v-show="total>0"
|
||||||
:total="total"
|
:total="total"
|
||||||
@@ -127,22 +144,18 @@ import { listProduct } from '@/api/wms/product';
|
|||||||
export default {
|
export default {
|
||||||
name: 'ProductSelector',
|
name: 'ProductSelector',
|
||||||
props: {
|
props: {
|
||||||
// 双向绑定值
|
|
||||||
value: {
|
value: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
// 是否只读
|
|
||||||
readonly: {
|
readonly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
// 是否允许多选
|
|
||||||
multiple: {
|
multiple: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
// 过滤条件
|
|
||||||
filters: {
|
filters: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({})
|
default: () => ({})
|
||||||
@@ -166,24 +179,21 @@ export default {
|
|||||||
surfaceTreatmentDesc: undefined,
|
surfaceTreatmentDesc: undefined,
|
||||||
zincLayer: undefined
|
zincLayer: undefined
|
||||||
},
|
},
|
||||||
// 内部选中的ID数组
|
|
||||||
selectedIds: [],
|
selectedIds: [],
|
||||||
// 内部选中的行数据
|
|
||||||
selectedRows: []
|
selectedRows: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
// 按钮显示文本
|
|
||||||
buttonText() {
|
buttonText() {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
return this.selectedIds.length > 0
|
return this.selectedIds.length > 0
|
||||||
? `已选 ${this.selectedIds.length} 项`
|
? `已选 ${this.selectedIds.length} 项`
|
||||||
: '选择产品';
|
: '选择产品';
|
||||||
} else {
|
} else {
|
||||||
|
console.log(this.selectedRows);
|
||||||
return this.selectedRows[0]?.productName || '选择产品';
|
return this.selectedRows[0]?.productName || '选择产品';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 只读状态显示文本
|
|
||||||
displayText() {
|
displayText() {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
return this.selectedIds.length > 0
|
return this.selectedIds.length > 0
|
||||||
@@ -195,28 +205,45 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// 监听外部值变化,同步到内部选中状态
|
|
||||||
value: {
|
value: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
handler(val) {
|
handler(val) {
|
||||||
this.selectedIds = val ? val.split(',').filter(id => id) : [];
|
this.selectedIds = val ? val.split(',').filter(id => id) : [];
|
||||||
// 当列表已加载时,同步选中状态
|
// this.syncSelectedRows();
|
||||||
if (this.productList.length > 0) {
|
this.$forceUpdate(); // 新增:强制刷新视图
|
||||||
this.syncTableSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 监听对话框显示状态,加载数据
|
|
||||||
dialogVisible(val) {
|
dialogVisible(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.getList().then(() => {
|
this.getList();
|
||||||
this.syncTableSelection();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 获取产品列表
|
// 判断卡片是否选中
|
||||||
|
isSelected(productId) {
|
||||||
|
return this.selectedIds.includes(productId);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 同步选中行数据
|
||||||
|
// syncSelectedRows() {
|
||||||
|
// if (this.productList.length === 0) return;
|
||||||
|
// // this.selectedRows = this.productList.filter(item =>
|
||||||
|
// // this.selectedIds.includes(item.productId)
|
||||||
|
// // );
|
||||||
|
// },
|
||||||
|
|
||||||
|
// 卡片选择事件(多选)
|
||||||
|
handleCardSelection(checked, item) {
|
||||||
|
if (checked) {
|
||||||
|
!this.selectedIds.includes(item.productId) && this.selectedIds.push(item.productId);
|
||||||
|
} else {
|
||||||
|
this.selectedIds = this.selectedIds.filter(id => id !== item.productId);
|
||||||
|
}
|
||||||
|
// this.syncSelectedRows();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 原有方法保持不变(仅修改同步选中状态逻辑)
|
||||||
async getList() {
|
async getList() {
|
||||||
try {
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
@@ -225,6 +252,7 @@ export default {
|
|||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
this.productList = response.rows || [];
|
this.productList = response.rows || [];
|
||||||
this.total = response.total || 0;
|
this.total = response.total || 0;
|
||||||
|
// this.syncSelectedRows(); // 加载数据后同步选中状态
|
||||||
}
|
}
|
||||||
return this.productList;
|
return this.productList;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -235,15 +263,11 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 搜索
|
|
||||||
handleQuery() {
|
handleQuery() {
|
||||||
this.queryParams.pageNum = 1;
|
this.queryParams.pageNum = 1;
|
||||||
this.getList().then(() => {
|
this.getList();
|
||||||
this.syncTableSelection();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 重置
|
|
||||||
resetQuery() {
|
resetQuery() {
|
||||||
this.queryParams = {
|
this.queryParams = {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -257,12 +281,9 @@ export default {
|
|||||||
surfaceTreatmentDesc: undefined,
|
surfaceTreatmentDesc: undefined,
|
||||||
zincLayer: undefined
|
zincLayer: undefined
|
||||||
};
|
};
|
||||||
this.getList().then(() => {
|
this.getList();
|
||||||
this.syncTableSelection();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 行点击事件
|
|
||||||
handleRowClick(row) {
|
handleRowClick(row) {
|
||||||
if (!this.multiple) {
|
if (!this.multiple) {
|
||||||
this.selectedIds = [row.productId];
|
this.selectedIds = [row.productId];
|
||||||
@@ -271,61 +292,30 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择项变化(多选)
|
|
||||||
handleSelectionChange(rows) {
|
|
||||||
this.selectedRows = rows;
|
|
||||||
this.selectedIds = rows.map(row => row.productId);
|
|
||||||
},
|
|
||||||
|
|
||||||
// 单个选择按钮
|
|
||||||
handleSelect(row) {
|
handleSelect(row) {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
// 多选模式下切换选中状态
|
|
||||||
const index = this.selectedIds.indexOf(row.productId);
|
const index = this.selectedIds.indexOf(row.productId);
|
||||||
if (index > -1) {
|
index > -1
|
||||||
this.selectedIds.splice(index, 1);
|
? (this.selectedIds.splice(index, 1), this.selectedRows.splice(index, 1))
|
||||||
this.selectedRows.splice(index, 1);
|
: (this.selectedIds.push(row.productId), this.selectedRows.push(row));
|
||||||
} else {
|
} else {
|
||||||
this.selectedIds.push(row.productId);
|
|
||||||
this.selectedRows.push(row);
|
|
||||||
}
|
|
||||||
this.syncTableSelection();
|
|
||||||
} else {
|
|
||||||
// 单选模式直接确认
|
|
||||||
this.selectedIds = [row.productId];
|
this.selectedIds = [row.productId];
|
||||||
this.selectedRows = [row];
|
this.selectedRows = [row];
|
||||||
this.confirmSelection();
|
this.confirmSelection();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 同步表格选中状态
|
|
||||||
syncTableSelection() {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
if (this.multiple && this.$refs.table) {
|
|
||||||
this.productList.forEach(row => {
|
|
||||||
const isSelected = this.selectedIds.includes(row.productId);
|
|
||||||
if (isSelected) {
|
|
||||||
this.$refs.table.toggleRowSelection(row, true);
|
|
||||||
} else {
|
|
||||||
this.$refs.table.toggleRowSelection(row, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// 确认选择
|
|
||||||
confirmSelection() {
|
confirmSelection() {
|
||||||
const emitValue = this.selectedIds.join(',');
|
const emitValue = this.selectedIds.join(',');
|
||||||
this.$emit('input', emitValue);
|
this.$emit('input', emitValue);
|
||||||
this.$emit('change', emitValue, this.selectedRows);
|
this.$emit('change', emitValue, this.selectedRows);
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
|
this.$forceUpdate(); // 新增:强制刷新视图
|
||||||
},
|
},
|
||||||
|
|
||||||
// 关闭对话框
|
|
||||||
handleClose() {
|
handleClose() {
|
||||||
// 关闭时重新同步选中状态(避免临时选择影响)
|
|
||||||
this.selectedIds = this.value ? this.value.split(',').filter(id => id) : [];
|
this.selectedIds = this.value ? this.value.split(',').filter(id => id) : [];
|
||||||
|
// this.syncSelectedRows();
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,4 +348,105 @@ export default {
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 卡片容器样式 */
|
||||||
|
.card-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
min-height: 400px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 卡片样式 */
|
||||||
|
.product-card {
|
||||||
|
border: 1px solid #e6e6e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
position: relative;
|
||||||
|
background: #fff;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: #409eff;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 选中卡片样式 */
|
||||||
|
.selected-card {
|
||||||
|
border-color: #409eff;
|
||||||
|
background-color: #f0f7ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 多选勾选框位置 */
|
||||||
|
.card-checkbox {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
right: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 卡片内容样式 */
|
||||||
|
.card-content {
|
||||||
|
margin-right: 24px; /* 给多选框留空间 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #1989fa;
|
||||||
|
margin-right: 8px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-item span {
|
||||||
|
color: #303133;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 选择按钮样式 */
|
||||||
|
.select-btn {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 16px;
|
||||||
|
right: 16px;
|
||||||
|
color: #409eff;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #66b1ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 空数据提示 */
|
||||||
|
.empty-tip {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 400px;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
append-to-body
|
append-to-body
|
||||||
>
|
>
|
||||||
<!-- 搜索区域(同步原料管理页面筛选字段) -->
|
<!-- 搜索区域(保持不变) -->
|
||||||
<el-form :inline="true" :model="queryParams" class="search-form" size="small">
|
<el-form :inline="true" :model="queryParams" class="search-form" size="small">
|
||||||
<el-form-item label="原材料编号">
|
<el-form-item label="原材料编号">
|
||||||
<el-input
|
<el-input
|
||||||
@@ -84,40 +84,57 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<!-- 数据表格(同步原料管理页面核心字段) -->
|
<!-- 卡片布局(替换原表格) -->
|
||||||
<el-table
|
<div v-loading="loading" class="card-container">
|
||||||
ref="table"
|
<div
|
||||||
v-loading="loading"
|
v-for="(item, index) in rawMaterialList"
|
||||||
:data="rawMaterialList"
|
:key="index + item.rawMaterialId"
|
||||||
@row-click="handleRowClick"
|
class="material-card"
|
||||||
@selection-change="handleSelectionChange"
|
:class="{ 'selected-card': isSelected(item.rawMaterialId) }"
|
||||||
:select-on-indeterminate="multiple"
|
@click="handleRowClick(item)"
|
||||||
highlight-current-row
|
|
||||||
height="400px"
|
|
||||||
style="width: 100%"
|
|
||||||
>
|
>
|
||||||
<el-table-column
|
<!-- 多选勾选框 -->
|
||||||
type="selection"
|
<el-checkbox
|
||||||
width="55"
|
|
||||||
align="center"
|
|
||||||
v-if="multiple"
|
v-if="multiple"
|
||||||
|
:checked="isSelected(item.rawMaterialId)"
|
||||||
|
@change="(val) => handleCardSelection(val, item)"
|
||||||
|
class="card-checkbox"
|
||||||
/>
|
/>
|
||||||
<el-table-column label="原材料编号" align="center" prop="rawMaterialCode" :show-overflow-tooltip="true" />
|
|
||||||
<el-table-column label="原材料名称" align="center" prop="rawMaterialName" :show-overflow-tooltip="true" width="180" />
|
|
||||||
<el-table-column label="规格" align="center" prop="specification" width="120" />
|
|
||||||
<el-table-column label="计量单位" align="center" prop="unit" width="100" />
|
|
||||||
<el-table-column label="材质" align="center" prop="material" />
|
|
||||||
<el-table-column label="厂家" align="center" prop="manufacturer" width="120" :show-overflow-tooltip="true" />
|
|
||||||
<el-table-column label="表面处理" align="center" prop="surfaceTreatmentDesc" />
|
|
||||||
<el-table-column label="锌层" align="center" prop="zincLayer" width="80" />
|
|
||||||
<el-table-column label="操作" align="center" width="100">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button type="text" size="small" @click.stop="handleSelect(scope.row)">选择</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<!-- 分页 -->
|
<!-- 卡片内容(包含所有原表格字段) -->
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="card-title">
|
||||||
|
<span class="name">{{ item.rawMaterialName }}</span>
|
||||||
|
<span class="code">[{{ item.rawMaterialCode }}]</span>
|
||||||
|
</div>
|
||||||
|
<div class="card-info">
|
||||||
|
<div class="info-item">规格:<span>{{ item.specification || '-' }}</span></div>
|
||||||
|
<div class="info-item">单位:<span>{{ item.unit || '-' }}</span></div>
|
||||||
|
<div class="info-item">材质:<span>{{ item.material || '-' }}</span></div>
|
||||||
|
<div class="info-item">厂家:<span>{{ item.manufacturer || '-' }}</span></div>
|
||||||
|
<div class="info-item">表面处理:<span>{{ item.surfaceTreatmentDesc || '-' }}</span></div>
|
||||||
|
<div class="info-item">锌层:<span>{{ item.zincLayer || '-' }}</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 选择按钮 -->
|
||||||
|
<el-button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
class="select-btn"
|
||||||
|
@click.stop="handleSelect(item)"
|
||||||
|
>
|
||||||
|
选择
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 空数据提示 -->
|
||||||
|
<div class="empty-tip" v-if="rawMaterialList.length === 0 && !loading">
|
||||||
|
暂无匹配的原材料数据
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 分页(保持不变) -->
|
||||||
<pagination
|
<pagination
|
||||||
v-show="total>0"
|
v-show="total>0"
|
||||||
:total="total"
|
:total="total"
|
||||||
@@ -141,28 +158,23 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 替换为原材料接口
|
|
||||||
import { listRawMaterial } from '@/api/wms/rawMaterial';
|
import { listRawMaterial } from '@/api/wms/rawMaterial';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'RawMaterialSelector',
|
name: 'RawMaterialSelector',
|
||||||
props: {
|
props: {
|
||||||
// 双向绑定值(逗号分隔的rawMaterialId字符串)
|
|
||||||
value: {
|
value: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
// 是否只读
|
|
||||||
readonly: {
|
readonly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
// 是否允许多选
|
|
||||||
multiple: {
|
multiple: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
// 过滤条件(继承原料管理页面筛选逻辑)
|
|
||||||
filters: {
|
filters: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({})
|
default: () => ({})
|
||||||
@@ -172,9 +184,8 @@ export default {
|
|||||||
return {
|
return {
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
rawMaterialList: [], // 原材料列表数据
|
rawMaterialList: [],
|
||||||
total: 0,
|
total: 0,
|
||||||
// 查询参数(同步原料管理页面核心筛选字段)
|
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
@@ -186,14 +197,11 @@ export default {
|
|||||||
surfaceTreatmentDesc: undefined,
|
surfaceTreatmentDesc: undefined,
|
||||||
zincLayer: undefined
|
zincLayer: undefined
|
||||||
},
|
},
|
||||||
// 内部选中的原材料ID数组(关联rawMaterialId)
|
|
||||||
selectedIds: [],
|
selectedIds: [],
|
||||||
// 内部选中的行数据
|
|
||||||
selectedRows: []
|
selectedRows: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
// 按钮显示文本
|
|
||||||
buttonText() {
|
buttonText() {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
return this.selectedIds.length > 0
|
return this.selectedIds.length > 0
|
||||||
@@ -203,7 +211,6 @@ export default {
|
|||||||
return this.selectedRows[0]?.rawMaterialName || '选择原材料';
|
return this.selectedRows[0]?.rawMaterialName || '选择原材料';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 只读状态显示文本
|
|
||||||
displayText() {
|
displayText() {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
return this.selectedIds.length > 0
|
return this.selectedIds.length > 0
|
||||||
@@ -215,28 +222,45 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// 监听外部值变化,同步到内部选中状态
|
|
||||||
value: {
|
value: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
handler(val) {
|
handler(val) {
|
||||||
this.selectedIds = val ? val.split(',').filter(id => id) : [];
|
this.selectedIds = val ? val.split(',').filter(id => id) : [];
|
||||||
// 列表已加载时同步表格选中状态
|
// this.syncSelectedRows();
|
||||||
if (this.rawMaterialList.length > 0) {
|
this.$forceUpdate(); // 新增:强制刷新视图
|
||||||
this.syncTableSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 监听对话框显示,加载原材料列表
|
|
||||||
dialogVisible(val) {
|
dialogVisible(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.getList().then(() => {
|
this.getList();
|
||||||
this.syncTableSelection();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 获取原材料列表(调用原料接口)
|
// 判断卡片是否选中
|
||||||
|
isSelected(rawMaterialId) {
|
||||||
|
return this.selectedIds.includes(rawMaterialId);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 同步选中行数据
|
||||||
|
// syncSelectedRows() {
|
||||||
|
// if (this.rawMaterialList.length === 0) return;
|
||||||
|
// this.selectedRows = this.rawMaterialList.filter(item =>
|
||||||
|
// this.selectedIds.includes(item.rawMaterialId)
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
|
||||||
|
// 卡片选择事件(多选)
|
||||||
|
handleCardSelection(checked, item) {
|
||||||
|
if (checked) {
|
||||||
|
!this.selectedIds.includes(item.rawMaterialId) && this.selectedIds.push(item.rawMaterialId);
|
||||||
|
} else {
|
||||||
|
this.selectedIds = this.selectedIds.filter(id => id !== item.rawMaterialId);
|
||||||
|
}
|
||||||
|
// this.syncSelectedRows();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 原有方法保持不变(仅修改同步选中状态逻辑)
|
||||||
async getList() {
|
async getList() {
|
||||||
try {
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
@@ -245,6 +269,7 @@ export default {
|
|||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
this.rawMaterialList = response.rows || [];
|
this.rawMaterialList = response.rows || [];
|
||||||
this.total = response.total || 0;
|
this.total = response.total || 0;
|
||||||
|
// this.syncSelectedRows(); // 加载数据后同步选中状态
|
||||||
}
|
}
|
||||||
return this.rawMaterialList;
|
return this.rawMaterialList;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -255,15 +280,11 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 搜索(逻辑不变,同步筛选参数)
|
|
||||||
handleQuery() {
|
handleQuery() {
|
||||||
this.queryParams.pageNum = 1;
|
this.queryParams.pageNum = 1;
|
||||||
this.getList().then(() => {
|
this.getList();
|
||||||
this.syncTableSelection();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 重置(重置为原材料查询参数)
|
|
||||||
resetQuery() {
|
resetQuery() {
|
||||||
this.queryParams = {
|
this.queryParams = {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -276,12 +297,9 @@ export default {
|
|||||||
surfaceTreatmentDesc: undefined,
|
surfaceTreatmentDesc: undefined,
|
||||||
zincLayer: undefined
|
zincLayer: undefined
|
||||||
};
|
};
|
||||||
this.getList().then(() => {
|
this.getList();
|
||||||
this.syncTableSelection();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 行点击事件(单选直接确认)
|
|
||||||
handleRowClick(row) {
|
handleRowClick(row) {
|
||||||
if (!this.multiple) {
|
if (!this.multiple) {
|
||||||
this.selectedIds = [row.rawMaterialId];
|
this.selectedIds = [row.rawMaterialId];
|
||||||
@@ -290,20 +308,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择项变化(多选)
|
|
||||||
handleSelectionChange(rows) {
|
|
||||||
this.selectedRows = rows;
|
|
||||||
this.selectedIds = rows.map(row => row.rawMaterialId);
|
|
||||||
},
|
|
||||||
|
|
||||||
// 单个选择按钮(多选切换选中状态,单选直接确认)
|
|
||||||
handleSelect(row) {
|
handleSelect(row) {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
const index = this.selectedIds.indexOf(row.rawMaterialId);
|
const index = this.selectedIds.indexOf(row.rawMaterialId);
|
||||||
index > -1
|
index > -1
|
||||||
? (this.selectedIds.splice(index, 1), this.selectedRows.splice(index, 1))
|
? (this.selectedIds.splice(index, 1), this.selectedRows.splice(index, 1))
|
||||||
: (this.selectedIds.push(row.rawMaterialId), this.selectedRows.push(row));
|
: (this.selectedIds.push(row.rawMaterialId), this.selectedRows.push(row));
|
||||||
this.syncTableSelection();
|
|
||||||
} else {
|
} else {
|
||||||
this.selectedIds = [row.rawMaterialId];
|
this.selectedIds = [row.rawMaterialId];
|
||||||
this.selectedRows = [row];
|
this.selectedRows = [row];
|
||||||
@@ -311,29 +321,17 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 同步表格选中状态
|
|
||||||
syncTableSelection() {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
if (this.multiple && this.$refs.table) {
|
|
||||||
this.rawMaterialList.forEach(row => {
|
|
||||||
const isSelected = this.selectedIds.includes(row.rawMaterialId);
|
|
||||||
this.$refs.table.toggleRowSelection(row, isSelected);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// 确认选择(触发v-model更新和change事件)
|
|
||||||
confirmSelection() {
|
confirmSelection() {
|
||||||
const emitValue = this.selectedIds.join(',');
|
const emitValue = this.selectedIds.join(',');
|
||||||
this.$emit('input', emitValue);
|
this.$emit('input', emitValue);
|
||||||
this.$emit('change', emitValue, this.selectedRows);
|
this.$emit('change', emitValue, this.selectedRows);
|
||||||
|
this.$forceUpdate(); // 新增:强制刷新视图
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 关闭对话框(恢复原始选中状态)
|
|
||||||
handleClose() {
|
handleClose() {
|
||||||
this.selectedIds = this.value ? this.value.split(',').filter(id => id) : [];
|
this.selectedIds = this.value ? this.value.split(',').filter(id => id) : [];
|
||||||
|
// this.syncSelectedRows();
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,7 +345,7 @@ export default {
|
|||||||
|
|
||||||
.search-form {
|
.search-form {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
flex-wrap: wrap; // 适配多筛选字段换行
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.readonly-text {
|
.readonly-text {
|
||||||
@@ -359,11 +357,117 @@ export default {
|
|||||||
|
|
||||||
::v-deep .el-dialog__body {
|
::v-deep .el-dialog__body {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
overflow-x: auto; // 适配宽表格横向滚动
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
::v-deep .el-form-item {
|
::v-deep .el-form-item {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 卡片容器样式 */
|
||||||
|
.card-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
min-height: 400px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 卡片样式 */
|
||||||
|
.material-card {
|
||||||
|
border: 1px solid #e6e6e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
position: relative;
|
||||||
|
background: #fff;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: #409eff;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 选中卡片样式 */
|
||||||
|
.selected-card {
|
||||||
|
border-color: #409eff;
|
||||||
|
background-color: #f0f7ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 多选勾选框位置 */
|
||||||
|
.card-checkbox {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
right: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 卡片内容样式 */
|
||||||
|
.card-content {
|
||||||
|
margin-right: 24px; /* 给多选框留空间 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #1989fa;
|
||||||
|
margin-right: 8px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-info {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-item {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-item span {
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 选择按钮样式 */
|
||||||
|
.select-btn {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 16px;
|
||||||
|
right: 16px;
|
||||||
|
color: #409eff;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #66b1ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 空数据提示 */
|
||||||
|
.empty-tip {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 400px;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -145,8 +145,8 @@ export default {
|
|||||||
}
|
}
|
||||||
this.$store.dispatch("Login", this.loginForm).then(() => {
|
this.$store.dispatch("Login", this.loginForm).then(() => {
|
||||||
// this.$store.dispatch('category/getCategoryList');
|
// this.$store.dispatch('category/getCategoryList');
|
||||||
this.$store.dispatch('category/getProductMap');
|
// this.$store.dispatch('category/getProductMap');
|
||||||
this.$store.dispatch('category/getRawMaterialMap');
|
// this.$store.dispatch('category/getRawMaterialMap');
|
||||||
// this.$store.dispatch('category/getBomMap');
|
// this.$store.dispatch('category/getBomMap');
|
||||||
// this.$store.dispatch('finance/getFinancialAccounts');
|
// this.$store.dispatch('finance/getFinancialAccounts');
|
||||||
// this.$store.dispatch('craft/getProcessList');
|
// this.$store.dispatch('craft/getProcessList');
|
||||||
|
|||||||
Reference in New Issue
Block a user