<template>
  <el-dialog
    v-model="visible"
    :show-close="!requesting"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="700px"
    custom-class="loading-dialog-EL"
    align-center
    append-to-body
  >
    <div class="loading-content">
      <!-- 新的步骤进度条 -->
      <ProgressSteps
        v-if="useNewProgress && progressSteps.length > 0"
        :steps="progressSteps"
        @complete="handleButtonClick"
      />

      <!-- 原有的简单进度条 -->
      <div v-else class="progress-container">
        <div class="progress-bar">
          <div
            class="progress-inner"
            :style="{ width: `${progress}%` }"
          ></div>
        </div>
        <span class="progress-text">{{ progress.toFixed(2) }}%</span>
      </div>

      <div class="message" style="display: none">{{ message }}</div>
      <!-- 错误信息插槽 -->
      <slot name="errList"></slot>
      <!-- 进度消息插槽 -->
      <slot name="progressMessages"></slot>

      <el-button
        v-if="!disabledButton && !useNewProgress"
        :disabled="disabledButton"
        type="primary"
        class="action-button   button--primary1  mar-top-20"
        @click="handleButtonClick"
      >
        {{ buttonText }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits , watch } from 'vue'
import ProgressSteps from './ProgressSteps.vue'

interface StepData {
  goods_art_no: string
  msg_type: string
  name: string
  status: '等待处理' | '正在处理' | '处理完成' | '处理失败'
  current: number
  total: number
  error: number
}

interface Props {
  modelValue: boolean
  progress?: number
  message?: string
  disabledButton?: boolean
  buttonText?: string,
  requesting?: boolean
  useNewProgress?: boolean
  progressSteps?: StepData[]
}

const props = withDefaults(defineProps<Props>(), {
  progress: 0,
  message: '正在为您处理，请稍后...',
  disabledButton: true,
  buttonText: '处理完毕，点击打开最终图片目录',
  requesting: false,
  useNewProgress: false,
  progressSteps: () => []
})

const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void
  (e: 'button-click'): void
}>()

const visible = ref(props.modelValue)

// 监听visible变化
watch(() => visible.value, (newVal) => {
  emit('update:modelValue', newVal)
})

// 监听props.modelValue变化
watch(() => props.modelValue, (newVal) => {
  visible.value = newVal
})

const handleButtonClick = () => {
  emit('button-click')
}
</script>
<style lang="scss">
.loading-dialog-EL{
  border-radius: 10px;
  .el-dialog__header {
    display: none;
    padding: 0;
  }
 .el-dialog__body {
   // background-image: url(@/assets/images/Photography/loading-bg.png);  /* 添加背景图片 */
    background-size: cover;  /* 确保图片覆盖整个区域 */
    background-position: center;  /* 图片居中显示 */
    background-repeat: no-repeat;  /* 防止图片重复 */
    padding: 20px 20px;  /* 添加内边距 */
  }

}
</style>

<style lang="scss" scoped>
.loading-dialog {
  :deep(.el-dialog__header) {
    display: none;
    padding: 0;
  }

  :deep(.el-dialog__body) {
    padding:0;
  }
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.progress-container {
  width: 100%;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;

  .progress-bar {
    flex: 1;
    height: 6px;
    background: #E4E7ED;
    border-radius: 3px;
    overflow: hidden;

    .progress-inner {
      height: 100%;
      background: linear-gradient(90deg, #2FB0FF,#B863FB);
      border-radius: 3px;
      transition: width 0.3s ease;
    }
  }

  .progress-text {
    min-width: 45px;
    color: #606266;
    font-size: 14px;
  }
}

.message {
  color: #606266;
  font-size: 14px;
  margin-bottom: 0px;
}

.action-button {
  padding: 10px  20px;
}
</style>
