wanshenmean
15 小时以前 f288ccc545f8cc32bc922c96dfb3cab9a1f92ec6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
  <div class="stock-detail-page">
    <el-card shadow="never">
      <template #header>
        <span>库存明细 - {{ route.query.palletCode || '' }}</span>
      </template>
 
      <!-- 搜索 -->
      <el-form :inline="true" :model="queryForm" class="search-form">
        <el-form-item label="物料名称">
          <el-input v-model="queryForm.materielName" placeholder="请输入物料名称" clearable />
        </el-form-item>
        <el-form-item label="电芯码">
          <el-input v-model="queryForm.serialNumber" placeholder="请输入电芯码" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
 
      <!-- 表格 -->
      <el-table v-loading="loading" :data="tableData" border stripe>
        <el-table-column prop="materielCode" label="物料编码" min-width="140" show-overflow-tooltip />
        <el-table-column prop="materielName" label="物料名称" min-width="160" show-overflow-tooltip />
        <el-table-column prop="serialNumber" label="电芯码" min-width="180" show-overflow-tooltip />
        <el-table-column prop="stockQuantity" label="库存数量" min-width="120" align="center" />
        <el-table-column prop="status" label="状态" min-width="120" align="center">
          <template #default="{ row }">
            {{ getStatusText(row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="inboundOrderRowNo" label="通道号" min-width="120" align="center" />
        <el-table-column prop="creater" label="创建人" min-width="100" align="center" />
        <el-table-column prop="createDate" label="创建时间" min-width="160" align="center" />
      </el-table>
 
      <el-pagination
        v-model:current-page="pagination.page"
        v-model:page-size="pagination.pageSize"
        :total="pagination.total"
        :page-sizes="[10, 20, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        style="margin-top: 16px; justify-content: flex-end"
      />
    </el-card>
  </div>
</template>
 
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import { client } from '@/api/client';
 
const route = useRoute();
const loading = ref(false);
const tableData = ref([]);
const stockStatusOptions = ref([]);
 
const queryForm = reactive({
  materielName: '',
  serialNumber: '',
});
 
const pagination = reactive({ page: 1, pageSize: 20, total: 0 });
 
async function loadData() {
  loading.value = true;
  try {
    const stockId = route.query.id;
    const wheres = [{ name: 'stockId', value: String(stockId), displayType: 'int' }];
    if (queryForm.materielName) wheres.push({ name: 'materielName', value: queryForm.materielName, displayType: 'like' });
    if (queryForm.serialNumber) wheres.push({ name: 'serialNumber', value: queryForm.serialNumber, displayType: 'like' });
    const res = await client.post('/api/StockInfoDetail/getPageData', {
      page: pagination.page,
      rows: pagination.pageSize,
      sort: 'id',
      order: 'asc',
      wheres: JSON.stringify(wheres),
    });
    tableData.value = res?.rows || [];
    pagination.total = res?.total || 0;
  } catch {
    ElMessage.error('加载数据失败');
  } finally {
    loading.value = false;
  }
}
 
async function loadDictionary() {
  try {
    const res = await client.post('/api/Sys_Dictionary/GetVueDictionary', ['stockStatusEmun']);
    const ss = res?.find(item => item.dicNo === 'stockStatusEmun');
    stockStatusOptions.value = ss?.data || [];
  } catch {
    stockStatusOptions.value = [];
  }
}
 
function handleSearch() { pagination.page = 1; loadData(); }
function handleReset() {
  queryForm.materielName = '';
  queryForm.serialNumber = '';
  handleSearch();
}
function handleSizeChange() { loadData(); }
function handlePageChange() { loadData(); }
const getStatusText = (val) => stockStatusOptions.value.find(o => `${o.key}` === `${val}`)?.value || val || '-';
 
onMounted(() => { loadDictionary(); loadData(); });
</script>
 
<style scoped>
.stock-detail-page { padding: 16px; }
.search-form { margin-bottom: 12px; }
</style>