CycleCountDetailModal.vue 12.2 KB
<template>
  <j-modal
    :title="title + '选择'"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel">
    <a-row :gutter="18">
      <a-col :span="16">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" class="j-inline-form" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
                            <a-form-item label="库区">
                              <a-select
                                show-search
                                placeholder="请选择库区"
                                option-filter-prop="children"
                                v-model="queryParam.zoneCode"
                              >
                                <a-select-option v-for="item in zoneList" :key="item.name" :value="item.code">
                                  {{ item.name }}
                                </a-select-option>
                              </a-select>
                            </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.code"></a-input>
                </a-form-item>
              </a-col>
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </a-row>
          </a-form>
        </div>
        <a-table
          size="middle"
          bordered
          :rowKey="rowKey"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :scroll="{ y: 240 }"
          :customRow="customRowFn"
          :rowSelection="{selectedRowKeys, onChange: onSelectChange, type: 'checkbox'}"
          @change="handleTableChange">
          <span slot="zoneCode" slot-scope="zoneCode">
          <a-tag :key="zoneCode" color="blue">
            {{ solutionZoneCode(zoneCode) }}
          </a-tag>
        </span>
        </a-table>
      </a-col>
      <a-col :span="8">
        <a-card :title="'已选' + title" :bordered="false" :head-style="{padding:0}" :body-style="{padding:0}">
          <a-table size="middle" :rowKey="rowKey" bordered v-bind="selectedTable">
              <span slot="action" slot-scope="text, record, index">
                <a @click="handleDeleteSelected(record, index)">删除</a>
              </span>
          </a-table>
        </a-card>
      </a-col>
    </a-row>
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:true}"
        :columns="detailColumns"
        :dataSource="detailDataSource"
        :pagination="detailIpagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="companyCode" slot-scope="companyCode">
          <a-tag :key="companyCode" color=blue>
            {{ solutionCompany(companyCode) }}
          </a-tag>
        </span>
        <span slot="inventoryStatus_dictText" slot-scope="inventoryStatus_dictText">
          <a-tag :key="inventoryStatus_dictText" :color="getStatusColor(inventoryStatus_dictText)">
            {{ inventoryStatus_dictText }}
          </a-tag>
        </span>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
  </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: [],
      selectedRowIds: [],
      columns: [
        {title: 'ID', align: 'center', width: '20%', widthRight: '70%', dataIndex: 'id'},
        {title: '容器编码', align: 'center', width: '25%', dataIndex: 'containerCode'},
        {title: '容器状态', align: 'center', width: '20%', dataIndex: 'containerStatus_dictText'},
        {title: '库位编码', align: 'center', width: '20%', dataIndex: 'locationCode'},
        {title: '总数量', align: 'center', width: '20%', dataIndex: 'totalQty'},
        {title: '库区', align: 'center', width: '20%', widthRight: '70%', dataIndex: 'zoneCode', scopedSlots: {customRender: 'zoneCode'}},
        {title: '状态', align: 'center', width: '20%', dataIndex: 'enable_dictText'},
      ],
      detailColumns: [
        {title: '货主', align: "center", dataIndex: 'companyCode', scopedSlots: {customRender: 'companyCode'}},
        {title: '容器编码', align: "center", dataIndex: 'containerCode'},
        {title: '库位编码', align: "center", dataIndex: 'locationCode'},
        {title: '物料编码', align: "center", dataIndex: 'materialCode'},
        {title: '物料名称', align: "center", dataIndex: 'materialName'},
        {title: '物料规格', align: "center", dataIndex: 'materialSpec'},
        {title: '物料单位', align: "center", dataIndex: 'materialUnit'},
        {title: '数量', align: "center", dataIndex: 'qty'},
        {title: '库存状态', align: "center", dataIndex: 'inventoryStatus_dictText', scopedSlots: {customRender: 'inventoryStatus_dictText'}},
        {title: '批次', align: "center", dataIndex: 'batch'},
        {title: '入库日期', align: "center", dataIndex: 'receiptDate'}
      ],
      selectedTable: {
        pagination: false,
        scroll: {y: 240},
        columns: [
          {title: '库位编码', align: 'center', width: '70%', dataIndex: 'locationCode'},
          {title: '操作', dataIndex: 'action', align: 'center', width: 60, scopedSlots: {customRender: 'action'},}
        ],
        dataSource: [],
      },
      dataSource: [],
      detailDataSource: [],
      url: {
        list: '/inventory/inventoryHeader/freeList',
        pageByMainIds: "/inventory/inventoryDetail/pageByMainIds"
      },
      zoneList: [],
      companyList: [],
      ipagination: {
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5', '10', '15'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      detailIpagination:{
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5', '10', '15'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      }
    }
  },
  methods: {
    handleOk() {
      let params = {
        inventoryHeaderIds: this.selectedRowIds,
        cycleCountHeaderId: this.cycleCountHeader.id,
        cycleCountHeaderCode: this.cycleCountHeader.code,
      }
      if (this.selectedRowIds.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("至少选择一项")
      }
    },
    customRowFn(record, index) {
      return {
        on: {
          click: () => {
            let rowKey = record[this.rowKey];
            if (this.selectedRowKeys.includes(rowKey)) {
              this.selectedRowKeys = this.selectedRowKeys.filter(key => key !== rowKey);
              this.selectedTable.dataSource = this.selectedTable.dataSource.filter(data => data[this.rowKey] !== rowKey);
              this.selectedRowIds = this.selectedRowIds.filter(id => id !== record.id)
            } else {
              this.selectedRowKeys.push(rowKey);
              this.selectedTable.dataSource.push(record)
              this.selectedRowIds.push(record.id)
            }
            this.onSelectChange(this.selectedRowKeys, record);
            this.getDetailDataSource()
          }
        }
      }
    },
    handleDeleteSelected(record, index) {
      let rowKey = record[this.rowKey];
      this.selectedTable.dataSource = this.selectedTable.dataSource.filter(data => data[this.rowKey] !== rowKey);
      this.selectedRowKeys = this.selectedRowKeys.filter(key => key !== rowKey);
      this.selectedRowIds = this.selectedRowIds.filter(id => id !== record.id)
      this.onSelectChange(this.selectedRowKeys, record);
      this.getDetailDataSource();
    },
    getDetailDataSource(){
      this.loading = true;
      let params = {
        inventoryHeaderIds: this.selectedRowIds.join(","),
        pageNo: this.detailIpagination.current,
        pageSize: this.detailIpagination.pageSize
      }
      getAction(this.url.pageByMainIds, params).then((res) => {
        if (res.success) {
          this.detailDataSource = res.result ? res.result.records : null;
          if (res.result && res.result.total) {
            this.detailIpagination.total = res.result.total;
          } else {
            this.detailIpagination.total = 0;
          }
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    close() {
      this.visible = false;
      this.selectedRowIds = [];
      this.selectionRows = [];
      this.selectedRowKeys = [];
      this.detailDataSource = [];
      this.selectedTable.dataSource = [];
    },
    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>
</style>