<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  v-show="showSearch" label-width="68px">
      <el-row :gutter="40">
        <el-col :span="6">
          <el-form-item label="原仓库" prop="fromCangku">
            <el-select v-model="queryParams.fromCangku" placeholder="请选择仓库" clearable >
                <el-option v-for="dict in warehouseList" :key="dict.id" :label="dict.warehouseName" :value="dict.warehouseCode" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="目标仓库" prop="toCangku">
            <el-select v-model="queryParams.toCangku" placeholder="请选择仓库" clearable >
                <el-option v-for="dict in warehouseList" :key="dict.id" :label="dict.warehouseName" :value="dict.warehouseCode" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="项目号" prop="xmNo">
            <el-input
              v-model="queryParams.xmNo"
              placeholder="请输入项目号"
              clearable
              @keyup.enter="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <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-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="recordList" ref="infoTableRef" highlight-current-row @row-click="(row) => tableInfoRowClick(row, infoTableRef)" border show-overflow-tooltip>
      <el-table-column label="物料描述" align="center" prop="wlMs" />
      <el-table-column label="供应商" align="center" prop="gysMc" />
      <el-table-column label="项目编号" align="center" prop="xmNo" />
      <el-table-column label="项目描述" align="center" prop="xmMs" />
      <el-table-column label="移库数量" align="center" prop="realQty" />
      <el-table-column label="原仓库" align="center" prop="fromCangkuName" />
      <el-table-column label="原库位码" align="center" prop="fromPcode" />
      <el-table-column label="原托盘码" align="center" prop="fromTrayCode" />
      <el-table-column label="目标仓库" align="center" prop="toCangkuName" />
      <el-table-column label="目标库位码" align="center" prop="toPcode" />
      <el-table-column label="目标托盘码" align="center" prop="toTrayCode" />
      <el-table-column label="身份码" align="center" prop="entityId" />
      <el-table-column label="移库人" align="center" prop="movedByName" />
      <el-table-column label="移库原因" align="center" prop="moveReason" />
      <el-table-column
        label="操作"
        align="center"
        width="80"
        fixed="right"
      >
        <template #default="scope">
          <el-button link type="primary" @click="delData(scope.row)"
            >撤销</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="Move">
import { listRecord, delMove } from "@/api/wisdom/move";
import {warehouseDict} from "@/api/information/warehouseinfo";    //所属仓库

// 显示搜索条件
const showSearch = ref(true);

// 所属仓库下拉数据
const warehouseList = ref([]);
const warehouseFun = () =>{
  //所属仓库下拉数据
  warehouseDict().then(response=>{
    warehouseList.value = response.data
  })
}
warehouseFun()

/** 查询移库记录列表 */
// 遮罩层
const loading = ref(true);
// 查询参数
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  fromCangku: null,
  toCangku: null,
  xmNo:null
});
// 总条数
const total = ref(0);
// 表格引用
const infoTableRef = ref(null);
// 移库记录表格数据
const recordList = ref([]);
const getList = () => {
  loading.value = true;
  listRecord(queryParams.value).then(response => {
    recordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
getList();

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  proxy.resetForm("queryForm");
  handleQuery();
}

const delData = (row) => {
  proxy.$modal.confirm('确定撤销该条移库记录吗？').then(function() {
    return delMove(row.id);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}
</script>
