<template>
  <!-- 列表 -->
  <div>
    <AutoResizer :given-height="177">
      <template #default="{height}">
        <el-table
          v-loading="loading"
          :data="list"
          :height="height"
          border
        >
          <el-table-column
            label="产品编码"
            align="center"
            prop="productCode"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column
            label="产品名称"
            align="center"
            prop="productName"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column
            label="存货类别"
            align="center"
            prop="categoryName"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column label="累计入库数量" align="center" prop="totalReceiveQty" />
          <el-table-column label="累计销售数量" align="center" prop="totalSaleQty" />
          <el-table-column label="当前库存数量" align="center" prop="totalNowQty" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="160"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                v-hasPermi="['wms:location-adjustment:update']"
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(scope.row)"
              >查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </AutoResizer>

    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 库存明细 -->
    <FinishProductDetail ref="finishProductDetail" />
  </div>

</template>

<script>
import { getMaterialStockPage } from '@/api/wms/inquirePurchase/inventoryInquire'
import FinishProductDetail from './FinishProductDetail.vue'
export default {
  components: {
    FinishProductDetail
  },
  props: {
    'activeName': {
      type: String,
      default: ''
    },
    'queryParamspro': {
      type: Object,
      default: () => {}
    }
  },
  inject: ['paramsQuery'],
  data() {
    return {
      type: '',
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 领料单列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      //   是否显示查看弹出层
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        type: '2'
      },
      //   表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      const params = {
        ...this.paramsQuery,
        ...this.queryParams
      }
      getMaterialStockPage(params).then(response => {
        // this.list = response.data.list
        this.total = response.data.total
        this.type = response.data.type
        if (this.type === '2') {
          this.list = response.data.list
        } else {
          this.list = []
          this.$parent.$parent.$parent.handleQuery()
          this.$parent.$parent.$parent.activeName = 'materialInventory'
        }
      }).finally(() => {
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        wmsIncomingReceiptId: undefined,
        orderType: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined,
        funitId: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    // 库存明细
    handleView(row) {
      const { productCode } = row
      this.$refs.finishProductDetail.queryParams.productCode = productCode
      this.$refs.finishProductDetail.open = true
    }
  }
}
</script>

        <style>

        </style>

