<template>
  <div class="resout-container AI-Design-container">
    <div class="header">
      <van-nav-bar title="生成结果" left-arrow @click-left="returnPage" @click-right="toHome">
        <template #right>
          <van-icon name="wap-home-o" color="#333" size="26" />
        </template>
      </van-nav-bar>
    </div>

    <div class="container">
      <!-- 历史生图 -->
      <div class="history-section padded-lr-20" v-if="wallType === 'outside' || wallType === 'inside'">
        <div class="history-header" @click="viewHistory">
          <van-icon name="clock-o" color="#EC8868" />
          <span>历史生图</span>
          <span v-if="!readState" class="badge-dot"></span>
        </div>
      </div>
      <!-- 房屋效果图 -->
      <div class="image-container">
        <div v-if="imageUrl" class="comparisonWrapper">
          <div class="imgbox-t">
            <div>
              <p class="tit">原图</p>
            </div>
            <div>
              <p class="tit">AI效果图</p>
            </div>
          </div>
          <div class="imgbox-b">
            <div class="image-wrapper" @click="imgClick(0)">
              <img :src="UserFilePathUrl" alt="房屋效果图" class="house-image" @error="handleImageError" />
              <div v-on="{
                'click.stop': imgHasErr ? () => reloadImage('userFile') : () => { }
              }"></div>
            </div>
            <div class="image-wrapper" @click="imgClick(1)">
              <img :src="imageUrlSmall" alt="房屋效果图" class="house-image" @error="handleImageError" />
              <div v-on="{
                'click.stop': imgHasErr ? () => reloadImage('imageSmall') : () => { }
              }"></div>
            </div>
          </div>
        </div>
        <div v-else class="loading-state">
          <img v-if="StateCode != 3 && StateCode != 4" src="@/assets/AIDesign/loding.gif" style="width: 100px;">
          <p class="loading-text">{{ type || StateCode ? (StateCode == 3 ? '生成失败' : (StateCode == 4 ?
            '生成失败，\n' + StateInfo :
            '正在为您加速生成中，先喝杯茶吧~\n退出本页不影响生成')) : '加载中...' }}</p>
        </div>
        <div v-if="imageUrl" class="feedback" @click="toFeedback">
          <img src="@/assets/AIDesign/feedback_icon.png" class="feedback-icon" />
          <span v-if="F_Feedback == null">一键反馈</span>
          <span v-if="F_Feedback != null">查看反馈</span>
        </div>
      </div>

      <!-- 功能按钮组 -->
      <!-- 外墙 -->
      <div class="button-group-outside" v-if="wallType === 'outside' || wallType === 'inside'">
        <button class="action-button-big flex-center" @click="handleAIfun"
          v-if="agentFrom === 'stoneLikePaint' && allRes && allRes.F_DesignStyle != 'CHANGE_COLOR' && StateCode == 2 && wallType === 'outside'">
          <img src="@/assets/AIDesign/file-excel-line.png" class="icon" />
          <div>
            <div class="title">确认AI设计</div>
            <div class="text">生成解决方案</div>
          </div>
        </button>
        <div class="flex-between">
          <button class="action-button-middle flex-center" :disabled="regenerateDisable"
            :class="regenerateDisable == true ? 'save-button-disabled' : ''" @click="regenerate">
            <img src="@/assets/AIDesign/resetIcon.png" class="icon" />
            <div>
              <div class="title">重新生成</div>
              <div class="text">再来一次也不错</div>
            </div>
          </button>
          <!-- :class="projectDisableFlag == true ? 'save-button-disabled' : ''"  :disabled="projectDisableFlag"-->
          <button class="action-button-middle flex-center" @click="manualDesign"
            v-if="showArtificial && StateCode == 2 && !projectDisableFlag && wallType === 'outside'">
            <img src="@/assets/AIDesign/bsIcon.png" class="iconbig" />
            <div>
              <div class="title">转人工设计
              </div>
              <div class="text">别墅之星小程序</div>
            </div>
          </button>
        </div>
      </div>
      <!-- 内墙 -->
      <!--<div class="button-group" v-if="wallType === 'inside'">-->
        <!--<button class="action-button" :disabled="regenerateDisable"-->
          <!--:class="regenerateDisable == true ? 'save-button-disabled' : ''" @click="regenerate">-->
          <!--<van-icon class="icon" name="replay" />-->
          <!--<span class="text">重新生成</span>-->
        <!--</button>-->
        <!--<button class="action-button" @click="viewHistory">-->
          <!--<van-icon class="icon" name="clock-o" />-->
          <!--<span class="text">历史生图</span>-->
          <!--<span v-if="!readState" class="badge-dot"></span>-->
        <!--</button>-->
      <!--</div>-->
    </div>
    <van-image-preview
            v-model="showImagePreview"
            :images="imagePreviewArray"
            :loop="false"
            :start-position="imagePreviewIndex"
            @change="imagePreviewOnChange">
      <template v-slot:index>
        <div class="image-preview-header">
          <div>{{imagePreviewIndex+1}}/{{imagePreviewArray.length}}</div>
          <div>{{imagePreviewIndex == 0 ? '原图' : '效果图'}}</div>
        </div>
      </template>
    </van-image-preview>
  </div>
