addDetailDialog.vue 9.22 KB
<template>
  <el-dialog
    title="添加盘点明细"
    :visible.sync="visible"
    :showinventory="showinventory"
    width="1000px"
    append-to-body
    @close="$emit('update:showinventory', false)"
  >
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="仓库" prop="warehouseCode">
        <el-select
          v-model="queryParams.warehouseCode"
          placeholder="仓库"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in warehouseOptions"
            :key="item.id"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="货主" prop="companyCode">
        <el-select
          v-model="queryParams.companyCode"
          placeholder="货主"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in companyOptions"
            :key="item.id"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="库位编码" prop="locationCode">
        <el-input
          v-model="queryParams.locationCode"
          placeholder="请输入库位编码"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="容器编码" prop="containerCode">
        <el-input
          v-model="queryParams.containerCode"
          placeholder="请输入容器编码"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit-outline"
          size="mini"
          @click="handleSelect"
          >选取添加</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :col-data="colData"
        @selectData="selectData"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="inventoryList"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column
        label="库存明细id"
        align="center"
        prop="id"
        width="120"
        sortable
        v-if="colData[0].istrue"
      />
      <el-table-column
        label="仓库"
        align="center"
        prop="warehouseCode"
        width="150"
        :show-overflow-tooltip="true"
        v-if="colData[1].istrue"
      >
        <template slot-scope="scope">
          {{ warehouseCodeFormat(scope.row, scope.column) }}
        </template>
      </el-table-column>
      <el-table-column
        label="货主"
        align="center"
        prop="companyCode"
        width="200"
        :show-overflow-tooltip="true"
        v-if="colData[2].istrue"
      >
        <template slot-scope="scope">
          {{ companyCodeFormat(scope.row, scope.column) }}
        </template>
      </el-table-column>
      <el-table-column
        label="库位编码"
        align="center"
        prop="locationCode"
        width="150"
        v-if="colData[3].istrue"
      />
      <el-table-column
        label="容器编码"
        align="center"
        prop="containerCode"
        width="150"
        v-if="colData[4].istrue"
      />

      <el-table-column
        label="总重量"
        align="center"
        prop="totalWeight"
        width="100"
        v-if="colData[5].istrue"
      />
      <el-table-column
        label="总数"
        align="center"
        prop="totalQty"
        width="80"
        v-if="colData[6].istrue"
      />
      <el-table-column
        label="锁定"
        align="center"
        prop="locking"
        width="55"
        v-if="colData[7].istrue"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="created"
        width="160"
        v-if="colData[8].istrue"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.created) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="创建用户"
        align="center"
        prop="createdBy"
        :show-overflow-tooltip="true"
        min-width="150"
        v-if="colData[9].istrue"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { CycleCountLookinventoryDetail } from "@/api/inventory/inventoryHeader/detail";
import { getWarehouseByUserCode } from "@/api/system/warehouse";
import { getCompaniesByToken } from "@/api/system/company";
import { addCycleCountDetail } from "@/api/cycle/cycleCountHeader/detail";
export default {
  props: {
    showinventory: {
      type: Boolean,
      default: false,
    },
    cycleCountHeadCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      visible: this.showinventory,
      loading: true,
      showSearch: true,
      total: 0,
      cycleCount: this.cycleCountHeadCode,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        warehouseCode: undefined,
        companyCode: undefined,
        locationCode: undefined,
        containerCode: undefined,
      },

      warehouseOptions: [],
      inventoryList: [],
      dateRange: [],
      companyOptions: [],
      // istrue属性存放列的状态
      colData: [
        { title: "库存明细id", istrue: true },
        { title: "仓库", istrue: true },
        { title: "货主", istrue: true },
        { title: "库位编码", istrue: true },
        { title: "容器编码", istrue: true },
        { title: "总重量", istrue: true },
        { title: "总数", istrue: true },
        { title: "锁定", istrue: true },
        { title: "创建时间", istrue: true },
        { title: "创建用户", istrue: true, disabled: true },
      ],
    };
  },
  watch: {
    showinventory() {
      this.visible = this.showinventory;
    },
     cycleCountHeadCode(newValue) {
      this.cycleCount = newValue;
    },
  },
  created() {
    
    this.getList();
   

    getWarehouseByUserCode(this.$store.getters.name).then((response) => {
      this.warehouseOptions = response.data;
    });
    //货主select下拉接口获取
    getCompaniesByToken().then((response) => {
      this.companyOptions = response;
    });
  },
     beforeUpdate() {
       if(this.showinventory) {
    this.$nextTick(() => {
      this.$refs["table"].doLayout();
    });
       }
  },
  methods: {
    getList() {
      this.loading = true;
      CycleCountLookinventoryDetail(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        this.inventoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 仓库字典翻译
    warehouseCodeFormat(row, column) {
      return this.selectCommonLabel(this.warehouseOptions, row.warehouseCode);
    },
    // 货主字典翻译
    companyCodeFormat(row, column) {
      return this.selectCommonLabel(this.companyOptions, row.companyCode);
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.inventoryDetailds = selection.map(item => item.id);
    },
    handleSelect() {
      let addParams = {
        cycleCountHeadCode: this.cycleCount,
        inventoryDetailds: this.inventoryDetailds.toString(),
      };
     
      this.visible = false;
      addCycleCountDetail(addParams).then((response) => {
        if (response.code == 200) {
          this.$parent.getDetailList();
          this.msgSuccess(response.msg);
        } else {
          this.msgError(response.msg);
        }
      });
    },
    /** 表格列显示隐藏切换操作 */
    selectData(val) {
      if (val) {
        this.colData.filter((i) => {
          if (val.indexOf(i.title) !== -1) {
            i.istrue = true;
          } else {
            i.istrue = false;
          }
        });
      }
    },
  },
};
</script>