CompareInventory.vue 16.2 KB
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
<template>
  <a-layout>
    <a-layout-header class="header">
      <h1 style="color: white;">库存差异比较系统</h1>
    </a-layout-header>

    <a-layout-content class="content">
      <!-- 数据加载状态 -->
      <a-card title="数据状态" style="margin-bottom: 20px;">
        <a-row :gutter="16">
          <a-col :span="8">
            <a-statistic
              title="WCS系统数据量"
              :value="systemATotal"
              :value-style="{ color: systemALoaded ? '#3f8600' : '#cf1322' }"
            >
              <template #suffix>
                <a-tag :color="systemALoaded ? 'green' : 'red'">
                  {{ systemALoaded ? '已加载' : '加载中' }}
                </a-tag>
              </template>
            </a-statistic>
          </a-col>
          <a-col :span="8">
            <a-statistic
              title="WMS系统数据量"
              :value="systemBTotal"
              :value-style="{ color: systemBLoaded ? '#3f8600' : '#cf1322' }"
            >
              <template #suffix>
                <a-tag :color="systemBLoaded ? 'green' : 'red'">
                  {{ systemBLoaded ? '已加载' : '加载中' }}
                </a-tag>
              </template>
            </a-statistic>
          </a-col>
          <a-col :span="8">
            <a-statistic
              title="数据更新时间"
              :value="dataUpdateTime"
            />
          </a-col>
        </a-row>

        <div style="text-align: center; margin-top: 20px;">
          <a-button
            type="primary"
            @click="loadAllData"
            :loading="loadingData"
            :disabled="loadingData"
          >
            <reload-outlined />
            {{ loadingData ? '数据加载中...' : '重新加载数据' }}
          </a-button>
        </div>
      </a-card>

      <!-- WCS系统数据展示 -->
      <a-card title="WCS系统库存数据" style="margin-bottom: 20px;">
        <a-table
          :scroll="{ x: true,y: 300 }"
          :data-source="systemAData"
          :columns="systemAColumns"
          :pagination="systemAPagination"
          :loading="loadingSystemA"
          size="small"
          @change="handleSystemAPageChange"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'count'">
              <span :style="{ fontWeight: 'bold', color: '#1890ff' }">
                {{ record.count }}
              </span>
            </template>
          </template>
        </a-table>
      </a-card>

      <!-- WMS系统数据展示 -->
      <a-card title="WMS系统库存数据" style="margin-bottom: 20px;">
        <a-table
          :scroll="{ x: true,y: 300 }"
          :dataSource="systemBData"
          :columns="systemBColumns"
          :pagination="systemBPagination"
          :loading="loadingSystemB"
          size="small"
          @change="handleSystemBPageChange"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'qty'">
              <span :style="{ fontWeight: 'bold', color: '#52c41a' }">
                {{ record.qty }}
              </span>
            </template>
          </template>
        </a-table>
      </a-card>

      <!-- 数据比较控制 -->
      <a-card title="数据比较" style="margin-bottom: 20px;">
        <div style="text-align: center;">
          <a-button
            type="primary"
            size="large"
            @click="compareData"
            :disabled="!systemALoaded || !systemBLoaded || comparing"
            :loading="comparing"
          >
            <template #icon><SearchOutlined /></template>
            {{ comparing ? '比较中...' : '开始比较数据' }}
          </a-button>

          <a-button
            v-if="comparing"
            size="large"
            @click="cancelCompare"
            danger
            style="margin-left: 10px;"
          >
            <template #icon><ExclamationCircleOutlined /></template>
            取消比较
          </a-button>
        </div>

        <!-- 比较状态指示器 -->
        <div v-if="comparing" style="text-align: center; margin-top: 10px;">
          <a-spin size="large" />
          <p style="margin-top: 10px; color: #1890ff;">
            数据比较中,请稍候...
          </p>
        </div>
      </a-card>

      <!-- 比较结果区域 -->
      <a-card
        title="差异分析结果"
        v-if="comparisonResult.length && !comparing"
      >
        <!-- 统计概览 -->
        <a-row :gutter="16" style="margin-bottom: 20px;">
          <a-col :span="6">
            <a-statistic title="总记录数" :value="comparisonResult.length" />
          </a-col>
          <a-col :span="6">
            <a-statistic
              title="完全匹配"
              :value="matchCount"
              :value-style="{ color: '#3f8600' }"
            />
          </a-col>
          <a-col :span="6">
            <a-statistic
              title="数量差异"
              :value="quantityDiffCount"
              :value-style="{ color: '#cf1322' }"
            />
          </a-col>
          <a-col :span="6">
            <a-statistic
              title="仅单系统存在"
              :value="singleSystemCount"
              :value-style="{ color: '#faad14' }"
            />
          </a-col>
        </a-row>

        <!-- 差异详情 -->
        <a-table
          :scroll="{ x: true,y: 300 }"
          :columns="detailColumns"
          :data-source="comparisonResult"
          :rowClassName="(record) => getRowClassByStatus(record.status)"
          :pagination="{
            pageSize: 10,
            showSizeChanger: true,
            showQuickJumper: true,
            showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`
          }"
          size="small"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'status'">
              <a-tag :color="getStatusColor(record.status)">
                {{ getStatusText(record.status) }}
              </a-tag>
            </template>

            <template v-if="column.dataIndex === 'systemAQty' && record.status === wcsConstant.QUANTITY_DIFF">
              <span style="color: #cf1322; font-weight: bold;">
                {{ record.systemAQty }}
              </span>
            </template>

            <template v-if="column.dataIndex === 'systemBQty' && record.status === wcsConstant.QUANTITY_DIFF">
              <span style="color: #cf1322; font-weight: bold;">
                {{ record.systemBQty }}
              </span>
            </template>

            <template v-if="column.dataIndex === 'countDiff'">
              <span
                :style="{
                  color: record.countDiff === 0 ? '#3f8600' : '#cf1322',
                  fontWeight: 'bold'
                }"
              >
                {{ record.countDiff > 0 ? '+' : '' }}{{ record.countDiff }}
              </span>
            </template>
          </template>
        </a-table>
      </a-card>
    </a-layout-content>
  </a-layout>
</template>

<script>
import {
  UploadOutlined,
  SearchOutlined,
  ExclamationCircleOutlined,
  ReloadOutlined
} from '@ant-design/icons-vue';
import { message, Modal } from 'ant-design-vue';
import {compare, getInventoryDetailByLocationCode} from "../../../api/api";
import {httpAction} from "../../../api/manage";
import * as wcsConstant from "../../../utils/wcsConstant";

export default {
  name: 'CompareInventory',
  components: {
    UploadOutlined,
    SearchOutlined,
    ExclamationCircleOutlined,
    ReloadOutlined,
  },
  data() {
    return {
      // WCS系统数据相关
      systemAData: [],
      systemATotal: 0,
      systemALoaded: false,
      loadingSystemA: false,
      systemAPagination: {
        current: 1,
        pageSize: 5,
        total: 0,
        showSizeChanger: true,
        pageSizeOptions: ['5','10', '20', '30','100','1000','3250'],
        showQuickJumper: true,
      },

      // WMS系统数据相关
      systemBData: [],
      systemBTotal: 0,
      systemBLoaded: false,
      loadingSystemB: false,
      systemBPagination: {
        current: 1,
        pageSize: 5,
        total: 0,
        showSizeChanger: true,
        pageSizeOptions: ['5','10', '20', '30','100','1000','3250'],
        showQuickJumper: true,
      },

      // 比较结果相关
      comparisonResult: [],
      comparing: false,
      cancelToken: null,

      // 加载状态
      loadingData: false,
      dataUpdateTime: '--',

      // 表格列定义(使用驼峰命名)
      systemAColumns: [
        { title: '库位编码', dataIndex: 'locationNo', key: 'locationNo', width: 150 },
        { title: '物料编码', dataIndex: 'no', key: 'no', width: 120 },
        { title: '物料名称', dataIndex: 'name', key: 'name', width: 150 },
        { title: '数量', dataIndex: 'count', key: 'count', width: 80 },
        { title: '单位', dataIndex: 'unit', key: 'unit', width: 80 },
      ],

      systemBColumns: [
        { title: '库位编码', dataIndex: 'locationCode', key: 'locationCode', width: 150 },
        { title: '物料编码', dataIndex: 'materialCode', key: 'materialCode', width: 120 },
        { title: '物料名称', dataIndex: 'materialName', key: 'materialName', width: 150 },
        { title: '数量', dataIndex: 'qty', key: 'qty', width: 80 },
        { title: '单位', dataIndex: 'materialUnit', key: 'materialUnit', width: 80 },
      ],

      detailColumns: [
        { title: '库位编码', dataIndex: 'locationCode', key: 'locationCode', width: 150 },
        { title: '物料编码', dataIndex: 'materialCode', key: 'materialCode', width: 120 },
        { title: '物料名称', dataIndex: 'materialName', key: 'materialName', width: 150 },
        { title: 'WCS系统数量', dataIndex: 'systemAQty', key: 'systemAQty', width: 100 },
        { title: 'WMS系统数量', dataIndex: 'systemBQty', key: 'systemBQty', width: 100 },
        { title: '数量差异', dataIndex: 'countDiff', key: 'countDiff', width: 100 },
        { title: '状态', dataIndex: 'status', key: 'status', width: 100 },
      ],
    };
  },
  computed: {
    wcsConstant() {
      return wcsConstant
    },
    matchCount() {
      return this.comparisonResult.filter(item => item.status === wcsConstant.MATCH).length;
    },
    quantityDiffCount() {
      return this.comparisonResult.filter(item => item.status === wcsConstant.QUANTITY_DIFF).length;
    },
    singleSystemCount() {
      return this.comparisonResult.filter(item =>
        item.status === wcsConstant.ONLY_IN_A || item.status === wcsConstant.ONLY_IN_B
      ).length;
    },
  },
  mounted() {
    // // 页面加载时自动获取数据
    // this.loadAllData();
  },
  methods: {
    // 加载所有数据
    async loadAllData() {
      this.loadingData = true;
      this.dataUpdateTime = '加载中...';

      try {
        // 并行加载WCS系统和WMS系统的数据
        await Promise.all([
          this.loadSystemAData(1),
          this.loadSystemBData(1)
        ]);

        this.dataUpdateTime = new Date().toLocaleString();
        message.success('数据加载完成');
      } catch (error) {
        message.error('数据加载失败');
        console.error(error);
      } finally {
        this.loadingData = false;
      }
    },

    // 加载WCS系统数据
    async loadSystemAData(page) {
      this.loadingSystemA = true;
      console.log("WCS库存返回开始")
      try {
        const response = await this.$http.get('/config/location/wcsInventory', {
          params: {
            pageNo: page,
            pageSize: this.systemAPagination.pageSize
          }
        });
        console.log("WCS库存返回结果")
        console.log(JSON.stringify(response))

        if (response.success) {
          this.systemAData = response.result;
          this.systemATotal = response.total;
          this.systemALoaded = true;

          // 更新分页信息
          this.systemAPagination.current = page;
          this.systemAPagination.total = response.total;
        } else {
          throw new Error(response.message);
        }
      } catch (error) {
        this.systemALoaded = false;
        console.error('加载WCS系统数据失败:', error);
        message.error('加载WCS系统数据失败');
      } finally {
        this.loadingSystemA = false;
      }
    },

    // 加载WMS系统数据
    async loadSystemBData(page) {
      this.loadingSystemB = true;

      try {
        getInventoryDetailByLocationCode()
        const response = await this.$http.get('/inventory/inventoryDetail/list', {
          params: {
            pageNo: page,
            pageSize: this.systemBPagination.pageSize
          }
        });
        if (response.success) {
          this.systemBData = response.result.records;
          this.systemBTotal = response.result.total;
          this.systemBLoaded = true;

          // 更新分页信息
          this.systemBPagination.current = page;
          this.systemBPagination.total = response.result.total;
        } else {
          throw new Error(response.message);
        }
      } catch (error) {
        this.systemBLoaded = false;
        console.error('加载WMS系统数据失败:', error);
        message.error('加载WMS系统数据失败');
      } finally {
        this.loadingSystemB = false;
      }
    },
    // WCS系统分页变化处理
    handleSystemAPageChange(pagination) {
      this.systemAPagination.pageSize = pagination.pageSize;
      this.loadSystemAData(pagination.current);
    },
    // WMS系统分页变化处理
    handleSystemBPageChange(pagination) {
      this.systemBPagination.pageSize = pagination.pageSize;
      this.loadSystemBData(pagination.current);
    },
    // 比较数据
    compareData() {
      if (this.comparing && this.cancelToken) {
        this.cancelToken.cancel('用户取消了请求');
        return;
      }
      this.comparing = true;
      this.comparisonResult = [];

      httpAction("/config/location/compare", {}, 'POST').then((res) => {
        if (res.success) {
          this.comparisonResult = res.result;
          message.success(`数据比较完成,共发现 ${this.comparisonResult.length} 条记录`);
        } else {
          this.$message.error(res.message);
        }
      }).finally(() => {
        this.comparing = false;
      })
    },
    // 取消比较
    cancelCompare() {
      if (this.comparing && this.cancelToken) {
        this.cancelToken.cancel('用户取消了比较操作');
        message.info('已取消数据比较');
      }
    },

    getRowClassByStatus(status) {
      const statusClassMap = {
        3 : 'status-match',
        0 : 'status-quantity-diff',
        1 : 'status-only-a',
        2 : 'status-only-b'
      };
      return statusClassMap[status] || '';
    },
    // 状态颜色
    getStatusColor(status) {
      const colors = {
        3 : 'green',
        0 : 'red',
        1 : 'orange',
        2 : 'blue',
      };
      return colors[status] || 'default';
    },

    // 状态文本
    getStatusText(status) {
      const texts = {
        3 : '完全匹配',
        0 : '数量差异',
        1 : '仅WCS系统存在',
        2 : '仅WMS系统存在',
      };
      return texts[status] || '未知';
    },
  },
};
</script>

<style scoped>
.header {
  background-color: #001529;
  padding: 0 20px;
}

.content {
  padding: 20px;
  background-color: #f0f2f5;
  min-height: calc(100vh - 64px);
}

.ant-card {
  margin-bottom: 16px;
}

/* 解决scoped样式穿透问题,确保样式能应用到表格行 */
::v-deep .status-match {
  background-color: #f6ffed !important; /* 绿色 - 完全匹配 */
}

::v-deep .status-quantity-diff {
  background-color: #fff1f0 !important; /* 红色 - 数量差异 */
}

::v-deep .status-only-a {
  background-color: #fff7e6 !important; /* 橙色 - 仅WCS系统存在 */
}

::v-deep .status-only-b {
  background-color: #e6f7ff !important; /* 蓝色 - 仅WMS系统存在 */
}

/* 行 hover 效果 */
::v-deep .ant-table-tbody > tr.status-match:hover > td {
  background-color: #eaffdf !important;
}

::v-deep .ant-table-tbody > tr.status-quantity-diff:hover > td {
  background-color: #ffe8e6 !important;
}

::v-deep .ant-table-tbody > tr.status-only-a:hover > td {
  background-color: #fff0cc !important;
}

::v-deep .ant-table-tbody > tr.status-only-b:hover > td {
  background-color: #ccf0ff !important;
}
</style>