</template>
<script lang="ts">
import { ImagePreview, Dialog } from 'vant';
import { Component, Vue } from "vue-property-decorator";
import { GetEntity, GetReadState, UpdateReadState, insideGetEntity, insideGetReadState, insideUpdateReadState, GetProjectlist, GetDictList, AddTrackEvent } from "@/api/indexAI";
import { getWecomType, toLBHome, toXiaoChengxu, getWxconfig, getWecomTypeName, checkAndSaveUserWecomType } from '@/utils/index';
import axios from "axios";
declare let wx: any;
@Component
export default class extends Vue {
  private readState = true;
  // 数据属性
  // private imageUrl = require('@/assets/AIDesign/house-image.jpg'); // 替换为实际图片路径
  private imageUrl = ''; // 替换为实际图片路径
  private imageUrlSmall = '';
  private UserFilePathUrl = '';//用户原图
  private pollingTimer: number | null = null; // 轮询定时器引用
  private timer = null;
  private StateCode = null;
  private projectId = null;
  private regenerateDisable = true;
  private StateInfo = '';
  private type = '';
  private wallType = '';
  private F_OutsideType = null;
  private F_Feedback = null;
  private defaultImg = require('@/assets/AIDesign/imgErrIcon.jpg'); // 替换为实际图片路径
  private imgHasErr = false;
  private showImagePreview = false;
  private imagePreviewArray = [];
  private imagePreviewIndex = 0
  // 处理内外墙api
  private GetEntityToApi = {
    outside: GetEntity,
    inside: insideGetEntity
  };
  private GetReadStateToApi = {
    outside: GetReadState,
    inside: insideGetReadState
  };
  private UpdateReadStateToApi = {
    outside: UpdateReadState,
    inside: insideUpdateReadState
  };

  private designPageApi = {
    outside: '/AIDesign/design',
    inside: '/AIDesign/insideDesign'
  };

  private designTimer = {
    outside: 30000,
    inside: 20000
  };
  private showArtificial = false;
  private agentFrom = window.localStorage.getItem('agentFromAI');
  private outsideDesignCount = 0;//项目下设计已用数量-接口获取
  private isNeedProjectFlag = true;//是否需要项目-接口获取
  private projectDisableFlag = true;//转人工不可点击
  private serviceCodeArray = [];
  private allRes = null;
  created() {
    getWxconfig();
    if (window.localStorage.getItem('agentFromAI') === 'stoneLikePaint') {
      this.getServiceCode();
    }
    checkAndSaveUserWecomType();
  }

  activated() {
    this.initialize();
    this.wallType = this.$route.query.wallType || 'outside';
    const userInfo: any = JSON.parse(window.localStorage.getItem("userInfoV1")!);
    const customerCode = userInfo && userInfo.sysUserExt ? userInfo.sysUserExt.customerCode : '';
    const salesLevel = userInfo && userInfo.sysUserExt ? userInfo.sysUserExt.salesLevel : '';
    // 外墙-服务商随身邦
    if (this.agentFrom === 'stoneLikePaint' && this.wallType === 'outside') {
      this.getIsNeedProjectFlag();
      this.showArtificial = true;
    }
    // 和部分经销商展示转人工
    // else if(customerCode && (salesLevel === 'customer_level' || salesLevel === 'reseller_level')){
    //   this.showArtificial = true;
    // }
    // 从经销商随身邦进入的，显示转人工按钮，没有次数限制
    if ((this.agentFrom === 'ssb' || this.agentFrom === 'dg') && this.wallType === 'outside') {
      this.showArtificial = true;
      this.projectDisableFlag = false;
    }
    this.type = window.localStorage.getItem('type');
    this.GetReadStateFn();
    this.GetEntityDataFirst()

  }
  // 离开页面时清除定时器
  deactivated() {
    // console.log('resule页面销毁1')
    window.localStorage.removeItem('type');
    clearInterval(this.pollingTimer);
    clearTimeout(this.timer);
    this.pollingTimer = null;
    this.timer = null;
  }
  initialize() {
    clearInterval(this.pollingTimer);
    clearTimeout(this.timer);
    this.readState = true;
    this.imageUrl = ''; // 替换为实际图片路径
    this.imageUrlSmall = '';
    this.UserFilePathUrl = '';//用户原图
    this.pollingTimer = null; // 轮询定时器引用
    this.timer = null;
    this.StateCode = null;
    this.projectId = null;
    this.regenerateDisable = true;
    this.StateInfo = '';
    this.type = '';
    this.wallType = '';
    this.outsideDesignCount = 0;
    this.isNeedProjectFlag = true;
    this.projectDisableFlag = true;
    this.showArtificial = false;
    this.allRes = null;
    this.imgHasErr = false;
  }

  // 图片加载失败处理（私有方法）
  private handleImageError(e) {
    const imgElement = e.target as HTMLImageElement;
    // 降级显示默认占位图
    imgElement.src = this.defaultImg;
    imgElement.onerror = null;
    this.imgHasErr = true;
  }
  private reloadImage(imgType: 'userFile' | 'imageSmall') {
    let that = this;
    if (that.allRes && that.imgHasErr) {
      if (imgType === 'userFile') {
        if (that.allRes.F_UserFilePath) {
          that.UserFilePathUrl = that.allRes.BaseUrl + that.allRes.F_UserFilePath;
          that.imgHasErr = false;
        }
      } else {
        let high_Definition_img = that.allRes.F_ResultFilePath || that.allRes.F_ResultlargeFilePath || that.allRes.F_ResultSmallFilePath;
        if (high_Definition_img) {
          that.imageUrl = that.allRes.BaseUrl + high_Definition_img;
          that.imageUrlSmall = that.allRes.BaseUrl + that.allRes.F_ResultSmallFilePath;
          that.imgHasErr = false;
        }
      }
    }
  }
  // 是否关联了项目
  getIsNeedProjectFlag() {
    let that = this;
    const formData = new FormData();
    // const userInfo: any = JSON.parse(window.localStorage.getItem("userInfoV1")!);
    // let roleIdArray = [];
    // if (userInfo.roles.length > 0) {
    //   userInfo.roles.forEach(item => {
    //     roleIdArray.push(item.roleId);
    //   })
    // }
    // formData.append('roleIds', roleIdArray.join(','));
    // formData.append('WXuserid', userInfo.loginName);
    formData.append('baseType', 0);//0外墙--这里只用查询外墙
    // const agentFrom = window.localStorage.getItem('agentFromAI');
    // const wecomType = getWecomType(agentFrom);
    // formData.append('wecomType', 5);
    GetDictList(formData).then(response => {
      if (response.StatusCode == 200) {
        if (that.serviceCodeArray.length == 0) {
          that.isNeedProjectFlag = false; //是否需要项目
        } else {
          that.isNeedProjectFlag = response.Data.isNeedProject;
        }
      }
    })
  }

