Commit 3a01986e authored by 方建宇's avatar 方建宇

物品归还-选择归还物品获取数据

parent 47522ed5
......@@ -122,14 +122,18 @@
<div style="display: flex; justify-content: flex-end;">
<el-input v-model="searchQuery" placeholder="搜索数据" style="margin-bottom: 10px;width: 200px;"></el-input>
</div>
<el-table :data="filteredItems" border style="width: 100%">
<el-table :data="filteredItems" border style="width: 100%" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="applicant" label="申请人" width="150"></el-table-column>
<el-table-column prop="itemName" label="物品名称" width="150"></el-table-column>
<el-table-column prop="itemType" label="物品类型" width="150"></el-table-column>
<el-table-column prop="itemUnit" label="单位" width="150"></el-table-column>
<el-table-column prop="quantity" label="待归还数量" width="150"></el-table-column>
<el-table-column prop="itemUnit" label="单位" width="130"></el-table-column>
<el-table-column prop="applyQuantity" label="待归还数量" width="150"></el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">
<el-button @click="onCloseSelectDialog">取消</el-button>
<el-button type="primary" @click="confirmSelection">确定</el-button>
</div>
</el-dialog>
</div>
</template>
......@@ -156,8 +160,9 @@ export default {
editingId: null, // 用于存储正在编辑的归还ID
showItemSelectDialog: false,
searchQuery: '',
itemsList: [],
itemsList: [], // 存储领用申请数据
selectedRowIndex: -1,
selectedItems: [], // 用于存储选中的数据
rules: {
returnDate: [
{ required: true, message: '请选择归还日期', trigger: 'change' }
......@@ -264,8 +269,62 @@ export default {
},
openItemSelectDialog(index) {
this.selectedRowIndex = index;
// 去掉 fetchItems 调用
// 调用 listApply 接口获取领用申请数据
this.fetchItems();
this.showItemSelectDialog = true;
},
fetchItems() {
listApply().then(response => {
if (response.code === 200) {
// 解析 items 字段
this.itemsList = response.rows.flatMap(row => {
try {
const items = JSON.parse(row.items);
return items.map(item => ({
applicant: row.applicant,
itemName: item.itemName,
itemType: item.itemType,
itemUnit: item.unit,
applyQuantity: item.applyQuantity // 假设 applyRemaining 是待归还数量
}));
} catch (error) {
console.error('解析 items 字段失败:', error);
return [];
}
});
} else {
this.$message.error('获取领用申请数据失败: ' + response.msg);
}
}).catch(error => {
this.$message.error('获取领用申请数据失败: ' + error.message);
});
},
handleSelectionChange(selection) {
this.selectedItems = selection;
},
onCloseSelectDialog() {
this.showItemSelectDialog = false;
},
confirmSelection() {
if (this.selectedItems.length === 0) {
this.$message.warning('请选择要添加的数据');
return;
}
// 将选中的数据填充到主页面的表格中
this.selectedItems.forEach(selectedItem => {
this.form.items[this.selectedRowIndex] = {
item: '',
itemType: selectedItem.itemType,
itemName: selectedItem.itemName,
unit: selectedItem.itemUnit,
pendingReturn: selectedItem.applyQuantity,
returnQuantity: 0,
remainingReturn: selectedItem.applyQuantity
};
});
this.onCloseSelectDialog();
}
},
created() {
......@@ -275,6 +334,9 @@ export default {
this.form = JSON.parse(draft);
this.$message.info('已加载草稿');
}
// 调用 listApply 接口获取领用申请数据
this.fetchItems();
},
watch: {
'form.items': {
......@@ -292,7 +354,7 @@ export default {
item.applicant.includes(this.searchQuery) ||
item.itemName.includes(this.searchQuery) ||
item.itemType.includes(this.searchQuery) ||
item.unit.includes(this.searchQuery)
item.itemUnit.includes(this.searchQuery)
);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment