<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="sapNo">
            <el-input v-model="queryParams.sapNo" placeholder="请输入订单编号" clearable @keyup.enter="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="物料号" prop="wlNo">
            <el-input v-model="queryParams.wlNo" placeholder="请输入物料号" clearable @keyup.enter="handleQuery" />
          </el-form-item>
        </el-col>
        <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 label="移库时间" prop="optionTime">
            <el-date-picker v-model="optionTime" type="datetimerange" start-placeholder="开始时间" end-placeholder="结束时间"
              format="YYYY/MM/DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />
          </el-form-item>
        </el-col>
        <el-col :span="6" class="searchBtn">
          <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" type="index" width="70" />
      <el-table-column label="物料号" align="center" prop="wlNo" />
      <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="sapNo" />
      <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" prop="createTime" />
      <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 proxy = getCurrentInstance().proxy;
const optionTime = ref([]);

// 显示搜索条件
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;
  //操作时间
  if (optionTime.value && optionTime.value.length > 0) {
    queryParams.value.startDate = optionTime.value[0]
    queryParams.value.endDate = optionTime.value[1]
  } else {
    queryParams.value.startDate = ""
    queryParams.value.endDate = ""
  }
  getList();
}

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

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