  private getServiceCode() {
    let that = this;
    const userInfo: any = JSON.parse(window.localStorage.getItem("userInfoV1")!);
    let serviceCodeArray = [];
    // if (userInfo && userInfo.loginTypeList && userInfo.loginTypeList.length > 0) {
    //   userInfo.loginTypeList.forEach(item => {
    //     if (item.shopType == 'stoneLikePaint') {
    //       item.shopList.forEach(childItem => {
    //         serviceCodeArray.push(childItem.shop_code);
    //       })
    //     }
    //   })
    // }
    if (userInfo && userInfo.ServiceCode) {
      serviceCodeArray = userInfo.ServiceCode.split(',').map(item => item.trim()).filter(item => item !== '');
    }
    that.serviceCodeArray = serviceCodeArray;
  }
  GetReadStateFn() {
    const formData = new FormData();
    // const userInfo: any = JSON.parse(window.localStorage.getItem("userInfoV1")!);
    // formData.append('WXuserid', userInfo.loginName);
    if (this.wallType === 'outside') {
      const outsideType_val = this.F_OutsideType || 0;
      formData.append('outsideType', outsideType_val);
    }
    this.GetReadStateToApi[this.wallType](formData).then(response => {
      if (response.StatusCode == 200) {
        this.readState = response.Data.readState;
      }
    });
  }
  UpdateReadStateFn() {
    const formData = new FormData();
    // const userInfo: any = JSON.parse(window.localStorage.getItem("userInfoV1")!);
    // formData.append('WXuserid', userInfo.loginName);
    const outsideType_val = this.F_OutsideType || 0;
    formData.append('outsideType', outsideType_val);
    this.UpdateReadStateToApi[this.wallType](formData).then(response => { });
  }
  returnPage() {
    this.$router.push({ path: this.designPageApi[this.wallType] });
    // this.$router.back();
  }
  toHome() {
    toLBHome()
  }
  imgClick(index) {
      this.showImagePreview = true;
      this.imagePreviewIndex = index;
    // ImagePreview([this.UserFilePathUrl,this.imageUrl],index);
  }
    imagePreviewOnChange(index){
      this.imagePreviewIndex = index;
    }
  private startPolling(): void {
    // 立即执行一次检查
    this.GetEntityData();

    // 设置定时器每秒执行一次检查
    this.pollingTimer = window.setInterval(() => {
      if (!this.imageUrl) {
        if (this.StateCode == 3 || this.StateCode == 4) {
          clearInterval(this.pollingTimer);
          this.pollingTimer = null;
        } else {
          this.GetEntityData();
        }

      } else {
        // 当 imageUrl 有值时，清除定时器
        if (this.pollingTimer) {
          clearInterval(this.pollingTimer);
          this.pollingTimer = null;
        }
      }
    }, 3000);
  }
  //进入页面首次调用获取状态
  GetEntityDataFirst() {
    let that = this;
    const F_ID = this.$route.query.F_id || "";
    const formData = new FormData();
    formData.append('F_id', F_ID);
    this.GetEntityToApi[this.wallType](formData).then(response => {
      // console.log(response);
      if (response.StatusCode == 200) {
        if (response.Data == null) {
          that.regenerateDisable = true;
          if (that.timer) {
            clearTimeout(that.timer);
            that.timer = null;
          }
          that.timer = setTimeout(() => {
            that.startPolling();
          }, that.designTimer[that.wallType]);
        } else {
          this.allRes = response.Data;
          this.StateCode = response.Data.StateCode;
          this.StateInfo = response.Data.Description;
          this.projectId = response.Data.ProjectID;
          this.F_OutsideType = response.Data.F_OutsideType;
          this.F_Feedback = response.Data.F_Feedback;
          let DesignCount = response.Data.DesignCount || 0;
          // 外墙-服务商随身邦
          if (this.agentFrom === 'stoneLikePaint' && this.wallType === 'outside') {
            if (that.isNeedProjectFlag) {
              if (DesignCount >= 3) {
                that.projectDisableFlag = false;//有项目判断>=3出现
              }
            } else {
              that.projectDisableFlag = false;//没有项目就可点击
            }
          }
          if (response.Data.F_ResultFilePath || response.Data.F_ResultlargeFilePath) {
            const high_Definition_img = response.Data.F_ResultFilePath || response.Data.F_ResultlargeFilePath || response.Data.F_ResultSmallFilePath;
            that.imageUrl = response.Data.BaseUrl + high_Definition_img;
            that.imageUrlSmall = response.Data.BaseUrl + response.Data.F_ResultSmallFilePath;
            that.UserFilePathUrl = response.Data.BaseUrl + response.Data.F_UserFilePath;
            that.imagePreviewArray = [that.UserFilePathUrl,that.imageUrl];
          }
          if (response.Data.StateCode == 1) {
            let createTime = new Date(response.Data.CreateDate);
            let currentTime = new Date().getTime();
            if (currentTime - createTime > that.designTimer[that.wallType]) {
              that.startPolling();
            } else {
              if (that.timer) {
                clearTimeout(that.timer);
                that.timer = null;
              }
              that.timer = setTimeout(() => {
                that.startPolling();
              }, currentTime - createTime);
            }
          } else {
            if (response.Data.StateCode == 2 || response.Data.StateCode == 3 || response.Data.StateCode == 4) {
              that.regenerateDisable = false;
            } else {
              that.regenerateDisable = true;
            }
          }
        }
      } else {
        this.$toast.fail(response.Info);
      }
    })
  }

