<template>
  <el-dialog title="工艺列表" v-model="visible" width="800px" height="400px" @close="close" append-to-body draggable>
    <el-table ref="dialogTable" :data="processList" size="small" v-loading="loading" border height="370px"
      @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="40" align="center" /> -->
      <el-table-column type="index" label="行号" width="50" align="center" />
      <el-table-column label="工序编码" align="center" prop="processCode" />
      <el-table-column label="工序简称" align="center" prop="processAlias" />
    </el-table>
    <template #footer>
      <div class="dialog-footer">
        <el-button icon="Close" @click="close">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
const { proxy } = getCurrentInstance()
/** 工序变量 */
const total = ref(0)
import { getProcessList } from '@/api/business/outsourcedOrderDetail'

const processList = ref([])
const visible = ref(false)
const loading = ref(false)
const queryParams = ref({
  lotId: '',
  dayworkId: '',
  isAmend: '',
  isWasteRecycling: '',
  processAlias: '',
  pageNum: 1,
  pageSize: 10
})
const technologyVersions = ref([])
const selections = ref([])
const finishedProcesses = ref([])

/**
 * 对话框打开 事件
 */
function open(data) {
  visible.value = true
  console.log(data)
  queryParams.value.dayworkId = data.dayworkId
  queryParams.value.lotId = data.lotId
  queryParams.value.isAmend = data.isAmend
  queryParams.value.isWasteRecycling = data.isWasteRecycling
  finishedProcesses.value = data.finishedProcesses
  getProcessesList()
}

/**
 * 对话框关闭 事件
 */
function close() {
  proxy.$refs.dialogTable.clearSelection()
  queryParams.value.pageNum = 1
  visible.value = false
}
function getProcessesList() {
  // queryParams.value.productId = productId.value
  getProcessList(queryParams.value).then((res) => {
    const maxStep = res.rows.findLastIndex(e => finishedProcesses.value.some(t => t.technologicalProcessDetailId === e.id))
    console.log(maxStep)
    res.rows.splice(0, maxStep + 1)
    processList.value = res.rows
  })
}
//切换工艺版本
function handleTechnologyVersionChange() {
}

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

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

defineExpose({
  open
})
</script>
