<template>
  <el-dialog title="添加工序" v-model="visible" width="800px" height="400px" @close="close" append-to-body draggable>
    <el-form ref="dialogForm" :model="queryParams" :inline="true" style="padding-top: 16px">
      <el-form-item label="工序名称：" prop="processAlias" label-width="104">
        <el-input v-model.trim="queryParams.keyword" type="text" @keydown.enter.prevent style="width: 160px"
          placeholder="请输入关键字" :clearable="true" @keyup.enter="handleSearch" />
      </el-form-item>
      <el-form-item label-width="20px">
        <el-button type="info" icon="Search" @click="handleSearch">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table ref="dialogTable" :data="productList" size="small" v-loading="loading" border height="370px"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="序号" width="56" align="center" type="index" />
      <el-table-column label="工序名称" align="center" prop="processAlias" />
    </el-table>
    <!-- 分页 -->
    <!-- <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    /> -->
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" icon="Check" :disabled="selections.length === 0" @click="handleMultipleSelected">
          确 定
        </el-button>
        <el-button type="danger" icon="Close" @click="close">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { processesForOutsourceByFirst } from "@/api/business/daywork";
const { proxy } = getCurrentInstance();
/** 字典数组区 */
const { process_status } = proxy.useDict("process_status");
/** 工序变量 */
const total = ref(0);
const props = defineProps({
  multipleSelected: {
    type: Function,
    default: null,
  },
  supplierId: {
    type: String,
    default: "",
  },
});

const { multipleSelected, supplierId } = toRefs(props);
const productList = ref([]);
const visible = ref(false);
const loading = ref(false);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
});
const selections = ref([]);

/**
 * 对话框打开 事件
 */
function open(data) {
  console.log(data)
  queryParams.value.id = data.lotId
  queryParams.value.outsourceDetailId = data.id ? data.id : 0
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = 10;
  visible.value = true;
  getList();
}

/**
 * 对话框关闭 事件
 */
function close() {
  proxy.$refs.dialogForm.resetFields();
  proxy.$refs.dialogTable.clearSelection();
  queryParams.value.pageNum = 1;
  visible.value = false;
}

/**
 * 加载数据
 */
function getList() {
  loading.value = true;
  processesForOutsourceByFirst(queryParams.value).then((res) => {
    productList.value = res.rows;
    total.value = res.total;
    loading.value = false;
  });
}

/**
 * 列表checkbox列选择 事件
 */
function handleSelectionChange(selection) {
  selections.value = selection;
}

/**  搜索 事件 */
function handleSearch() {
  getList();
}
/** 多选事件 */
function handleMultipleSelected() {
  if (multipleSelected.value) {
    multipleSelected.value(selections.value);
  }
  close();
}

defineExpose({
  open,
});
</script>