  GetEntityData() {
    let that = this;
    const F_ID = this.$route.query.F_id || "";
    const formData = new FormData();
    formData.append('F_id', F_ID);
    this.GetEntityToApi[this.wallType](formData).then(response => {
      // console.log(response);
      if (response.StatusCode == 200) {
        if (response.Data) {
          this.allRes = response.Data;
          this.StateCode = response.Data.StateCode;
          this.StateInfo = response.Data.Description;
          this.F_OutsideType = response.Data.F_OutsideType;
          this.F_Feedback = response.Data.F_Feedback;
          this.projectId = response.Data.ProjectID;
          let DesignCount = response.Data.DesignCount || 0;
          // 外墙-服务商随身邦
          if (this.agentFrom === 'stoneLikePaint' && this.wallType === 'outside') {
            if (that.isNeedProjectFlag) {
              if (DesignCount >= 3) {
                that.projectDisableFlag = false;//有项目判断>=3出现
              }
            } else {
              that.projectDisableFlag = false;//没有项目就可点击
            }
          }
          if (response.Data.F_ResultFilePath || response.Data.F_ResultlargeFilePath) {
            const high_Definition_img = response.Data.F_ResultFilePath || response.Data.F_ResultlargeFilePath || response.Data.F_ResultlargeFilePath;
            that.imageUrl = response.Data.BaseUrl + high_Definition_img;
            that.imageUrlSmall = response.Data.BaseUrl + response.Data.F_ResultSmallFilePath;
            that.UserFilePathUrl = response.Data.BaseUrl + response.Data.F_UserFilePath;
            that.imagePreviewArray = [that.UserFilePathUrl,that.imageUrl];
          }
          if (response.Data.StateCode == 2 || response.Data.StateCode == 3 || response.Data.StateCode == 4) {
            that.regenerateDisable = false;
          } else {
            that.regenerateDisable = true;
          }
        } else {
          that.regenerateDisable = true;
        }
      } else {
        this.$toast.fail(response.Info);
      }
    })
  }
  // 下载图片并保存到相册
  downloadAndSaveImage() {
    const that = this;
    const imageUrl = this.imageUrl;
    wx.ready(function () {
      // 1. 下载OSS图片到本地临时路径
      wx.downloadFile({
        url: imageUrl,
        success: (downloadRes) => {
          // 检查下载是否成功（临时文件路径存在）
          if (downloadRes.statusCode === 200 && downloadRes.tempFilePath) {
            // 2. 保存图片到相册
            wx.saveImageToPhotosAlbum({
              filePath: downloadRes.tempFilePath,
              success: () => {
                // 提示用户
                that.$toast.success('图片已成功保存到相册');
              },
              fail: (saveErr) => {
                console.error('保存图片失败', saveErr);
                that.$toast.fail('保存失败，请重试');
              }
            });
          } else {
            console.error('图片下载失败', downloadRes);
            that.$toast.fail('图片下载失败，请检查URL');
          }
        },
        fail: (downloadErr) => {
          console.error('下载请求失败', downloadErr);
          that.$toast.fail('下载图片失败，请重试');
        }
      });
    });
  }
  // 方法
  private saveImage(): void {
    if (!this.imageUrl) {
      this.$toast.fail('图片尚未生成完成');
      return;
    }

    // // 创建一个临时的下载链接
    // const link = document.createElement('a');
    // link.href = this.imageUrl;
    // link.download = `ai-design-${new Date().getTime()}.png`;
    // link.style.display = 'none';

    // // 将链接添加到页面并触发点击事件
    // document.body.appendChild(link);
    // link.click();

    // // 清理DOM元素
    // document.body.removeChild(link);

    fetch(this.imageUrl).then(response => response.blob()).then(blob => {
      const blobUrl = URL.createObjectURL(blob);
      // 创建一个临时的下载链接
      const link = document.createElement('a');
      link.href = blobUrl;
      link.download = `ai-design-${new Date().getTime()}.png`;
      link.style.display = 'none';

      // 将链接添加到页面并触发点击事件
      document.body.appendChild(link);
      link.click();

      // 清理DOM元素
      document.body.removeChild(link);

      // 释放Blob URL
      URL.revokeObjectURL(blobUrl);

      // this.$toast.success('图片保存成功');
    }).catch(error => {
      console.error('图片下载失败:', error);
      this.$toast.fail('图片下载失败');
    });
  }

