<template>
  <div class="page-container column-container">
    <!-- 搜索区 -->
    <el-form
      class="list-search-container"
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      style="margin-right: 0px"
    >
      <el-form-item label="批次号：" prop="lotCode">
        <el-input
          v-model="queryParams.lotCode"
          placeholder="请输入批次号"
          style="width: 144px"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品描述：" prop="productDescription">
        <el-input
          v-model="queryParams.productDescription"
          placeholder="请输入产品描述"
          style="width: 144px"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生成日期：" prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          type="date"
          style="width: 144px"
          value-format="YYYY-MM-DD"
          placeholder="选择起始日期"
          clearable
        />
        <span style="margin: 0 4px">~</span>
        <el-date-picker
          v-model="queryParams.endTime"
          type="date"
          style="width: 144px"
          value-format="YYYY-MM-DD"
          placeholder="选择结束日期"
          clearable
        />
      </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>
    <!-- 功能按钮区 -->
    <div class="list-btns-container">
      <el-button
        type="primary"
        icon="Plus"
        v-hasPermi="['business:noCurrentReject:save']"
        @click="handleLogDialog"
      >
        新增
      </el-button>
      <el-button
        type="danger"
        icon="Delete"
        v-hasPermi="['business:noCurrentReject:remove']"
        :disabled="ids.length === 0"
        @click="handleDelete"
      >
        删除
      </el-button>
    </div>
    <!-- 渲染数据区 -->
    <div class="el-table-container">
      <div class="el-table-inner-container">
        <el-table
          v-loading="loading"
          :data="dataList"
          size="small"
          @selection-change="handleSelectionChange"
          border
          height="100%"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="批次号" align="center" prop="lotCode" />
          <el-table-column
            label="产品描述"
            align="center"
            min-width="150px"
            prop="productDescription"
          />
          <el-table-column
            label="计划单号"
            align="center"
            prop="productionPlanNo"
          />
          <el-table-column label="责任工段" align="center" prop="deptName" />
          <el-table-column
            label="批次投产量"
            align="center"
            prop="productionQuantity"
          />
          <el-table-column label="废品数量" align="center" prop="rejectNum" />
          <el-table-column label="生成日期" align="center" prop="fillDate">
            <template #default="scope">
              {{ parseTime(scope.row.fillDate, "{y}-{m}-{d}") }}
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-button
                link
                type="warning"
                icon="Edit"
                v-hasPermi="['business:noCurrentReject:edit']"
                @click="handleShowTurnoverDialog(scope.row)"
              >
                编辑
              </el-button>

              <el-button
                link
                type="danger"
                icon="Delete"
                v-hasPermi="['business:noCurrentReject:remove']"
                @click="handleDelete(scope.row)"
              >
                删除
              </el-button>
              <!-- <el-button
                v-else
                link
                type="primary"
                icon="View"
                @click="handleShowTurnoverDialog(scope.row)"
              >
                查看
              </el-button> -->
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情弹窗 -->
    <dialog-reject-info
      ref="dialogRejectInfoRef"
      @handleSaveSuccess="getList()"
    />
    <!-- 选择批次弹窗 -->
    <dialog-select-lot ref="dialogSelectLot" @handleSaveSuccess="getList()" />
  </div>
</template>

<script setup name="noCurrentReject">
import { listReject, delReject } from "@/api/business/noCurrentReject";

import DialogRejectInfo from "./DialogRejectInfo";
import DialogSelectLot from "./DialogSelectLot";
const { proxy } = getCurrentInstance();
const dataList = ref([]);
const loading = ref(true);
const ids = ref([]);
const total = ref(0);
/** 查询对象 */
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  formCode: null,
  formDate: null,
});

/***********************  方法区  ****************************/

/** 列表查询 */
function getList() {
  loading.value = true;
  listReject(queryParams.value).then((response) => {
    dataList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm("是否确认删除选中的数据项？")
    .then(function () {
      return delReject(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功！");
    })
    .catch(() => {});
}

// 新增按钮操作
function handleLogDialog() {
  proxy.$refs.dialogSelectLot.open();
}

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

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
    formCode: null,
    formDate: null,
  };
  handleQuery();
}

/** 修改周转按钮操作 */
function handleShowTurnoverDialog(row) {
  proxy.$refs.dialogRejectInfoRef.open(row);
}

/** 导出按钮操作 */
// function handleExport() {
//   proxy.download(
//     "business/returnReceipt/export",
//     {
//       ...queryParams.value,
//     },
//     `order_${new Date().getTime()}.xlsx`
//   );
// }

getList();
</script>
