<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="code" label-width="104">
        <el-input v-model.trim="queryParams.processAlias" 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="factory" />
      <el-table-column label="炉号" align="center" prop="furnaceNumber" />
      <el-table-column label="牌号" align="center" prop="brandNumber" />
      <el-table-column label="规格" align="center" prop="spec" />
      <el-table-column label="材料直径" align="center" prop="diameter" />
      <el-table-column label="形状" align="center" prop="shape" />
      <el-table-column label="来料日期" align="center" prop="incomingDate" />
      <el-table-column label="原料编码" align="center" prop="rawMaterialCode" />
      <el-table-column label="技术要求1" align="center" prop="firstTechnicalRequirement" />
      <el-table-column label="技术要求2" align="center" prop="secondTechnicalRequirement" />
      <el-table-column label="操作" align="center" prop="rawMaterialCode">
        <template #default="scope">
          <el-button type="success" icon="finished" circle @click="handleSingleSelected(scope.row)" />
        </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" /> -->
    <!-- <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 { carrierForOutsource } from "@/api/business/outsourcedOrder";
import { getFurnaceNoInfo } from '@/api/business/p2'
const { proxy } = getCurrentInstance();
/** 字典数组区 */
const { process_status } = proxy.useDict("process_status");
/** 工序变量 */
const total = ref(0);
const props = defineProps({
  singleSelected: {
    type: Function,
    default: null,
  },
  multipleSelected: {
    type: Function,
    default: null,
  },
  supplierId: {
    type: String,
    default: "",
  },
});

const { multipleSelected, supplierId, singleSelected } = toRefs(props);
const productList = ref([]);
const visible = ref(false);
const lotId = ref({});
const loading = ref(false);
const queryParams = ref({
});
const details = ref([])
const selections = ref([]);

/**
 * 对话框打开 事件
 */
function open(data) {
  queryParams.value = data.queryParams
  details.value = data.details
  visible.value = true;
  getList();
}

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

/**
 * 加载数据
 */
function getList() {
  loading.value = true;
  getFurnaceNoInfo({
    productionPlanNo: queryParams.value.productionPlanNo,
    lineNumber: queryParams.value.lineNumber
  }).then((res) => {
    productList.value = res.data;
    loading.value = false;
  });
}

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

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

function handleSingleSelected(row) {
  if (singleSelected.value) {
    singleSelected.value(details.value, row);
  }
  close();
}

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