| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <template>
- <div>
- <!-- Tab部分 使用 el-radio-group -->
- <el-radio-group v-model="currentTab" style="margin: 5px">
- <el-radio-button
- v-for="tab in tabs"
- :key="tab.dictValue"
- :label="tab.dictValue"
- >
- <template #default>
- <span v-if="tab.dictValue=='0'" class="el-icon-menu"></span>
- <span v-if="tab.dictValue=='1'" class="el-icon-folder-checked"></span>
- <span v-if="tab.dictValue=='2'" class="el-icon-sort"></span>
- <span v-if="tab.dictValue=='3'" class="el-icon-circle-check"></span>
- <span v-if="tab.dictValue=='4'" class="el-icon-question"></span>
- <span v-if="tab.dictValue=='5'" class="el-icon-warning"></span>
- {{ tab.dictLabel }} ({{ tab.sum }})
- </template>
- </el-radio-button>
- </el-radio-group>
- <!-- 表格部分 -->
- <div class="table-container">
- <table v-show="currentTab === '0' || currentTab === '1' || currentTab === '3'">
- <thead>
- <tr>
- <th>物资类型</th>
- <th v-for="cabinet in cabinets" :key="cabinet.cabinetId">{{ cabinet.cabinetName }}</th>
- </tr>
- </thead>
- <tbody>
- <tr v-for="(materialType, index) in materialTypes" :key="index">
- <td width="150">
- <img :src="materialType.materialsTypeIcon" alt="Material Icon" width="50" height="50"/><br>
- {{ materialType.materialsTypeName }}
- </td>
- <td style="font-size: 22px" v-for="cabinet in cabinets" :key="cabinet.cabinetId">
- {{ getCellData(materialType.materialsTypeId, cabinet.cabinetId) }}
- </td>
- </tr>
- </tbody>
- </table>
- <table v-show="currentTab === '2' || currentTab === '4' || currentTab === '5'">
- <thead>
- <tr>
- <th>物资类型</th>
- <th v-for="cabinet in cabinets" :key="cabinet.cabinetId">{{ cabinet.cabinetName }}</th>
- </tr>
- </thead>
- <tbody>
- <tr v-for="(materialType, index) in materialTypes" :key="index">
- <td width="150">
- <img :src="materialType.materialsTypeIcon" alt="Material Icon" width="50" height="50"/><br>
- {{ materialType.materialsTypeName }}
- </td>
- <td style="font-size: 22px" v-for="cabinet in cabinets" :key="cabinet.cabinetId"
- :style="getCellStyle(materialType.materialsTypeId, cabinet.cabinetId)"
- >
- {{ getCellData(materialType.materialsTypeId, cabinet.cabinetId) }}
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </template>
- <script>
- import { getInventorySum, getMaterialInventory } from '@/api/mes/statisticians'
- import { getDicts } from '@/api/system/dict/data'
- export default {
- dicts: ['Inventory_type'],
- data() {
- return {
- currentTab: '0', // 当前选中的Tab
- tabs: [],
- tableData0: [],//各个物资柜数据
- tableData1: [],
- tableData2: [],//各个物资柜数据
- tableData3: [],
- tableData4: [],//各个物资柜数据
- tableData5: []
- }
- },
- watch: {
- currentTab(newVal) {
- getMaterialInventory(this.currentTab).then(response => {
- console.log(response, '物资盘点')
- switch (newVal) {
- case '0':
- this.tableData0 = response.data
- break;
- case '1':
- this.tableData1 = response.data
- break;
- case '2':
- this.tableData2 = response.data
- break;
- case '3':
- this.tableData3 = response.data
- break;
- case '4':
- this.tableData4 = response.data
- break;
- case '5':
- this.tableData5 = response.data
- break;
- }
- })
- }
- },
- computed: {
- cabinets() {
- return this.tableData0||this.tableData1||this.tableData2||this.tableData3||this.tableData4||this.tableData5
- },
- materialTypes() {
- // 假设我们只取第一个物资柜的所有物资类型
- if (this.tableData0.length > 0) {
- return this.tableData0[0].materialsTypeVOList
- }else if (this.tableData1.length > 0) {
- return this.tableData1[0].materialsTypeVOList
- }else if (this.tableData2.length > 0) {
- return this.tableData2[0].materialsTypeVOList
- }else if (this.tableData3.length > 0) {
- return this.tableData3[0].materialsTypeVOList
- }else if (this.tableData4.length > 0) {
- return this.tableData4[0].materialsTypeVOList
- }else if (this.tableData5.length > 0) {
- return this.tableData5[0].materialsTypeVOList
- }
- return []
- }
- },
- mounted() {
- this.getList()
- },
- methods: {
- getList() {
- getMaterialInventory(this.currentTab).then(response => {
- console.log(response, '物资盘点')
- // this.tableData = response.data
- switch (this.currentTab) {
- case '0':
- this.tableData0 = response.data
- break;
- case '1':
- this.tableData1 = response.data
- break;
- case '2':
- this.tableData2 = response.data
- break;
- case '3':
- this.tableData3 = response.data
- break;
- case '4':
- this.tableData4 = response.data
- break;
- case '5':
- this.tableData5 = response.data
- break;
- }
- })
- getInventorySum().then(response => {
- console.log(response, '总数')
- this.tabs = response.data
- })
- },
- getCellData(materialTypeId, cabinetId) {
- let tableData=null
- switch (this.currentTab) {
- case '0':
- tableData = this.tableData0
- break;
- case '1':
- tableData = this.tableData1
- break;
- case '2':
- tableData = this.tableData2
- break;
- case '3':
- tableData = this.tableData3
- break;
- case '4':
- tableData = this.tableData4
- break;
- case '5':
- tableData = this.tableData5
- break;
- }
- const cabinet = tableData.find(c => c.cabinetId === cabinetId)
- if (cabinet) {
- const materialType = cabinet.materialsTypeVOList.find(m => m.materialsTypeId === materialTypeId)
- if (materialType) {
- return materialType.number == null || materialType.number == 0 ? '-' : materialType.number
- }
- }
- return 0
- },
- getCellStyle(materialTypeId, cabinetId) {
- const number = this.getCellData(materialTypeId, cabinetId)
- if (number === null || number === 0) {
- return {}
- }
- if (this.currentTab === '2' && number > 0) {
- return { backgroundColor: 'yellow', color: 'black' }
- }
- if ((this.currentTab === '4' || this.currentTab === '5') && number > 0) {
- return { backgroundColor: 'red', color: 'black' }
- }
- return {}
- }
- }
- }
- </script>
- <style scoped>
- .table-container {
- width: 100%;
- overflow-x: auto;
- }
- table {
- width: 790px;
- border-collapse: collapse;
- table-layout: fixed;
- }
- th, td {
- border: 1px solid #ddd;
- padding: 8px;
- text-align: center;
- }
- th {
- background-color: #f2f2f2;
- }
- </style>
|