BarcodeManagement.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!--条码管理-->
  2. <template>
  3. <div>
  4. <div class="app-container">
  5. <div>
  6. <transition name="fade">
  7. <div v-show="showSearch" class="mb-[10px]">
  8. <el-row :gutter="10" class="mb8">
  9. <el-col :span="1.5">
  10. <el-button type="primary" icon="Plus">导出</el-button>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </transition>
  15. <el-table
  16. ref="multipleTable"
  17. v-loading="loading"
  18. :data="tableData"
  19. border
  20. :max-height="maxHeight"
  21. style="width: 96%"
  22. @selection-change="handleSelectionChange"
  23. >
  24. <el-table-column type="selection" width="55" align="center" fixed />
  25. <el-table-column label="物资名称" align="center" prop="material_name" fixed show-overflow-tooltip />
  26. <el-table-column label="物资编号" align="center" prop="material_code" show-overflow-tooltip />
  27. <el-table-column label="条形码" align="center" prop="bar_code" show-overflow-tooltip>
  28. <template #default="scope">
  29. <el-button type="text" class="common-btn-text-primary" @click="showQRCode(scope.row.barcode)">查看</el-button>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="二维码" align="center" prop="qr_code" show-overflow-tooltip>
  33. <template #default="scope">
  34. <el-button type="text" class="common-btn-text-primary" @click="showQRCode(scope.row.qr_code)">查看</el-button>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="条码状态" align="center" prop="status" show-overflow-tooltip>
  38. <template #default="scope">
  39. <div>
  40. <span v-if="Number(scope.row.status) === 0">禁用</span>
  41. <span v-if="Number(scope.row.status) === 1">启用</span>
  42. </div>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
  46. <template #default="scope">
  47. <div>
  48. <span v-if="Number(scope.row.status) === 1" class="common-btn-text-primary" @click="toggleStatus(scope.row, 0)">禁用</span>
  49. <span v-if="Number(scope.row.status) === 0" class="common-btn-text-primary" @click="toggleStatus(scope.row, 1)">启用</span>
  50. </div>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. <el-dialog v-model="dialogVisible.visible" title="二维码">
  55. <div class="flex justify-center items-center h-[400px]">
  56. <img :src="baseUrl + downLoadApi + dialogVisible.qr_code" alt="二维码" class="w-[300px] h-[300px]" />
  57. </div>
  58. </el-dialog>
  59. <pagination
  60. v-show="total > 0"
  61. v-model:page="queryParams.page"
  62. v-model:limit="queryParams.pageSize"
  63. :total="total"
  64. @pagination="fetchListData"
  65. />
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script setup lang="ts">
  71. import { ref, reactive, onMounted, onBeforeUnmount } from 'vue';
  72. import { getBarcodeManagementList, changeStatus } from '@/api/comprehensiveGuarantee/materialReserveManagement/BarcodeManagement';
  73. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  74. const baseUrl = import.meta.env.VITE_APP_BASE_API;
  75. const downLoadApi = import.meta.env.VITE_APP_BASE_DOWNLOAD_API;
  76. const showSearch = ref(true);
  77. const multiple = ref(true);
  78. const ids = ref<Array<number | string>>([]);
  79. const single = ref(true);
  80. const tableData = ref();
  81. // 定义响应式变量
  82. const loading = ref(false);
  83. const maxHeight = ref(window.innerHeight * 0.8);
  84. const total = ref();
  85. // 处理窗口大小变化
  86. const handleResize = () => {
  87. maxHeight.value = window.innerHeight * 0.8;
  88. };
  89. const initFormData = reactive({
  90. material_name: '',
  91. material_code: '',
  92. barcode: '',
  93. qr_code: '',
  94. status: ''
  95. });
  96. const data = reactive({
  97. form: { ...initFormData },
  98. queryParams: {
  99. page: '1',
  100. pageSize: '10'
  101. }
  102. });
  103. const { queryParams, form } = toRefs(data);
  104. const dialogVisible = ref({
  105. visible: false,
  106. qr_code: ''
  107. });
  108. const showQRCode = (qr_code) => {
  109. dialogVisible.value = { qr_code };
  110. dialogVisible.value.visible = true;
  111. };
  112. const fetchListData = () => {
  113. loading.value = true;
  114. getBarcodeManagementList(queryParams.value)
  115. .then((res) => {
  116. tableData.value = res.data;
  117. total.value = res.total;
  118. })
  119. .finally(() => {
  120. loading.value = false;
  121. });
  122. };
  123. const handleSelectionChange = (selection) => {
  124. ids.value = selection.map((item) => item.id);
  125. selectedRow.value = selection.length === 1 ? selection[0] : null;
  126. single.value = selection.length != 1;
  127. multiple.value = !selection.length;
  128. };
  129. const toggleStatus = (row, newStatus) => {
  130. const payload = {
  131. id: row.id,
  132. status: String(newStatus)
  133. };
  134. changeStatus(payload).then((response) => {
  135. // 更新成功后重新获取列表数据以刷新页面
  136. fetchListData();
  137. });
  138. };
  139. onMounted(() => {
  140. window.addEventListener('resize', handleResize);
  141. fetchListData();
  142. });
  143. // 在组件卸载前移除窗口大小变化监听器
  144. onBeforeUnmount(() => {
  145. window.removeEventListener('resize', handleResize);
  146. });
  147. </script>
  148. <style lang="scss" scoped></style>