<template>
  <el-dialog
    v-model="dialogVisible"
    title="批量修改状态"
    width="500px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form :model="form" label-width="100px">
      <el-form-item label="选择状态">
        <el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
          <el-option label="转入在职人才库" :value="1" />
          <el-option label="曾就职" :value="6" />
          <el-option label="具备潜力" :value="7" />
          <!-- <el-option label="待面试" :value="0" />
          
          <el-option label="已录用" :value="2" />
          <el-option label="已拒绝" :value="3" /> -->
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleConfirm" :loading="loading">
          确认
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue';
import { successMessage, warningMessage } from '/@/utils/message';
import axios from 'axios';
import { Session } from '/@/utils/storage';

const dialogVisible = ref(false);
const loading = ref(false);
const selectedRows = ref<Array<{ id: number | string }>>([]);

const form = reactive({
  status: 6,
});

const emit = defineEmits(['success']);

// 打开对话框的方法
const open = (rows: Array<{ id: number | string }>) => {
  selectedRows.value = rows;
  dialogVisible.value = true;
  form.status = 6;
};

// 确认修改状态
const handleConfirm = async () => {
  if (!form.status) {
    warningMessage('请选择状态');
    return;
  }

  loading.value = true;
  try {
    // 这里需要替换为实际的API调用
    const response = await axios.post(`${import.meta.env.VITE_API_URL}/api/system/talent_pool/batch-update-status/`, {
      ids: selectedRows.value.map(row => row.id),
      status: form.status,
      tenant_id: Session.get('tenant_id')
    },{
      headers:{
        'authorization':'JWT '+ Session.get('token'),
      },
    });

    if (response.data.code === 2000) {
      successMessage('状态修改成功');
      dialogVisible.value = false;
      emit('success');
    } else {
      warningMessage(response.data.message || '操作失败');
    }
  } catch (error) {
    console.error('批量修改状态失败:', error);
    warningMessage('操作失败');
  } finally {
    loading.value = false;
  }
};

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