<template>
  <el-dialog v-model="dialogVisible" title="招标文件" width="500" draggable>
    <el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto">
      <el-form-item label="招标文件" prop="name">
        <file-upload
          v-model="form.costEstimationFile"
          :fileSize="100"
          :auto-upload="false"
          uploadUrl="/tender/biddingPlan/uploadBiddingDocuments"
          method="put"
          ref="fileUploadRef"
          :data="{
            projectId: currentProject?.id,
            type: planType,
            fileType: '1',
            bidStatus: '0',
            id: row.id
          }"
          showFileList
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog()"> 取消 </el-button>
        <el-button type="primary" @click="submitForm()">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { useUserStoreHook } from '@/store/modules/user';
const userStore = useUserStoreHook();
const currentProject = computed(() => userStore.selectedProject);
const dialogVisible = ref(false);
const row = ref<any>();
const planType = ref<any>('');
const fileUploadRef = ref<any>();
const ruleForm = ref<any>();
const rules = ref({
  costEstimationFile: [{ required: true, message: '请上传招标文件', trigger: ['blur'] }]
});
const emit = defineEmits(['success']);
const form = ref({
  costEstimationFile: ''
});

const open = (rows: any, type: string) => {
  dialogVisible.value = true;
  console.log(rows, type);
  row.value = rows;
  planType.value = type;
};
const closeDialog = () => {
  dialogVisible.value = false;
  form.value.costEstimationFile = '';
  emit('success');
};
const submitForm = () => {
  fileUploadRef.value.submitUpload().then((res) => {
    if (res == 'noFile') {
      ElMessage({
        message: '请上传招标文件',
        type: 'warning'
      });
      return;
    }
    dialogVisible.value = false;
    emit('success');
  });
};
defineExpose({
  open
});
</script>

<style scoped lang="scss"></style>
