<template>
  <el-dialog title="选择部门" v-model="visible" width="600px" append-to-body draggable>
    <div class="column-container" style="height: 400px">
      <div class="el-table-container">
        <div class="el-table-inner-container">
          <el-table v-loading="loading" row-key="deptId" :data="dataList" height="100%">
            <el-table-column label="行号" type="index" width="50" align="center" />
            <el-table-column label="部门编码" prop="deptCode" width="150" align="center" />
            <el-table-column label="部门名称" prop="deptName" align="center" />
            <el-table-column label="操作" width="60" align="center">
              <template #default="scope">
                <el-button link type="success" icon="Select" @click="handleSelectDept(scope.row)">选择</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </el-dialog>
</template>
<script setup>
import { listDept } from '@/api/system/dept'
const emit = defineEmits(['handleSelectDept'])

const loading = ref(false)
const visible = ref(false)

const dataList = ref([])

/** 设备档案 查询对象 */
const queryParams = ref({
  type: 0,
  deptName: '',
  deptCode: '',
  isWorkSection: 1
})
/***********************  方法区  ****************************/
/** 打开抽屉 */
const open = () => {
  visible.value = true
  loadData()
}

const loadData = () => {
  loading.value = true
  listDept(queryParams.value).then((res) => {
    dataList.value = res.data
    //dataTotal.value = res.total
    loading.value = false
  })
}

const handleRefreshDetail = () => {
  loadData()
}

const handleSelectDept = (data) => {
  emit('handleSelectDept', data)
  visible.value = false
}

/** 暴露给父组件的方法 */
defineExpose({
  open
})
</script>