  private regenerate(): void {
    // console.log('重新生成');
    let that = this;
    // 实现重新生成逻辑
    const F_ID = this.$route.query.F_id || "";
    let projectId = this.allRes.WecomType == 2 && that.projectId ? that.projectId : null;
    this.$router.push({
      path: this.designPageApi[this.wallType],
      query: {
        F_id: F_ID,
        projectId
      }
    });
  }

  private toFeedback(){
      let that = this;
      const F_ID = this.$route.query.F_id || "";
      this.$router.push({ path: '/AIDesign/feedback', query: { F_id: F_ID, feedbackResult: that.F_Feedback == null ? 0 : 1, wallType: this.wallType } });
  }

  private viewHistory(): void {
    this.UpdateReadStateFn();
    // console.log('查看历史生成');
    // 实现查看历史生成逻辑
    this.$router.push({ path: '/AIDesign/history', query: { wallType: this.wallType } });
  }

  private manualDesign(): void {
    let that = this;
    const formData = new FormData();
    formData.append('eventname', '转人工设计');//事件名称
    formData.append('eventtype', 'click');//事件类型
    formData.append('menupath', '外墙质感/结果页/转人工设计');//完整菜单路径
    const eventdataObj = {
      wecomType: getWecomTypeName(window.localStorage.getItem('agentFromAI')),
    };
    formData.append('eventdata', JSON.stringify(eventdataObj));//事件数据
    AddTrackEvent(formData)//埋点
    // 实现转人工设计逻辑
    toXiaoChengxu(`${process.env.VUE_APP_BASE_DISID6}`);
  }

  private handleAIfun() {
    const formData = new FormData();
    formData.append('eventname', '确认AI设计');//事件名称
    formData.append('eventtype', 'click');//事件类型
    formData.append('menupath', '外墙质感/结果页/确认AI设计');//完整菜单路径
    const eventdataObj = {
      wecomType: getWecomTypeName(window.localStorage.getItem('agentFromAI')),
    };
    formData.append('eventdata', JSON.stringify(eventdataObj));//事件数据
    AddTrackEvent(formData)//埋点
    let allRes = JSON.stringify(this.allRes);
    sessionStorage.setItem("planParams", allRes);
    this.$router.push({ path: '/AIDesign/GeneratePlan' });
  }
}
</script>

<style scoped lang="scss">
.resout-container {
  background-color: #f8f9fa;
  min-height: 100vh;
  flex-direction: column;
}

.header {
  /*height: 50px;*/
  /*line-height: 50px;*/
  /*text-align: center;*/
  /*background: #fff;*/
  border-bottom: 1px solid #f8f8f8;

  .van-nav-bar__title {
    font-size: 20px;
    color: #333;
  }

  .van-icon {
    font-size: 20px;
    color: #333 !important;
  }
}

.container {
  padding: 0 20px;

  .history-section {
    margin: 20px 0;

    .history-header {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 16px;
      background-color: #ffffff;
      border-radius: 18px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
      border: 1px solid #e9ecef;
      /* margin-bottom: 10px; */
    }

    .icon-clock {
      font-size: 12px;
      margin-right: 8px;
    }

    .history-header span {
      font-weight: 500;
      color: #EC8868;
    }

    .history-header .badge-dot {
      width: 5px;
      height: 5px;
      background-color: #ff4d4f;
      border-radius: 50%;
    }
  }
}

