CycleCountDetailModal.vue 9.69 KB
<template>
  <j-modal
    :title="title + '选择'"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    :fullscreen="false"
    :width="1500"
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel">
    <a-row :gutter="24">
      <a-col :span="20">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
<!--              <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--                <a-form-item label="库位编码">-->
<!--                  <a-input placeholder="请输入库位编码" v-model="queryParam.locationCode"></a-input>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="容器编码">
                  <a-input placeholder="请输入容器编码" v-model="queryParam.containerCode"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="物料编码">
                  <a-input placeholder="请输入物料编码" v-model="queryParam.materialCode"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="物料名称">
                  <a-input placeholder="请输入物料名称" v-model="queryParam.materialName"></a-input>
                </a-form-item>
              </a-col>

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="条码">
                  <a-input placeholder="请输入条码" v-model="queryParam.barcode"></a-input>
                </a-form-item>
              </a-col>


              <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            :rowKey="rowKey"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :scroll="{ x: 1500, y: 500 }"
            :rowSelection="{selectedRowKeys, onChange: onSelectChange, type: 'checkbox'}"
            class="j-table-force-nowrap"
            @change="handleTableChange"
          >
          <span slot="zoneCode" slot-scope="zoneCode">
            <a-tag :key="zoneCode" color="blue">
              {{ solutionZoneCode(zoneCode) }}
            </a-tag>
          </span>
          </a-table>

        </div>
      </a-col>
<!--      <a-col :span="4">-->
<!--        <a-card :title="'已选' + title" :bordered="false" :body-style="{padding:0}">-->
<!--          <a-table size="middle" bordered :rowKey="rowKey" v-bind="selectedTable" class="j-table-force-nowrap">-->
<!--            <span slot="action" slot-scope="text, record, index">-->
<!--              <a @click="handleDeleteSelected(record, index)">删除</a>-->
<!--            </span>-->
<!--          </a-table>-->
<!--        </a-card>-->
<!--      </a-col>-->
    </a-row>
    <!-- 底部表格 end -->
  </j-modal>
</template>

<script>

import CycleCountDetailForm from './CycleCountDetailForm'
import JSelectBizQueryItem from "@comp/jeecgbiz/JButtonBizComponent/JSelectBizQueryItem";
import {JeecgListMixin} from "@/mixins/JeecgListMixin";
import {getCompanyList, getZoneList, createCycleCountDetailByInventory} from "@api/api";
import {getAction} from "@api/manage";

export default {
  name: 'CycleCountDetailModal',
  mixins: [JeecgListMixin],
  components: {
    JSelectBizQueryItem,
    CycleCountDetailForm
  },
  data() {
    return {
      title: '',
      loading: true,
      visible: false,
      disableSubmit: false,
      cycleCountHeader: {},
      queryParam: {},
      rowKey: 'id',

      selectedRowKeys: [],
      selectedRows: [],
      columns: [
        {
          title: '条码',
          dataIndex: 'barcode',
          align: 'center',
          width: 250,
          fixed: 'left'  // 固定在左侧
        },
        {
          title: '容器编码',
          dataIndex: 'containerCode',
          align: 'center',
          width: 100,

        },
        {
          title: '物料编码',
          dataIndex: 'materialCode',
          align: 'center',
          width: 300,
        },
        {
          title: '物料名称',
          dataIndex: 'materialName',
          align: 'center',
          width: 300,
        },
        {
          title: '物料规格',
          dataIndex: 'materialSpec',
          align: 'center',
          width: 200,
        },
        {
          title: '物料单位',
          dataIndex: 'materialUnit',
          align: 'center',
          width: 80
        },
        {
          title: '数量',
          dataIndex: 'qty',
          align: 'center',
          width: 80
        },
        {
          title: '长度',
          dataIndex: 'length',
          align: 'center',
          width: 80
        },

        {
          title: '生产时间',
          dataIndex: 'prod_time',
          align: 'center',
          width: 200
        },
        {
          title: '入库日期',
          dataIndex: 'receiptDate',
          align: 'center',
          width: 200
        },
        {
          title: '批次',
          dataIndex: 'batch',
          align: 'center',
          width: 120
        } ,
        {
          title: '库位编码',
          dataIndex: 'locationCode',
          align: 'center',
          width: 120
        } ,
        {
          title: '明细ID',
          dataIndex: 'id',
          align: 'center',
          width: 80,
        },
        {
          title: '主表ID',
          dataIndex: 'inventoryHeaderId',
          align: 'center',
          width: 80,
        },
      ],
      dataSource: [],
      url: {
        list: '/inventory/inventoryDetail/freeList',
      },
      zoneList: [],
      companyList: [],
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '50', '100'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
    }
  },
  methods: {
    searchReset() {
      Object.keys(this.queryParam).forEach(key => {
        this.queryParam[key] = ''
      })
      this.selectedRowKeys = []
      this.selectionRows = []  // 使用 selectionRows
      this.ipagination.current = 1  // 重置到第一页
      this.loadData(1)
    },

    handleOk() {
      if (!this.selectionRows || this.selectionRows.length === 0) {
        this.$message.warning("至少选择一项");
        return;
      }

      // 添加去重处理
      const inventoryHeaderIds = [...new Set(
        this.selectionRows
          .map(row => row.inventoryHeaderId)
          .filter(id => id != null && id !== undefined)
      )];

      console.log('去重前:', this.selectionRows.map(row => row.inventoryHeaderId));
      console.log('去重后:', inventoryHeaderIds);

      let params = {
        inventoryHeaderIds: inventoryHeaderIds,
        cycleCountHeaderId: this.cycleCountHeader.id,
        cycleCountHeaderCode: this.cycleCountHeader.code,
      }

      if (inventoryHeaderIds.length > 0) {
        createCycleCountDetailByInventory(params).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.$emit('ok')
          } else {
            this.$message.warning(res.message);
          }
        }).finally(() => {
          this.confirmLoading = false;
          this.close()
        })
      } else {
        this.$message.warning("选中数据无有效的主表ID")
      }
    },
    close() {
      this.searchReset()
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    loadForm() {
      getZoneList().then(res => {
        if (res.success) {
          this.zoneList = res.result
        }
      })
      getCompanyList().then(res => {
        if (res.success) {
          this.companyList = res.result
        }
      })
    },
    solutionZoneCode(value) {
      let actions = []
      Object.keys(this.zoneList).some(key => {
        if (this.zoneList[key].code === '' + value) {
          actions.push(this.zoneList[key].name)
          return true
        }
      })
      return actions.join('')
    },
    solutionCompany(value) {
      let actions = []
      Object.keys(this.companyList).some(key => {
        if (this.companyList[key].code === '' + value) {
          actions.push(this.companyList[key].name)
          return true
        }
      })
      return actions.join('')
    },
    getStatusColor(status) {
      const colors = {
        '良品': 'green',
        '报废品': 'purple',
        '待确认	': 'grey',
        '次品': 'red',
        default: 'blue'
      };
      return colors[status] || colors.default;
    },
  },
  created() {
    this.loadForm();
  }
}
</script>

<style lang="less" scoped>
.ant-table {
  .ant-table-body {
    overflow-x: auto !important;
  }

  .ant-table-header {
    overflow: hidden !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  // 处理长文本
  .ant-table-cell {
    white-space: nowrap;
    &.ellipsis {
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>