<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="项目名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入项目名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库类型" prop="purposeTypeEnum">
        <el-select
          v-model="queryParams.purposeTypeEnum"
          placeholder="请选择"
          clearable
          filterable
          style="width: 200px"
          @change="handleChangePurposeTypeEnum"
        >
          <el-option
            v-for="item in warehous_type"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="盘点仓库" prop="purposeLocationId">
        <el-select
          v-model="queryParams.purposeLocationId"
          placeholder="请选择"
          clearable
          filterable
          style="width: 200px"
          @change="handleCabinetChange(receiptHeaderForm.purposeLocationId)"
        >
          <el-option
            v-for="item in [
              { id: 1, name: '仓库1' },
              { id: 2, name: '仓库2' },
            ]"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="货位" prop="purposeLocation">
        <el-select
          v-model="queryParams.purposeLocation"
          placeholder="请选择"
          clearable
          filterable
          style="width: 200px"
        >
          <el-option
            v-for="item in [
              { id: 1, name: '货位1' },
              { id: 2, name: '货位2' },
            ]"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
      height="calc(100vh - 250px)"
    >
      <el-table-column
        label="项目"
        align="center"
        key="name"
        prop="name"
        width="200"
        fixed
      ></el-table-column>
      <el-table-column label="规格" align="center" prop="totalVolume" />
      <el-table-column label="厂家/产地" align="center" prop="manufacturer" show-overflow-tooltip />
      <el-table-column label="产品批号" align="center" prop="lotNumber" />
      <el-table-column label="单价" align="center" key="unit" prop="unitPrice" />
      <el-table-column label="发放数量" align="center" prop="dispenseQuantity" />
      <el-table-column label="库存数量" align="center" prop="quantity" />
      <el-table-column label="盈亏数量" align="center" prop="itemQuantity">
        <template #default="scope">
          <el-input v-model="scope.row.itemQuantity" :input-style="{ textAlign: 'center' }" type="number" />
        </template>
      </el-table-column>
      <el-table-column label="单位" align="center" prop="unitCode_dictText" />
      <el-table-column label="最小单位" align="center" prop="minUnitCode_dictText" />
      <el-table-column label="拆零比" align="center" prop="partPercent" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="Check"
            @click="handleSave(scope.row)"
            v-hasPermi="['chkstock:partDeptDevice:edit']"
            >保存
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script setup>
import { ref, reactive, toRaw, computed, watch, onMounted } from 'vue';
const { proxy } = getCurrentInstance();
import { getStockTakeList } from './components/api.js';
const { warehous_type } = proxy.useDict('warehous_type');
const dataList = ref([]);
const queryParams = reactive({
  // pageNo: 1,
  // pageSize: 10,
});
const loading = ref(false);
const showSearch = ref(true);
const total = ref(0);
// 获取列表
const getList = () => {
  loading.value = true;
  getStockTakeList(queryParams.value).then((res) => {
    loading.value = false;
    dataList.value = res.data;
    total.value = res.data.length;
  });
};
// 搜索
const handleQuery = () => {
  getList();
};
// 重置
const resetQuery = () => {
  queryParams.value = {};
  handleQuery();
};
// 重置
const reset = () => {};

// 多选
const handleSelectionChange = (selection) => {};
// 保存
const handleSave = (row) => {
  console.log(row);
  // 校验盈亏数量
  if (row.itemQuantity == '' || row.itemQuantity == null) {
    proxy.$modal.msgWarning('盈亏数量不能为空');
    return;
  }
  proxy.$modal
    .confirm('确定保存吗？', '保存', {
      confirmButtonText: '保存',
      cancelButtonText: '取消',
      type: 'warning',
    })
    .then(() => {
      proxy.$modal.msgSuccess('保存成功');
      getList();
    })
    .catch(() => {});
};
const handleChangePurposeTypeEnum = (val) => {};
const handleCabinetChange = (val) => {};
onMounted(() => {
  getList();
});
</script>
