# 采购台账库位字段(设备选择)
## 涉及页面
- 采购台账管理页面 (`views/procurementManagement/procurementLedger/index.vue`)
- 采购台账新增/编辑弹窗
- 库存管理页面 (`views/inventoryManagement/stockManagement/index.vue`)
- 入库记录页面 (`views/inventoryManagement/stockManagement/Record.vue`)
## 字段映射关系
| 表/实体 | 字段名 | 说明 |
|---------|--------|------|
| device_ledger | storage_location | 设备的存放位置(库位) |
| sales_ledger_product | storage_location | 采购台账产品明细的库位(来源于设备) |
| sales_ledger_product | device_id | 关联的设备ID |
| stock_in_record | warehouse | 入库记录的库位(来源于storageLocation) |
| stock_inventory | warehouse | 库存的库位(来源于storageLocation) |
**数据流向:**
```
设备台账(storage_location) → 采购产品明细(storage_location) → 入库记录(warehouse) → 库存(warehouse)
```
## API
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | /device/ledger/iotDeviceList | 获取IoT设备列表(is_iot_device=1) |
| POST | /purchase/purchaseLedger/addOrEditPurchase | 新增/编辑采购台账 |
| GET | /purchase/purchaseLedger/getPurchaseById | 查询采购台账详情 |
| GET | /stock/stockInventory/pagestockInventory | 库存分页查询 |
| GET | /stock/stockInventory/pageListCombinedStockInventory | 库存合并查询 |
| GET | /stock/stockInRecord/listPage | 入库记录分页查询 |
**IoT设备列表响应:**
```json
[
{
"id": 1,
"deviceName": "储罐A",
"storageLocation": "仓库1-A区"
}
]
```
**请求参数(产品明细新增字段):**
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| deviceId | Long | 否 | 设备ID(选择IoT设备后自动获取) |
| storageLocation | String | 否 | 库位(选择设备后自动填充设备的storageLocation) |
**响应字段(产品明细回显):**
| 参数 | 类型 | 说明 |
|------|------|------|
| deviceId | Long | 设备ID |
| deviceName | String | 设备名称 |
| storageLocation | String | 库位 |
**响应字段(库存/入库记录回显):**
| 参数 | 类型 | 说明 |
|------|------|------|
| warehouse | String | 库位(来源于采购台账产品明细的storageLocation) |
## 前端修改点
### 1. 采购台账产品表格新增设备选择列
```html
```
### 2. 库存/入库记录表格新增库位列
```html
```
### 3. data 数据
```js
data() {
return {
iotDeviceList: [], // IoT设备列表
productData: [], // 产品明细
}
}
```
### 4. methods 方法
```js
// 获取IoT设备列表
async getIotDeviceList() {
const res = await this.$axios.get('/device/ledger/iotDeviceList');
this.iotDeviceList = res.data;
},
// 设备选择变更时,自动填充库位
handleDeviceChange(row, index) {
const device = this.iotDeviceList.find(d => d.id === row.deviceId);
if (device) {
row.storageLocation = device.storageLocation;
} else {
row.storageLocation = '';
}
},
// 编辑回显时,根据deviceId回显设备名称
// 注意:后端查询已关联返回deviceName,无需额外处理
// 页面加载时获取设备列表
mounted() {
this.getIotDeviceList();
}
```
## 注意事项
- 设备选择接口只返回 `is_iot_device=1` 的设备(物联设备)
- 选择设备后,库位自动从设备的 `storageLocation` 字段获取,无需手动输入
- 编辑采购台账时,后端会自动回显 `deviceId`、`deviceName`、`storageLocation` 字段
- 库位字段仅用于采购台账的原材料产品,销售台账的成品不需要此字段
- 库位信息会在采购入库流程审批通过后自动带入到库存记录的 `warehouse` 字段
- 库存管理页面和入库记录页面的 `warehouse` 字段已自动回显库位信息
- 注意字段命名差异:采购台账用 `storageLocation`,库存用 `warehouse`,实际存储的是同一个库位值