.image-container {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  .feedback{
    padding: 15px 10px 15px 10px;
    font-size: 16px;
    color: rgba(22, 93, 255, 1);
    .feedback-icon{
      width: 20px;
      margin-right: 5px;
      margin-bottom: -5px;
    }
  }
  .comparisonWrapper {
    display: flex;
    flex-direction: column;
    padding: 35px 6px;

    .imgbox-t {
      display: flex;
      justify-content: space-between;
      align-items: center;

      >div {
        .tit {
          width: fit-content;
          padding: 0 5px;
          height: 17px;
          line-height: 17px;
          border-radius: 4px;
          font-size: 10px;
        }
      }

      >div:first-child {
        width: 36%;

        .tit {
          background: rgba(204, 204, 204, 1);

        }
      }

      >div:last-child {
        width: 58%;

        .tit {
          color: #fff;
          background: #FF8D1A;
        }
      }
    }

    .imgbox-b {
      display: flex;
      justify-content: space-between;
      align-items: center;

      >div:first-child {
        width: 36%;
      }

      >div:last-child {
        width: 58%;
      }

      .image-wrapper {
        position: relative;
        width: 100%;
        margin: 5px 0;
        display: flex;
        align-items: center;
        justify-content: flex-start;

        .house-image {
          border-radius: 10px;
          display: block;
          width: 100%;
          height: auto;
        }

        .house-image+div {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background: transparent;
          z-index: 2;
        }
      }
    }
  }
}

.loading-state {
  position: relative;
  width: 100%;
  height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  text-align: center;
  // background-color: rgba(0, 0, 0, 0.7);
  background-image: url('../../assets/AIDesign/bg.png');
  background-size: 100% 100%;
  /* 添加半透明黑色背景 */
  // border-radius: 16px;
  /* 圆角边框 */
}

.loading-text {
  margin-top: 10px;
  font-size: 14px;
  color: white;
  white-space: pre-line
    /* 文字颜色改为白色以提高对比度 */
}



.address-info {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 8px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

.project-name {
  margin: 0;
  font-weight: bold;
}

.address {
  margin: 4px 0 0;
  font-size: 12px;
}

.save-button {
  width: 100%;
  padding: 16px;
  margin-top: 20px;
  background-color: #E96337;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.save-button-disabled {
  background-color: #cccccc !important;
  cursor: not-allowed !important;
  color: white !important;
}

/* .save-button:hover {
  background-color: #e04a1d;
} */
.button-group-outside {
  .flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    margin-top: 10px;
  }

  .flex-between {
    display: flex;
    align-items: center;
    border: none;
  }

  .title {
    font-size: 16px;
    color: rgb(23, 23, 23);
    font-weight: 600;
    line-height: 16px;
  }

  .text {
    font-size: 12px;
    color: rgb(134, 144, 156);
    line-height: 12px;
    margin-top: 5px;
  }

  .icon {
    width: 28px;
    height: auto;
    margin-right: 10px;
  }

  .iconbig {
    width: 48px;
    height: auto;
    margin-right: 5px;
  }

  .action-button-big {
    width: 100%;
    height: 72px;
    text-align: center;
    border-radius: 8px;
    background: rgba(248, 243, 204, 1);
  }

  .action-button-middle {
    width: 48%;
    height: 72px;
    border-radius: 8px;
    background: rgba(240, 240, 240, 1);
    margin: 8px 1%;
  }

  .action-button-small {
    width: fit-content;
    margin: 10px auto;
    text-align: center;
    text-decoration: underline;
    font-size: 14px;
    line-height: 18px;

    .text {
      font-size: 14px;
      color: rgb(23, 23, 23);
    }
  }
}

.button-group {
  margin-top: 20px;

  .action-button {
    width: 100%;
    padding: 14px;
    margin-bottom: 12px;
    background-color: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    transition: background-color 0.3s ease;
  }

  .action-button:hover {
    background-color: #f5f5f5;
  }

  .badge-dot {
    margin-left: 10px;
    width: 5px;
    height: 5px;
    background-color: #ff4d4f;
    border-radius: 50%;
  }

  .icon {
    margin-right: 10px;
    font-size: 18px;
  }

  .text {
    font-weight: 500;
  }
}

.image-preview-header{
  flex-direction: column;
  display: flex;
  align-items: center;
}
.van-nav-bar__title {
  font-size: 20px;
  color: #333;
}
</style>