<template xmlns:el-col="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="提醒状态">
        <el-button
          size="mini"
          type="danger"
          @click="handleRemindFilter('overdue')"
        >
          逾期
        </el-button>
        <el-button
          size="mini"
          type="warning"
          @click="handleRemindFilter('urgent')"
        >
          7天内到期
        </el-button>
        <el-button
          size="mini"
          type="primary"
          @click="handleRemindFilter('important')"
        >
          15天内到期
        </el-button>
        <el-button
          size="mini"
          @click="handleRemindFilter('warnin')"
        >
          30天内到期
        </el-button>
      </el-form-item>

      <el-form-item label="店铺名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入店铺名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入店铺电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="isAudit">
        <el-select v-model="queryParams.isAudit" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in isAuditOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="登录帐号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入登录帐号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺Id" prop="storeSeq">
        <el-input
          v-model="queryParams.storeSeq"
          placeholder="请输入店铺Id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家Id" prop="merchantId">
        <el-input
          v-model="queryParams.merchantId"
          placeholder="请输入商家Id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['his:store:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['his:store:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['his:store:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:store:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="storeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="店铺id" align="center" prop="storeId" width="120px"/>-->
        <el-table-column label="商家ID" align="center" prop="merchantId"  width="150px"/>
      <el-table-column label="店铺ID" align="center" prop="storeSeq"  width="150px"/>
      <el-table-column label="店铺名称" align="center" prop="storeName" width="120px"/>
      <el-table-column label="机构全称" align="center" prop="fullName" width="120px"/>
      <el-table-column label="店铺LOGO" align="center" prop="logoUrl" width="100px">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover">
            <img slot="reference" :src="scope.row.logoUrl" width="80px" height="80px">
            <img :src="scope.row.logoUrl" style="max-width: 160px;">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="地址" align="center" prop="address" width="200px"/>
      <el-table-column label="店铺电话" align="center" prop="phone" width="120px"/>
      <el-table-column label="审核状态" align="center" prop="isAudit">
        <template slot-scope="scope">
          <dict-tag :options="isAuditOptions" :value="scope.row.isAudit"/>
        </template>
      </el-table-column>
      <el-table-column label="商品总数" align="center" prop="productCount" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="statusOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="销量" align="center" prop="salesCount" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="累计金额" align="center" prop="totalMoney" />
      <el-table-column label="登录帐号" align="center" prop="account" width="150px" />

      <el-table-column label="上次审核日期" align="center" prop="qualificationUpdateTime" width="150px" />
      <el-table-column label="下次到期日" align="center" prop="nextQualificationUpdateTime" width="150px" />
      <el-table-column label="剩余天数" align="center" prop="daysDiff" width="150px" />
      <el-table-column label="提醒状态（标签）" align="center" prop="daysDiff" width="150px">
        <template slot-scope="scope">
          <el-tag
            v-if="scope.row.daysDiff !== null"
            :type="getRemindTagType(scope.row.daysDiff)"
            size="small"
          >
            {{ getRemindTagName(scope.row.daysDiff) }}
          </el-tag>
          <span v-else>-</span>
        </template>
      </el-table-column>


      <el-table-column label="创建时间" align="center" prop="createTime"  width="150px"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="300px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row, true)"
            v-hasPermi="['his:store:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-promotion"
            @click="handleUpdate(scope.row, false)"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['his:store:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-refresh"
            @click="handleRefresh(scope.row)"
            v-hasPermi="['his:store:refresh']"
          >重置密码</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-promotion"
            @click="handleStoreExport(scope.row)"
          >导出
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改店铺管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" label-position="top" :disabled="isViewMode">

        <el-divider content-position="left">基础信息</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="店铺名称" prop="storeName">
              <el-input v-model="form.storeName" placeholder="请输入店铺名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入店铺电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="企业全称" prop="fullName">
          <el-input v-model="form.fullName" placeholder="请输入企业全称" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="店铺LOGO" prop="logoUrl">
              <el-upload
                v-model="form.logoUrl"
                class="avatar-uploader"
                :action="uploadUrl"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
                :disabled="isDeleting"
              >
                <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                <div class="avatar-wrapper" v-if="form.logoUrl">
                  <img :src="form.logoUrl" class="avatar" width="200px">
                  <!-- 显示删除还是显示放大是更具编辑或者详情来的 -->
<!--                  <div v-if="isViewMode" class="view-mask" @click.stop="previewImage(form.logoUrl)">-->
<!--                    <i class="el-icon-zoom-in"></i>-->
<!--                  </div>-->
<!--                  <div v-else class="delete-mask" @click.stop="handleDeleteLogo">-->
<!--                    <i class="el-icon-delete"></i>-->
<!--                  </div>-->
<!--                  并排显示就好了-->
                  <div class="button-group">
                    <div class="preview-btn" @click.stop="previewImage(form.logoUrl)">
                      <i class="el-icon-zoom-in"></i>
                    </div>
                    <div v-if="!isViewMode" class="delete-btn" @click.stop="handleDeleteLogo">
                      <i class="el-icon-delete"></i>
                    </div>
                  </div>

                </div>
                <!-- 未上传图片时显示的默认图标 -->
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="店铺介绍" prop="descs" >
              <el-input v-model="form.descs" placeholder="请输入店铺介绍" type="textarea" maxlength="100"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属城市" prop="cityIds">
              <el-cascader
                ref="citySelect"
                v-model="form.cityIds"
                :options="citys"
                @change="handleCityChange">
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入地址"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="法人姓名" prop="legalPersonName">
              <el-input v-model="form.legalPersonName" placeholder="请输入法人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码" prop="unifiedSocialCreditCode">
              <el-input v-model="form.unifiedSocialCreditCode" placeholder="请输入统一社会信用代码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="营业范围" prop="businessScope">
          <el-input v-model="form.businessScope" placeholder="请输入营业范围" type="textarea" />
        </el-form-item>

        <!-- 证书上传相关字段 -->
        <el-divider content-position="left">资质证书信息</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="营业执照上传" prop="businessLicense">
              <el-upload
                class="avatar-uploader"
                :action="uploadUrl"
                :show-file-list="false"
                :on-success="(response, file) => handleFileSuccess(response, file, 'businessLicense')"
                :before-upload="beforeAvatarUpload"
                :disabled="isDeleting"
              >
                <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                <div class="avatar-wrapper" v-if="form.businessLicense">
                  <img :src="form.businessLicense" class="avatar" width="200px">
                  <!-- 悬停显示的删除按钮 -->
<!--                  <div class="delete-mask" @click.stop="handleDelete5">-->
<!--                    <i class="el-icon-delete"></i>-->
<!--                  </div>-->
                  <div class="button-group">
                    <div class="preview-btn" @click.stop="previewImage(form.businessLicense)">
                      <i class="el-icon-zoom-in"></i>
                    </div>
                    <div v-if="!isViewMode" class="delete-btn" @click.stop="handleDelete5">
                      <i class="el-icon-delete"></i>
                    </div>
                  </div>
                </div>
                <!-- 未上传图片时显示的默认图标 -->
                <div v-else class="no-image-placeholder">
                  <span v-if="isViewMode">用户未上传</span>
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </div>

              </el-upload>
            </el-form-item>
            <el-col :span="12">
              <el-form-item label="营业执照编号" prop="businessCode" style="margin-left: 5px;margin-bottom: 20px">
                <el-input v-model="form.businessCode" placeholder="请输入营业制造编号" />
              </el-form-item>
            </el-col>

          </el-col>
          <el-col :span="12"></el-col>
          <el-col :span="12">
            <el-form-item label="营业执照是否长期有效" prop="isBusinessLicensePermanent">
              <el-switch
                @change="switchChange()"
                v-model="switchValue"
                active-color="#13ce66"
                inactive-color="#ff4949">
              </el-switch>
             </el-form-item>
            <el-form-item label="营业执照失效日期" prop="businessLicenseExpire" v-if="!switchValue">
              <el-date-picker
                v-model="form.businessLicenseExpire"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="medicalMallConfig.isMedicalMall">
          <el-row>
            <el-col :span="12">
              <el-form-item label="药品经营许可证上传" prop="drugLicense">
                <el-upload
                  class="avatar-uploader"
                  :action="uploadUrl"
                  :show-file-list="false"
                  :on-success="(response, file) => handleFileSuccess(response, file, 'drugLicense')"
                  :before-upload="beforeAvatarUpload"
                  :disabled="isDeleting"
                >
                  <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                  <div class="avatar-wrapper" v-if="form.drugLicense">
                    <img :src="form.drugLicense" class="avatar" width="200px">
                    <!-- 悬停显示的删除按钮 -->
<!--                    <div class="delete-mask" @click.stop="handleDelete6">-->
<!--                      <i class="el-icon-delete"></i>-->
<!--                    </div>-->
                    <div class="button-group">
                      <div class="preview-btn" @click.stop="previewImage(form.drugLicense)">
                        <i class="el-icon-zoom-in"></i>
                      </div>
                      <div v-if="!isViewMode" class="delete-btn" @click.stop="handleDelete6">
                        <i class="el-icon-delete"></i>
                      </div>
                    </div>
                  </div>
                  <!-- 未上传图片时显示的默认图标 -->
                  <div v-else class="no-image-placeholder">
                    <span v-if="isViewMode">用户未上传</span>
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </div>
                </el-upload>
              </el-form-item>

              <el-col :sapn="24">
                <el-form-item label="药品经营许可证范围" prop="drugLicenseBusinessScope" style="margin-left: 5px">
                  <el-input v-model="form.drugLicenseBusinessScope" placeholder="请输入药品经营许可证范围" type="textarea"/>
                </el-form-item>
              </el-col>

              <!-- 新增的单选框 -->
              <el-col :span="24">
                <el-form-item label="药品经营许可证范围是否包含" prop="drugScopeHasFrozen" style="margin-left: 5px">
                  <el-radio-group v-model="form.drugScopeHasFrozen">
                    <el-radio label="0">否</el-radio>
                    <el-radio label="1">冷冻</el-radio>
                    <el-radio label="2">冷藏</el-radio>
                    <el-radio label="3">冷冻冷藏</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <!-- 结束 -->

              <el-col :span="14">
                <el-form-item label="药品经营许可证编号" prop="drugCode" style="margin-left: 5px">
                  <el-input v-model="form.drugCode" placeholder="请输入药品经营许可证编号" />
                </el-form-item>
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-form-item label="药品经营许可证有效期" prop="drugLicenseExpiry">
                <el-date-picker
                  v-model="form.drugLicenseExpiry"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="2类医疗器械备案证书上传" prop="medicalDevice2">
                <el-upload
                  class="avatar-uploader"
                  :action="uploadUrl"
                  :show-file-list="false"
                  :on-success="(response, file) => handleFileSuccess(response, file, 'medicalDevice2')"
                  :before-upload="beforeAvatarUpload"
                  :disabled="isDeleting"
                >
                  <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                  <div class="avatar-wrapper" v-if="form.medicalDevice2">
                    <img :src="form.medicalDevice2" class="avatar" width="200px">
                    <!-- 悬停显示的删除按钮 -->
<!--                    <div class="delete-mask" @click.stop="handleDelete7">-->
<!--                      <i class="el-icon-delete"></i>-->
<!--                    </div>-->
                    <div class="button-group">
                      <div class="preview-btn" @click.stop="previewImage(form.medicalDevice2)">
                        <i class="el-icon-zoom-in"></i>
                      </div>
                      <div v-if="!isViewMode" class="delete-btn" @click.stop="handleDelete7">
                        <i class="el-icon-delete"></i>
                      </div>
                    </div>
                  </div>
                  <!-- 未上传图片时显示的默认图标 -->
                  <div v-else class="no-image-placeholder">
                    <span v-if="isViewMode">用户未上传</span>
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </div>
                </el-upload>
              </el-form-item>

              <el-col :sapn="24">
                <el-form-item label="2类器械经营范围" prop="medicalDevice2BusinessScope" style="margin-left: 5px">
                  <el-input v-model="form.medicalDevice2BusinessScope" placeholder="请输入2类器械经营范围" type="textarea"/>
                </el-form-item>
              </el-col>

              <el-col :span="14">
                <el-form-item label="2类器械生产备案编号" prop="medicalDevice2Code" style="margin-left: 5px">
                  <el-input v-model="form.medicalDevice2Code" placeholder="请输入2类器械生产备案编号" />
                </el-form-item>
              </el-col>
            </el-col>
            <el-col :span="12"></el-col>
            <el-col :span="12">
              <el-form-item label="2类医疗器械备案是否长期有效" prop="isMedicalDevice2ExpiryPermanent">
                <el-switch
                  @change="switchChange()"
                  v-model="medicalDevice2ExpiryValue"
                  active-color="#13ce66"
                  inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
              <el-form-item label="2类医疗器械备案有效期" prop="medicalDevice2Expiry" v-if="!medicalDevice2ExpiryValue">
                <el-date-picker
                  v-model="form.medicalDevice2Expiry"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="3类器械经营许可证上传" prop="medicalDevice3">
                <el-upload
                  class="avatar-uploader"
                  :action="uploadUrl"
                  :show-file-list="false"
                  :on-success="(response, file) => handleFileSuccess(response, file, 'medicalDevice3')"
                  :before-upload="beforeAvatarUpload"
                  :disabled="isDeleting"
                >
                  <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                  <div class="avatar-wrapper" v-if="form.medicalDevice3">
                    <img :src="form.medicalDevice3" class="avatar" width="200px">
                    <!-- 悬停显示的删除按钮 -->
<!--                    <div class="delete-mask" @click.stop="handleDelete2">-->
<!--                      <i class="el-icon-delete"></i>-->
<!--                    </div>-->
                    <div class="button-group">
                      <div class="preview-btn" @click.stop="previewImage(form.medicalDevice3)">
                        <i class="el-icon-zoom-in"></i>
                      </div>
                      <div v-if="!isViewMode" class="delete-btn" @click.stop="handleDelete2">
                        <i class="el-icon-delete"></i>
                      </div>
                    </div>
                  </div>
                  <!-- 未上传图片时显示的默认图标 -->
                  <div v-else class="no-image-placeholder">
                    <span v-if="isViewMode">用户未上传</span>
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </div>
                </el-upload>
              </el-form-item>

              <el-col :sapn="24">
                <el-form-item label="3类器械经营范围" prop="medicalDevice3BusinessScope" style="margin-left: 5px">
                  <el-input v-model="form.medicalDevice3BusinessScope" placeholder="请输入3类器械经营范围" type="textarea"/>
                </el-form-item>
              </el-col>

              <el-form-item label="3类器械生产备案编号" prop="medicalDevice3Code" style="margin-left: 5px">
                <el-input v-model="form.medicalDevice3Code" placeholder="请输入3类器械生产备案编号" />
              </el-form-item>
            </el-col>
            <el-col :span="12"></el-col>
            <el-col :span="12">
              <el-form-item label="3类器械经营许可证有效期" prop="medicalDevice3Expiry">
                <el-date-picker
                  v-model="form.medicalDevice3Expiry"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="食品经营许可证/备案凭证上传" prop="foodLicense">
                <el-upload
                  class="avatar-uploader"
                  :action="uploadUrl"
                  :show-file-list="false"
                  :on-success="(response, file) => handleFoodLicenseSuccess(response, file)"
                  :before-upload="beforeAvatarUpload"
                  :disabled="isDeleting"
                  :limit="3"
                  :on-exceed="handleFoodLicenseExceed"
                >
                  <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                  <div v-if="form.foodLicense && form.foodLicense.length > 0" class="food-license-container">
                    <div v-for="(url, index) in form.foodLicense" :key="index" class="food-license-item">
                      <div class="avatar-wrapper">
                        <img :src="url" class="avatar small-avatar" />
                        <div class="button-group">
                          <div class="preview-btn" @click.stop="previewImage(url)">
                            <i class="el-icon-zoom-in"></i>
                          </div>
                          <div v-if="!isViewMode" class="delete-btn" @click.stop="handleDeleteFoodLicense(index)">
                            <i class="el-icon-delete"></i>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!-- 添加上传按钮，当图片数量少于3张时显示 -->
                    <div v-if="form.foodLicense.length < 3 && !isViewMode" class="avatar-wrapper add-btn small-avatar">
                      <i class="el-icon-plus avatar-uploader-icon"></i>
                    </div>
                  </div>
                  <!-- 未上传图片时显示的默认图标 -->
                  <div v-else class="no-image-placeholder small-placeholder">
                    <span v-if="isViewMode">用户未上传</span>
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </div>
                </el-upload>
              </el-form-item>
              <el-form-item label="食品经营许可证/备案凭证编号" prop="foodCode" style="margin-left: 5px">
                <el-input v-model="form.foodCode" placeholder="请输入食品经营许可证/备案凭证编号" />
              </el-form-item>
            </el-col>
            <el-col :span="12"></el-col>
            <el-col :span="12">
              <el-form-item label="食品经营许可证/备案凭证是否长期有效" prop="isFoodLicenseExpiryPermanent">
                <el-switch
                  @change="switchChange()"
                  v-model="foodLicenseExpiryValue"
                  active-color="#13ce66"
                  inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
              <el-form-item label="食品经营许可证/备案凭证有效期" prop="foodLicenseExpiry" v-if="!foodLicenseExpiryValue">
                <el-date-picker
                  v-model="form.foodLicenseExpiry"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col :sapn="24">
              <el-form-item label="食品经营许可证/备案凭证经营范围" prop="foodLicenseBusinessScope">
                <el-input v-model="form.foodLicenseBusinessScope" placeholder="请输入食品经营许可证/备案凭证经营范围" type="textarea"/>
              </el-form-item>
            </el-col>

          </el-row>
        </div>
        <div v-hasPermi="['his:store:AgreementSigned']">
          <el-divider content-position="left">签署协议与特殊资质信息</el-divider>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="agreement-section">
                <el-form-item label="其它资质-入驻协议">
                  <el-input
                    v-model="form.titleNameOne"
                    placeholder="请输入标题"
                    class="agreement-title"
                  />
                  <el-upload
                    class="file-uploader"
                    :action="uploadUrl"
                    :show-file-list="false"
                    :on-success="(response, file) => handleFileSuccess1(response, file, 'settlementAgreement')"
                    :on-error="handleFileError"
                    :before-upload="beforeFileUpload"
                    :disabled="!!form.settlementAgreement"
                    accept=".jpg,.jpeg,.png,.gif,.doc,.docx,.pdf"
                  >
                    <div v-if="form.settlementAgreement" class="uploaded-file">
                      <img
                        v-if="isImageFile(form.settlementAgreement, 'settlementAgreement')"
                        :src="form.settlementAgreement"
                        class="uploaded-img"
                        width="100px"
                      />
                      <div v-else class="document-icon">
                        <i :class="getDocumentIconClass(form.settlementAgreement, 'settlementAgreement')" class="icon"></i>
                        <span class="file-name">{{ form.settlementAgreementFileName || getFileName(form.settlementAgreement) }}</span>
                      </div>
                      <i class="el-icon-delete delete-icon" @click.stop="handleFileRemove('settlementAgreement')"></i>
                    </div>
                    <div v-else class="upload-btn">
                      <div class="upload-btn-inner">
                        <i class="el-icon-plus"></i>
                        <span class="upload-tip">点击上传</span>
                      </div>
                    </div>
                  </el-upload>

                  <el-form-item prop="settlementAgreementCode">
                    <el-input
                      v-model="form.settlementAgreementCode"
                      placeholder="请输入备注内容"
                    />
                  </el-form-item>

                  <el-form-item label="协议是否长期有效" prop="isEffectivePermanent1">
                    <el-switch
                      @change="switchChange()"
                      v-model="medicalLicenseExpiryValue1"
                      active-color="#13ce66"
                      inactive-color="#ff4949">
                    </el-switch>
                  </el-form-item>

                  <el-form-item
                    label="协议有效期"
                    prop="medicalLicenseExpiry"
                    v-if="!medicalLicenseExpiryValue1"
                  >
                    <el-date-picker
                      v-model="form.settlementAgreementExpiry"
                      type="daterange"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期" style="width: 100%">
                    </el-date-picker>
                  </el-form-item>
                </el-form-item>
              </div>
            </el-col>

            <el-col :span="8">
              <div class="agreement-section">
                <el-form-item label="质量保证协议">
                  <el-input
                    v-model="form.titleNameTwo"
                    placeholder="请输入标题"
                    class="agreement-title"
                  />
                  <el-upload
                    class="file-uploader"
                    :action="uploadUrl"
                    :show-file-list="false"
                    :on-success="(response, file) => handleFileSuccess1(response, file, 'qualityAssuranceAgreement')"
                    :on-error="handleFileError"
                    :before-upload="beforeFileUpload"
                    :disabled="!!form.qualityAssuranceAgreement"
                    accept=".jpg,.jpeg,.png,.gif,.doc,.docx,.pdf"
                  >
                    <div v-if="form.qualityAssuranceAgreement" class="uploaded-file">
                      <img
                        v-if="isImageFile(form.qualityAssuranceAgreement, 'qualityAssuranceAgreement')"
                        :src="form.qualityAssuranceAgreement"
                        class="uploaded-img"
                        width="100px"
                      />
                      <div v-else class="document-icon">
                        <i :class="getDocumentIconClass(form.qualityAssuranceAgreement, 'qualityAssuranceAgreement')" class="icon"></i>
                        <span class="file-name">{{ form.qualityAssuranceAgreementFileName || getFileName(form.qualityAssuranceAgreement) }}</span>
                      </div>
                      <i class="el-icon-delete delete-icon" @click.stop="handleFileRemove('qualityAssuranceAgreement')"></i>
                    </div>
                    <div v-else class="upload-btn">
                      <div class="upload-btn-inner">
                        <i class="el-icon-plus"></i>
                        <span class="upload-tip">点击上传</span>
                      </div>
                    </div>
                  </el-upload>

                  <el-form-item prop="qualityAssuranceAgreementCode">
                    <el-input
                      v-model="form.qualityAssuranceAgreementCode"
                      placeholder="请输入备注内容"
                    />
                  </el-form-item>

                  <el-form-item label="协议是否长期有效" prop="isEffectivePermanent2">
                    <el-switch
                      @change="switchChange()"
                      v-model="medicalLicenseExpiryValue2"
                      active-color="#13ce66"
                      inactive-color="#ff4949">
                    </el-switch>
                  </el-form-item>

                  <el-form-item
                    label="协议有效期"
                    prop="medicalLicenseExpiry"
                    v-if="!medicalLicenseExpiryValue2"
                  >
                    <el-date-picker
                      v-model="form.qualityAssuranceAgreementExpiry"
                      type="daterange"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期" style="width: 100%">
                    </el-date-picker>
                  </el-form-item>
                </el-form-item>
              </div>
            </el-col>

            <el-col :span="8">
              <div class="agreement-section">
                <el-form-item label="其它特殊资质">
                  <el-input
                    v-model="form.titleNameThree"
                    placeholder="请输入标题"
                    class="agreement-title"
                  />
                  <el-upload
                    class="file-uploader"
                    :action="uploadUrl"
                    :show-file-list="false"
                    :on-success="(response, file) => handleFileSuccess1(response, file, 'otherSpecialQualification')"
                    :on-error="handleFileError"
                    :before-upload="beforeFileUpload"
                    :disabled="!!form.otherSpecialQualification"
                    accept=".jpg,.jpeg,.png,.gif,.doc,.docx,.pdf"
                  >
                    <div v-if="form.otherSpecialQualification" class="uploaded-file">
                      <img
                        v-if="isImageFile(form.otherSpecialQualification, 'otherSpecialQualification')"
                        :src="form.otherSpecialQualification"
                        class="uploaded-img"
                        width="100px"
                      />
                      <div v-else class="document-icon">
                        <i :class="getDocumentIconClass(form.otherSpecialQualification, 'otherSpecialQualification')" class="icon"></i>
                        <span class="file-name">{{ form.otherSpecialQualificationFileName || getFileName(form.otherSpecialQualification) }}</span>
                      </div>
                      <i class="el-icon-delete delete-icon" @click.stop="handleFileRemove('otherSpecialQualification')"></i>
                    </div>
                    <div v-else class="upload-btn">
                      <div class="upload-btn-inner">
                        <i class="el-icon-plus"></i>
                        <span class="upload-tip">点击上传</span>
                      </div>
                    </div>
                  </el-upload>

                  <el-form-item prop="otherSpecialQualificationCode">
                    <el-input
                      v-model="form.otherSpecialQualificationCode"
                      placeholder="请输入备注内容"
                    />
                  </el-form-item>

                  <el-form-item label="协议是否长期有效" prop="isEffectivePermanent3">
                    <el-switch
                      @change="switchChange()"
                      v-model="medicalLicenseExpiryValue3"
                      active-color="#13ce66"
                      inactive-color="#ff4949">
                    </el-switch>
                  </el-form-item>

                  <el-form-item
                    label="协议有效期"
                    prop="medicalLicenseExpiry"
                    v-if="!medicalLicenseExpiryValue3"
                  >
                    <el-date-picker
                      v-model="form.otherSpecialQualificationExpiry"
                      type="daterange"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期" style="width: 100%">
                    </el-date-picker>
                  </el-form-item>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </div>
        <el-divider content-position="left">店铺配置信息</el-divider>
        <el-col :span="12">
          <el-form-item label="网销报告" prop="reportUrl">
            <el-upload
              class="upload-demo"
              :action="uploadUrl"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :limit="1"
              :on-exceed="handleExceed"
              :on-success="(response, file) => handleFileSuccess(response, file, 'reportUrl')"
              :file-list="reportFileList">
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备案" prop="filingUrl">
            <el-upload
              class="upload-demo"
              :action="uploadUrl"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :on-success="(response, file) => handleFileSuccess(response, file, 'filingUrl')"
              multiple
              :limit="1"
              :on-exceed="handleExceed"
              :file-list="fileList">
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-form-item label="退货地址" prop="refundAddress">
          <el-input v-model="form.refundAddress" placeholder="请输入退货地址" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="退货电话" prop="refundPhone">
              <el-input v-model="form.refundPhone" placeholder="请输入退货电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="退货收货人" prop="refundConsignee">
              <el-input v-model="form.refundConsignee" placeholder="请输入退货收货人" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="寄件人电话" prop="sendPhone">
          <el-input v-model="form.sendPhone" placeholder="请输入寄件人电话" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商品总数" prop="productCount">
              <el-input-number v-model="form.productCount"  :min="0" label="描述文字"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="销量" prop="salesCount">
              <el-input-number v-model="form.salesCount"  :min="0" label="描述文字"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="累计金额" prop="totalMoney">
              <el-input-number v-model="form.totalMoney" :precision="2" :step="0.1"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="parseInt(dict.dictValue)"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分佣方式" prop="brokerageType" >
              <el-radio v-model="form.brokerageType" label="1">每盒</el-radio>
              <el-radio v-model="form.brokerageType" label="2">总价</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="配送方式" prop="shippingType">
          <el-checkbox-group v-model="form.shippingType" size="medium">
            <el-checkbox v-for="(item, index) in shippingTypeOptions" :key="index" :label="item.value"
                         :disabled="item.disabled">{{item.label}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>

        <el-divider content-position="left">登录信息</el-divider>
        <el-form-item label="登录帐号" prop="account" v-if="title != '修改店铺管理'">
          <el-input v-model="form.account" placeholder="请输入登录帐号" />
        </el-form-item>
        <!--        tips-->
        <span class="tip-text" v-if="title !== '修改店铺管理'">请及时修改密码,初试密码XyzAbc~12</span>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="!isViewMode" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">{{ isViewMode ? '关 闭' : '取 消' }}</el-button>
      </div>
    </el-dialog>

    <!-- 修改图片预览对话框，增加更大的预览尺寸 -->
    <el-dialog :visible.sync="imagePreviewVisible" width="1100px" append-to-body :modal-append-to-body="false" @close="imagePreviewVisible = false">
      <img :src="previewImageUrl" style="width: 100%; height: auto; max-height: 700px; object-fit: contain;" />
    </el-dialog>


    <el-dialog
      title="店铺资质消息提示"
      :visible.sync="dialogVisible"
      width="40%"
      center>
      <div v-for="(item,index) in promptList">({{index+1}})、{{item}}</div>
      <span slot="footer" class="dialog-footer">
       <el-button type="primary" @click="dialogVisible = false">已 知 晓</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { listStore, getStore, delStore, addStore, updateStore, exportStore, refreshPasWod,exportFsStream, businessLicenseCheck} from '@/api/hisStore/store'
import storeDetails from '../components/storeDetails.vue';
import StoreDialog from '../components/StoreDialog.vue';
import {getCitys} from "@/api/store/city";
import { getConfigByKey } from '@/api/system/config'
import { qualifications } from '@/api/system/user';
export default {
  name: "Store",
  components: { storeDetails, StoreDialog },
  data() {
    return {
      reportFileList:[],
      fileList:[],
      previewImageUrl: '', // 添加预览图片URL
      imagePreviewVisible: false,// 添加图片预览对话框可见性控制
      // 新增：控制LOGO上传组件禁用状态
      isDeleting: false,
      promptList:[],
      dialogVisible: false,
      // 控制是否为查看模式（只读）
      isViewMode: false,
      // 店铺对话框相关
      storeDialogVisible: false,
      storeDialogMode: 'add', // add, edit, detail
      currentStoreData: {},
      auditLogs: [],
      switchValue:false,
      switchMedicalValue:false,
      medicalDevice2ExpiryValue:false,
      medicalLicenseExpiryValue:false,
      foodLicenseExpiryValue:false,
      medicalLicenseExpiryValue1:false,//协议有效期控制
      medicalLicenseExpiryValue2:false,//协议有效期控制
      medicalLicenseExpiryValue3:false,//协议有效期控制
      shippingType: [],
      medicalMallConfig:{},
      citys: [],
      licenseuploadUrl: process.env.VUE_APP_BASE_API + "/common/uploadOSS",
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/uploadOSS",
      baseUrl: process.env.VUE_APP_BASE_API,
      shippingTypeOptions: [{
        "label": "配送",
        "value": "1"
      }, {
        "label": "自提",
        "value": "2"
      }, {
        "label": "配送自提",
        "value": "3"
      }],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺管理表格数据
      storeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      statusOptions: [],
      // 审核状态字典
      isAuditOptions: [],
      deliveryTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeName: null,
        address: null,
        phone: null,
        status: null,
        isAudit: null,
        account: null,
        daysDiffMin: null, // 添加最小剩余天数查询条件
        daysDiffMax: null  // 添加最大剩余天数查询条件
      },
      // 表单参数
      form: {
        medicalDevice3BusinessScope: null,
        medicalDevice2BusinessScope: null,
        settlementAgreementFileType: '', // 入驻协议文件类型（如 application/pdf）
        qualityAssuranceAgreementFileType: '', // 质量保证协议文件类型
        otherSpecialQualificationFileType: '', // 其他特殊资质文件类型
        settlementAgreement: null,
        settlementAgreementFileName: null, // 新增：存储文件名
        qualityAssuranceAgreement: null,
        qualityAssuranceAgreementFileName: null, // 新增：存储文件名
        otherSpecialQualification: null,
        otherSpecialQualificationFileName: null, // 新增：存储文件名
        foodLicense: [], // 食品经营许可证/备案凭证上传（支持多张图片）

      },
      // 表单校验
      rules: {
        drugLicenseBusinessScope: [
          { required: true, message: "药品经营许可证范围不能为空", trigger: "blur" }
        ],
        // 添加新的验证规则
        drugScopeHasFrozen: [
          { required: true, message: "请选择药品经营许可证范围是否包含冷冻/冷藏", trigger: "change" }
        ],
        storeName: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" }
        ],
        fullName: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" }
        ],
        businessLicenseExpire: [
          { required: true, message: "营业执照失效日期不能为空", trigger: "blur" }
        ],
        businessLicense: [
          { required: true, message: "营业执照不能为空", trigger: "blur" }
        ],
        businessCode:[
          { required: true, message: "营业执照编号不能为空", trigger: "blur" }
        ],
        drugLicense: [
          { required: true, message: "药品经营许可证不能为空", trigger: "blur" }
        ],
        drugCode:[
          { required: true, message: "药品经营许可证编号不能为空", trigger: "blur" }
        ],
        drugLicenseExpiry: [
          { required: true, message: "药品经营许可证有效期不能为空", trigger: "blur" }
        ],
        // medicalDevice3: [
        //   { required: true, message: "3类器械经营许可证不能为空", trigger: "blur" }
        // ],
        // medicalDevice3Code: [
        //   { required: true, message: "3类器械生产备案编号不能为空", trigger: "blur" }
        // ],
        // medicalDevice3Expiry: [
        //   { required: true, message: "3类器械经营许可证有效期不能为空", trigger: "blur" }
        // ],
        // foodLicense: [
        //   {
        //     validator: (rule, value, callback) => {
        //       if (!value || (Array.isArray(value) && value.length === 0)) {
        //         callback(new Error('请至少上传一张食品经营许可证图片'));
        //       } else {
        //         callback();
        //       }
        //     },
        //     trigger: 'change'
        //   }
        // ],
        // foodCode: [
        //   { required: true, message: "食品经营许可证编号不能为空", trigger: "blur" }
        // ],
        // foodLicenseExpiry: [
        //   { required: true, message: "食品经营许可证有效期不能为空", trigger: "blur" }
        // ],
        logoUrl: [
          { required: true, message: "店铺LOGO不能为空", trigger: "blur" }
        ],
        cityIds: [
          { required: true, message: "所属城市不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],
        licenseImages: [
          { required: true, message: "资质证书不能为空", trigger: "blur" }
        ],
        shippingType: [
          { required: true, message: "配送方式不能为空", trigger: "blur" }
        ],
        account: [
          { required: true, message: "登录账号不能为空", trigger: "blur" }
        ],
        brokerageType: [
          { required: true, message: "分佣方式不能为空", trigger: "blur" }
        ],
        refundPhone: [
          { required: true, message: "退货电话不能为空", trigger: "blur" }
        ],
        refundAddress: [
          { required: true, message: "退货地址不能为空", trigger: "blur" }
        ],
        refundConsignee: [
          { required: true, message: "退货收货人不能为空", trigger: "blur" }
        ],
        sendPhone: [
          { required: true, message: "寄件人电话不能为空", trigger: "blur" },
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
            required: true
          }
        ],
        // 新增字段校验规则
        enterpriseShortName: [
          { required: true, message: "企业简称不能为空", trigger: "blur" }
        ],
        enterpriseFullName: [
          { required: true, message: "企业全称不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "电话号码不能为空", trigger: "blur" }
        ],
        enterpriseAddress: [
          { required: true, message: "企业地址不能为空", trigger: "blur" }
        ],
        legalPersonName: [
          { required: true, message: "法人姓名不能为空", trigger: "blur" }
        ],
        unifiedSocialCreditCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        businessScope: [
          { required: true, message: "营业范围不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "新密码不能为空", trigger: "blur" },
          { min: 6, max: 20, message: "长度在 6 到 20 个字符", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getCitys();
    this.getList();
    getConfigByKey("medicalMall.func.switch").then(response => {
      if(response.data && response.data.configValue) {
        this.medicalMallConfig = JSON.parse(response.data.configValue);
      }
    });
    this.getDicts("sys_company_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_company_isaudit").then(response => {
      this.isAuditOptions = response.data;
    });
    this.getDicts("sys_store_delivery_type").then(response => {
      this.deliveryTypeOptions = response.data;
    });
    this.$nextTick(()=>{
      console.log("是否执行资质提示方法")
      this.handleNoticeInfo();
    })
  },
  methods: {
    // 处理提醒状态筛选
    handleRemindFilter(type) {
      // 重置其他查询条件
      this.resetForm("queryForm");
      // 根据不同类型设置查询参数
      switch (type) {
        case 'overdue': // 严重逾期
          this.queryParams.daysDiffMin = null;
          this.queryParams.daysDiffMax = 0;
          break;
        case 'urgent': // 紧急提醒 (7天内)
          this.queryParams.daysDiffMin = 0;
          this.queryParams.daysDiffMax = 7;
          break;
        case 'important': // 重点提醒 (15天内)
          this.queryParams.daysDiffMin = 0;
          this.queryParams.daysDiffMax = 15;
          break;
        case 'warning': // 常规预警 (30天内)
          this.queryParams.daysDiffMin = 0;
          this.queryParams.daysDiffMax = 30;
          break;
        default: // 默认情况，清空条件
            this.queryParams.daysDiffMin = null;
            this.queryParams.daysDiffMax = null;
          break;
      }
      this.handleQuery();
    },
    // 获取提醒标签类型
    getRemindTagType(daysDiff) {
      if (daysDiff < 0) {
        return 'danger'; // 严重逾期 - 红色
      } else if (daysDiff <= 7) {
        return 'warning'; // 紧急提醒 - 橙色
      } else if (daysDiff <= 15) {
        return ''; // 重点提醒 - 黄色 (Element UI 中空字符串是黄色)
      } else if (daysDiff <= 30) {
        return 'primary'; // 常规预警 - 蓝色 (Element UI 中 primary 是蓝色)
      }
      return 'info'; // 其他情况 - 灰色
    },
    // 获取提醒标签名称
    getRemindTagName(daysDiff) {
      if (daysDiff < 0) {
        return '逾期';
      } else if (daysDiff <= 7) {
        return '7天内到期';
      } else if (daysDiff <= 15) {
        return '15天内到期';
      } else if (daysDiff <= 30) {
        return '30天内到期';
      }
      return '正常';
    },
    // 添加图片预览方法
    previewImage(url) {
      this.previewImageUrl = url;
      this.imagePreviewVisible = true;
    },
    handleNoticeInfo() {
      qualifications()
        .then(response => {
          console.log("noticeInfo接口完整响应：", response);
          if (response.code === 200) {
            this.promptList = response.data;
            if (this.promptList && this.promptList.length > 0) {
              this.dialogVisible = true;
            }
            console.log("通知信息请求完成！", this.promptList);
          } else {
            console.warn("接口返回非成功状态：", response.code);
          }
        })
        .catch(err => {
          console.error("获取通知信息失败：", err);
          this.$message.error("加载通知信息失败，请稍后重试");
        });
    },
    // 在 methods 中添加新的方法
    checkBusinessLicense(imageUrl) {
      if (!imageUrl) return;
      // 使用正确的参数格式调用接口
      businessLicenseCheck(imageUrl).then(response => {
        if (response.code === 200) {
          if (!response.data.flag) {
            // 检查失败，显示错误信息
            this.$message.error(response.data.message || '营业执照校验失败');
            // 清除刚上传的图片
            this.form.businessLicense = '';
            this.$forceUpdate();
          }else {
            // 检查成功，回填数据
            this.form.legalPersonName = response.data.person; // 法人姓名
            this.form.unifiedSocialCreditCode = response.data.regNum; // 统一社会信用代码
            this.form.businessScope = response.data.businessStr; // 营业范围
            this.form.businessCode = response.data.regNum; // 营业执照编号
          }
        } else {
          this.$message.error('营业执照校验接口调用失败');
        }
      }).catch(error => {
        console.error('营业执照校验失败:', error);
        this.$message.error('营业执照校验失败');
      });
    },
    handleCityChange(value) {
      var nodes = this.$refs.citySelect.getCheckedNodes();
      this.form.address = nodes[0].pathLabels[0] + nodes[0].pathLabels[1] + nodes[0].pathLabels[2];
      this.form.cityIds = value.toString();
    },
    getCitys() {
      getCitys().then(res => {
        this.loading = false;
        this.citys = res.data;
      })
    },

    licensehandleAvatarSuccess(res, file) {
      if (res.code === 200) {
        this.form.licenseImages = res.url;
        this.$forceUpdate()
      } else {
        this.msgError(res.msg);
      }
    },
    handleAvatarSuccess(res, file) {
      if (res.code === 200) {
        this.form.logoUrl = res.url;
        this.$forceUpdate()
      } else {
        this.msgError(res.msg);
      }
    },
    beforeAvatarUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 1;
      if (!isLt1M) {
        this.$message.error('上传图片大小不能超过 1MB!');
      }
      return isLt1M;
    },
    handleBizLicenseSuccess(res, file) {
      if (res.code === 200) {
        this.form.bizLicense = res.url;
        this.$forceUpdate()
      } else {
        this.msgError(res.msg);
      }
    },
    beforeBizLicenseUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 5;
      if (!isLt1M) {
        this.$message.error('上传图片大小不能超过 5MB!');
      }
      return isLt1M;
    },

    // 通用文件上传成功处理函数
    handleFileSuccess(response, file, field) {
      if (response.code === 200) {
        this.$set(this.form, field, response.url);
        this.$forceUpdate();
        // 如果是营业执照上传，则进行检查
        if (field === 'businessLicense') {
          this.checkBusinessLicense(response.url);
        }
      } else {
        this.msgError(response.msg);
      }
    },
    // 食品经营许可证上传成功处理函数
    handleFoodLicenseSuccess(response, file) {
      if (response.code === 200) {
        // 初始化数组（如果尚未初始化）
        if (!Array.isArray(this.form.foodLicense)) {
          this.$set(this.form, 'foodLicense', []);
        }
        // 添加新上传的图片URL到数组中
        this.form.foodLicense.push(response.url);
        this.$forceUpdate();
      } else {
        this.msgError(response.msg);
      }
    },
    // 食品经营许可证上传超出限制处理函数
    handleFoodLicenseExceed(files, fileList) {
      this.$message.warning(`当前最多只能上传 3 张图片`);
    },

    /** 查询店铺管理列表 */
    getList() {
      this.loading = true;
      listStore(this.queryParams).then(response => {
        this.storeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.switchValue = false;
      this.switchMedicalValue=false;
      // 重置时确保isDeleting为false
      this.isDeleting = false;
      this.form = {
        storeId: null,
        cityIds: null,
        storeName: null,
        descs: null,
        logoUrl: null,
        address: null,
        lng: null,
        lat: null,
        phone: null,
        licenseImages: null,
        productCount: null,
        status: 0,
        createTime: null,
        updateTime: null,
        salesCount: null,
        balance: null,
        totalMoney: null,
        isAudit: 0,
        account: null,
        password: null,
        shippingType: ["1"],
        brokerageType: "1",
        brokerageRate: 0,
        fullName: null,
        // 重置新增字段
        enterpriseShortName: null,        // 企业简称
        enterpriseFullName: null,         // 企业全称
        contactPhone: null,               // 联系电话
        enterpriseAddress: null,          // 企业地址
        legalPersonName: null,            // 法人姓名
        unifiedSocialCreditCode: null,    // 统一社会信用代码
        businessScope: null,              // 营业范围
        // 重置证书相关字段
        businessLicense: null,                    // 营业执照文件
        businessLicenseExpire: null,              // 营业执照失效日期
        drugLicense: null,             // 药品经营许可证有效期
        drugLicenseExpiry: null,               // 药品经营许可证文件
        // 医疗器械相关证书
        medicalDevice1: null,          // 一类医疗器械备案证书
        medicalDevice1Expiry: null,        // 二类医疗器械备案有效期
        medicalDevice2: null,          // 二类器械生产备案文件
        medicalDevice2Expiry: null,        // 一类生产备案有效期
        medicalDevice3: null,         // 三类器械经营许可证文件
        medicalDevice3Expiry: null,       // 三类器械经营许可证有效期
        // 其他许可证相关字段
        foodLicense: [],               // 食品经营许可证文件（支持多张图片）
        foodLicenseExpiry: null,             // 食品经营许可证有效期
        medicalLicense: null,  // 医疗机构执业许可证文件
        medicalLicenseExpiry: null, // 医疗机构执业许可证有效期
        settlementAgreement: null,  //其它资质-入驻协议
        settlementAgreementFileName: null,
        qualityAssuranceAgreementFileName: null, // 新增：质量保证协议文件名
        otherSpecialQualificationFileName: null,// 新增：其他特殊资质文件名
        settlementAgreementExpiry: null,//其它资质-有效期
        qualityAssuranceAgreement: null,//质量保证协议
        qualityAssuranceAgreementExpiry: null,//质量保证协议有效期
        otherSpecialQualification: null,//其它特殊资质
        otherSpecialQualificationExpiry: null,//其它特殊资质有效期
        businessCode: null,
        drugLicenseBusinessScope:null,
        drugScopeHasFrozen: null,
        drugCode:null,
        medicalDevice1Code:null,
        medicalDevice2Code:null,
        medicalDevice3Code:null,
        foodCode:null,
        medicalCode:null,
        otherSpecialQualificationCode:null,
        qualityAssuranceAgreementCode:null,
        settlementAgreementCode: null,
        titleNameOne: null,
        titleNameTwo: null,
        titleNameThree: null,
        settlementAgreementFileType: '',
        qualityAssuranceAgreementFileType: '',
        otherSpecialQualificationFileType: ''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.daysDiffMin = null;
      this.queryParams.daysDiffMax = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.storeId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.isViewMode = false; // 新增时可编辑
      this.open = true;
      this.title = "添加店铺";

    },
    // 修复LOGO删除逻辑：确保删除后可重新上传
    handleDeleteLogo() {
      this.deleteImage('logoUrl', 'Logo');
    },
    handleDelete2() {
      this.deleteImage('medicalDevice3', '3类器械经营许可证');
    },
    // 删除指定索引的食品经营许可证图片
    handleDeleteFoodLicense(index) {
      this.$confirm(`确定要删除这张食品经营许可证图片吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.form.foodLicense.splice(index, 1);
        this.$message.success('图片已删除');
        this.$forceUpdate();
      }).catch(() => {
        this.$message.info('已取消删除');
      });
    },
    handleDelete5() {
      this.deleteImage('businessLicense', '营业执照');
    },
    handleDelete6() {
      this.deleteImage('drugLicense', '药品经营许可证');
    },
    handleDelete7() {
      this.deleteImage('medicalDevice2', '2类医疗器械备案证书');
    },
    // 通用图片删除方法
    deleteImage(field, itemType) {
      this.isDeleting = true; // 临时禁用上传组件
      this.$confirm(`确定要删除这张${itemType}吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.form[field] = ''; // 清空图片URL
        this.$message.success(`${itemType}已删除`);
      }).catch(() => {
        this.$message.info('已取消删除');
      }).finally(() => {
        this.isDeleting = false; // 无论操作结果，恢复上传组件可用
        this.$forceUpdate(); // 强制刷新确保状态同步
      });
    },
    /** 修改/详情按钮操作 */
    handleUpdate(row, isEdit = true) {
      this.reset();
      this.isViewMode = !isEdit; // 设置是否为查看模式
      const storeId = row.storeId || this.ids
      getStore(storeId).then(response => {
        this.form = response.data;
        // 如果后端返回的数据中没有这个字段，则设置默认值
        if (this.form.drugScopeHasFrozen === undefined) {
          this.form.drugScopeHasFrozen = null;
        }
        if(this.form.isBusinessLicensePermanent == 1){
          this.switchValue = true;
        }
        if(this.form.isMedicalDevice1ExpiryPermanent == 1){
          this.switchMedicalValue = true;
        }
        if(this.form.isMedicalDevice2ExpiryPermanent == 1){
          this.medicalDevice2ExpiryValue = true;
        }
        if(this.form.isMedicalLicenseExpiryPermanent == 1){
          this.medicalLicenseExpiryValue = true;
        }
        if(this.form.isEffectivePermanent1 == 1){
          this.medicalLicenseExpiryValue1 = true;
        }
        if(this.form.isFoodLicenseExpiryPermanent == 1){
          this.foodLicenseExpiryValue = true;
        }
        if(this.form.isEffectivePermanent2 == 1){
          this.medicalLicenseExpiryValue2 = true;
        }
        if(this.form.isEffectivePermanent3 == 1){
          this.medicalLicenseExpiryValue3 = true;
        }
        this.open = true;
        this.title = this.isViewMode ? "店铺详情" : "修改店铺";

        let str = this.form.shippingType
        this.form.shippingType = str.split(",")
        this.form.cityIds = ((this.form.cityIds).split(",")).map(Number)

        const dateFields = [
          'drugLicenseExpiry',
          'medicalDevice1Expiry',
          'medicalDevice2Expiry',
          'medicalDevice3Expiry',
          'foodLicenseExpiry',
          'medicalLicenseExpiry',
          'businessLicenseExpire'
        ];
        dateFields.forEach(field => {
          const startField = field + 'Start';
          const endField = field + 'End';
          if (this.form[startField] && this.form[endField]) {
            this.$set(this.form, field, [this.form[startField], this.form[endField]]);
          }
        });


        // 入驻协议有效期
        if (this.form.settlementAgreementStart && this.form.settlementAgreementEnd) {
          this.$set(this.form, 'settlementAgreementExpiry', [
            this.form.settlementAgreementStart,
            this.form.settlementAgreementEnd
          ]);
        }

        // 质量保证协议有效期
        if (this.form.qualityAssuranceAgreementStart && this.form.qualityAssuranceAgreementEnd) {
          this.$set(this.form, 'qualityAssuranceAgreementExpiry', [
            this.form.qualityAssuranceAgreementStart,
            this.form.qualityAssuranceAgreementEnd
          ]);
        }
        // 其它特殊资质有效期
        if (this.form.otherSpecialQualificationStart && this.form.otherSpecialQualificationEnd) {
          this.$set(this.form, 'otherSpecialQualificationExpiry', [
            this.form.otherSpecialQualificationStart,
            this.form.otherSpecialQualificationEnd
          ]);
        }
        this.reportFileList = this.urlToFileList(this.form.reportUrl);
        this.fileList = this.urlToFileList(this.form.filingUrl);

        // 处理食品经营许可证图片数据，支持逗号分隔的字符串
        if (this.form.foodLicense) {
          if (typeof this.form.foodLicense === 'string') {
            // 如果是逗号分隔的字符串，则分割成数组
            this.form.foodLicense = this.form.foodLicense.split(',').filter(url => url.trim() !== '');
          } else if (!Array.isArray(this.form.foodLicense)) {
            // 如果既不是字符串也不是数组，则初始化为空数组
            this.form.foodLicense = [];
          }
        } else {
          // 如果为空，则初始化为空数组
          this.form.foodLicense = [];
        }
      });
    },
    // 验证所有执照有效性验证方法
    validateLicenses() {
      // 验证营业执照
      if (!this.validateSingleLicense(!this.switchValue, this.form.businessLicenseExpire, "营业执照")) {
        return false;
      }
      // 验证2类医疗器械备案
      if (!this.validateSingleLicense(!this.medicalDevice2ExpiryValue, this.form.medicalDevice2Expiry, "2类医疗器械备案")) {
        return false;
      }
      // 验证食品经营许可证/备案凭证
      if (!this.validateSingleLicense(!this.foodLicenseExpiryValue, this.form.foodLicenseExpiry, "食品经营许可证/备案凭证")) {
        return false;
      }
      // 验证药品经营许可证（无长期有效开关，直接检查有效期）
      if (!this.validateLicenseWithoutSwitch(this.form.drugLicenseExpiry, "药品经营许可证")) {
        return false;
      }
      // 验证3类器械经营许可证（无长期有效开关，直接检查有效期）
      if (!this.validateLicenseWithoutSwitch(this.form.medicalDevice3Expiry, "3类器械经营许可证")) {
        return false;
      }
      return true;
    },
    // 验证单个执照的方法（适用于有长期有效开关的证件）
    validateSingleLicense(isExpiryRequired, expiryDateRange, licenseName) {
      // 如果不是长期有效，检查是否过期
      if (isExpiryRequired) {
        // 检查是否设置了有效期
        if (!expiryDateRange || expiryDateRange.length !== 2) {
          this.$message.warning(`请设置${licenseName}的有效期！`);
          return false;
        }
        // 获取结束日期
        const endDate = new Date(expiryDateRange[1]);
        // 获取当前日期
        const currentDate = new Date();
        // 比较日期（忽略时间部分）
        endDate.setHours(0, 0, 0, 0);
        currentDate.setHours(0, 0, 0, 0);
        // 如果结束日期早于当前日期，说明已过期
        if (endDate < currentDate) {
          this.$message.warning(`${licenseName}已过期，请更新${licenseName}有效期时间或设置为长期有效！`);
          return false;
        }
      }
      return true;
    },
    // 验证无开关控制的证件有效期
    validateLicenseWithoutSwitch(expiryDateRange, licenseName) {
      // 检查是否设置了有效期
      if (!expiryDateRange || expiryDateRange.length !== 2) {
        this.$message.warning(`请设置${licenseName}的有效期！`);
        return false;
      }
      // 获取结束日期
      const endDate = new Date(expiryDateRange[1]);
      // 获取当前日期
      const currentDate = new Date();
      // 比较日期（忽略时间部分）
      endDate.setHours(0, 0, 0, 0);
      currentDate.setHours(0, 0, 0, 0);
      // 如果结束日期早于当前日期，说明已过期
      if (endDate < currentDate) {
        this.$message.warning(`${licenseName}已过期，请更新${licenseName}有效期时间！`);
        return false;
      }
      return true;
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 添加所有执照有效性检查
          if (!this.validateLicenses()) {
            return; // 验证失败，停止提交
          }
          // 处理表单数据
          const formData = Object.assign({}, this.form);
          // 处理城市ID
          if (formData.cityIds) {
            formData.cityIds = formData.cityIds.toString();
          }
          // 处理配送方式
          if (formData.shippingType) {
            formData.shippingType = formData.shippingType.toString();
          }
          // 处理日期范围字段
          const dateRangeFields = [
            'drugLicenseExpiry',
            'medicalDevice2Expiry',
            'medicalDevice1Expiry',
            'medicalDevice3Expiry',
            'foodLicenseExpiry',
            'medicalLicenseExpiry',
            'businessLicenseExpire'
          ];
          dateRangeFields.forEach(field => {
            if (formData[field] && formData[field].length === 2) {
              formData[`${field}Start`] = formData[field][0];
              formData[`${field}End`] = formData[field][1];
            }
          });

          //其他执照处理
          const agreementFields = [
            {
              expiryField: 'settlementAgreementExpiry',
              startField: 'settlementAgreementStart',
              endField: 'settlementAgreementEnd',
              message: '其它资质-入驻协议，有效期开始日期或结束日期不能为空！'
            },
            {
              expiryField: 'qualityAssuranceAgreementExpiry',
              startField: 'qualityAssuranceAgreementStart',
              endField: 'qualityAssuranceAgreementEnd',
              message: '质量保证协议，有效期开始日期或结束日期不能为空！'
            },
            {
              expiryField: 'otherSpecialQualificationExpiry',
              startField: 'otherSpecialQualificationStart',
              endField: 'otherSpecialQualificationEnd',
              message: '其它特殊资质，有效期开始日期或结束日期不能为空！'
            }
          ];

          for (const field of agreementFields) {
            if (formData[field.expiryField] && formData[field.expiryField].length === 2) {
              formData[field.startField] = formData[field.expiryField][0];
              formData[field.endField] = formData[field.expiryField][1];
            } else {
              if (formData[field.expiryField.replace('Expiry', '')] != null) {
                return this.$message.warning(field.message);
              }
            }
          }

          // 处理各类许可证是否永久有效的开关状态
          formData.isFoodLicenseExpiryPermanent = this.foodLicenseExpiryValue ? 1 : 0;
          formData.isBusinessLicensePermanent = this.switchValue ? 1 : 0;
          formData.isMedicalDevice1ExpiryPermanent = this.switchMedicalValue ? 1 : 0;
          formData.isMedicalDevice2ExpiryPermanent = this.medicalDevice2ExpiryValue ? 1 : 0;
          formData.isMedicalLicenseExpiryPermanent = this.medicalLicenseExpiryValue ? 1 : 0;
          formData.isEffectivePermanent1 = this.medicalLicenseExpiryValue1 ? 1 : 0;
          formData.isEffectivePermanent2 = this.medicalLicenseExpiryValue2 ? 1 : 0;
          formData.isEffectivePermanent3 = this.medicalLicenseExpiryValue3 ? 1 : 0;

          // 处理食品经营许可证图片数据，转换为逗号分隔的字符串
          if (Array.isArray(formData.foodLicense)) {
            formData.foodLicense = formData.foodLicense.join(',');
          }

          if (formData.storeId != null) {
            updateStore(formData).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStore(formData).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const storeIds = row.storeId || this.ids;
      this.$confirm('是否确认删除店铺管理编号为"' + storeIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delStore(storeIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    handleRefresh(row) {
      const storeIds = row.storeId || this.ids;
      this.$confirm('是否确认重置店铺管理编号为"' + storeIds + '"的密码为XyzAbc~12 ', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return refreshPasWod(storeIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("修改成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有店铺管理数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportStore(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    },
    handleStoreExport(row){
      const queryStoreId = row.storeId;
      this.exportLoading = true;
      exportFsStream({ queryStoreId: queryStoreId }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
        this.exportLoading = false;
      });

    },
    //长期有效营业执照选择
    switchChange(){
      console.log(this.form.isBusinessLicensePermanent);
    },
    // 判断是否为图片文件（根据URL后缀）
    isImageFile(url, field) {
      // 若有存储的文件类型，直接用 MIME 类型判断
      if (this.form[`${field}FileType`]) {
        return this.form[`${field}FileType`].startsWith('image/');
      }
      // 后备：用 URL 后缀判断
      const imageExts = ['jpg', 'jpeg', 'png', 'gif'];
      const ext = url.split('.').pop()?.toLowerCase() || '';
      return imageExts.includes(ext);
    },

// 根据文件类型获取文档图标（优先用 MIME 类型）
    getDocumentIconClass(url, field) {
      // 若有存储的文件类型，直接用 MIME 类型判断
      if (this.form[`${field}FileType`]) {
        const fileType = this.form[`${field}FileType`];
        if (fileType === 'application/msword' || fileType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
          return 'el-icon-document';
        } else if (fileType === 'application/pdf') {
          return 'el-icon-file-pdf';
        }
        return 'el-icon-file';
      }
      // 后备：用 URL 后缀判断
      const ext = url.split('.').pop()?.toLowerCase() || '';
      if (ext === 'doc' || ext === 'docx') {
        return 'el-icon-document';
      } else if (ext === 'pdf') {
        return 'el-icon-file-pdf';
      }
      return 'el-icon-file';
    },

    // /// 从URL中提取文件名代码回退
    getFileName(url) {
      return url.split('/').pop().split('?')[0].slice(-8);
    },

    // 文件上传前校验
    beforeFileUpload(file) {
      // 校验文件类型
      const acceptTypes = [
        'image/jpeg',
        'image/png',
        'image/gif',
        'application/msword',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/pdf'
      ];
      if (!acceptTypes.includes(file.type)) {
        this.$message.error('请上传JPG、PNG、GIF、Word或PDF格式的文件');
        return false;
      }

      // 2. 校验文件大小（10MB）
      const maxSize = 10 * 1024 * 1024; // 10MB
      if (file.size > maxSize) {
        this.$message.error('文件大小不能超过10MB');
        return false;
      }

      return true;
    },

    // 文件上传成功处理（复用原有逻辑，仅优化提示）
    handleFileSuccess1(response, file, field) {
      this.form[field] = response.url;
      this.form[`${field}FileName`] = file.name;
      this.form[`${field}FileType`] = file.type; // 新增：记录文件 MIME 类型
      this.$message.success(`文件：${file.name}上传成功`);
    },

    // 文件上传失败处理
    handleFileError(err, file) {
      this.$message.error(`文件《${file.name}》上传失败，请重试`);
    },

    // 移除已上传文件
    handleFileRemove(field) {
      this.form[field] = '';
      this.form[`${field}FileName`] = ''; // 清空文件名
      this.$message.info('文件已移除');
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    // 将逗号分隔的URL字符串转换为文件对象数组
    urlToFileList(urlStr) {
      if (!urlStr) return [];
      return urlStr.split(',').map(url => {
        const fileName = url.substring(url.lastIndexOf('/') + 1);
        return {
          name: fileName,
          url: url,
          uid: Date.now() + Math.random().toString(36).substr(2, 9) // 生成唯一ID
        };
      });
    },
  }
};
</script>
<style>
.file-uploader {
  display: inline-block;
}

/* 已上传文件容器 */
.uploaded-file {
  position: relative;
  display: inline-block;
  cursor: default;
}

/* 已上传图片样式 */
.uploaded-img {
  width: 150px;
  height: 150px;
  border-radius: 4px;
  border: 1px solid #e4e7ed;
  vertical-align: middle;
}

/* 文档图标容器 */
/* 文档图标容器 */
.document-icon {
  width: 150px;
  height: 150px;
  border: 1px solid #e4e7ed;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #f5f7fa;
  vertical-align: middle;
}

.document-icon .icon {
  font-size: 36px;
  color: #409eff;
  margin-bottom: 8px;
  font-family: "element-icons" !important; /* 强制使用 Element 图标字体 */
  display: inline-block; /* 确保图标正常渲染 */
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  vertical-align: baseline;
  -webkit-font-smoothing: antialiased; /* 优化渲染 */
  -moz-osx-font-smoothing: grayscale; /* Firefox 优化渲染 */
}

.document-icon .file-name {
  font-size: 12px;
  color: #606266;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 80%;
  text-align: center;
}

/* 删除图标 */
.delete-icon {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background-color: #f56c6c;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 上传按钮（外层正方形边框） */
.upload-btn {
  width: 150px;
  height: 150px;
  /* 正方形边框 - 实线边框，默认灰色 */
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
}

/* 上传按钮 hover 效果（边框变色） */
.upload-btn:hover {
  border-color: #409eff;
  background-color: #f0f7ff; /* 轻微背景色变化，增强交互感 */
}

/* 上传按钮内部内容容器 */
.upload-btn-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #c0c4cc;
}

.upload-btn-inner i {
  font-size: 28px;
  margin-bottom: 8px;
}

.upload-btn-inner .upload-tip {
  font-size: 12px;
}

/* 上传说明 */
.upload-desc {
  margin-top: 8px;
  font-size: 12px;
  color: #909399;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px !important;
  text-align: center;
}

.el-divider__text {
  font-size: 16px;
  font-weight: bold;
}

/* LOGO上传区域样式优化 */
.avatar-wrapper {
  position: relative;
  display: inline-block;
}
.avatar {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 4px;
}
.delete-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.3s ease;
  border-radius: 4px;
}
.avatar-wrapper:hover .delete-mask {
  opacity: 1;
}
.avatar-uploader {
  display: inline-block;
}

.agreement-section {
  border: 1px solid #ebeef5;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 20px;
  background-color: #fafafa;
}

.agreement-section .agreement-title {
  margin-bottom: 10px;
}

.agreement-section .el-form-item {
  margin-bottom: 15px;
}

.agreement-section .el-form-item__label {
  font-weight: normal;
}

.agreement-section .el-date-editor.el-input__inner {
  width: 100%;
}

.agreement-section .el-date-editor--daterange.el-input__inner {
  width: 100%;
}
/* 并排按钮样式 */
.button-group {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}

.preview-btn,
.delete-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
}

.preview-btn:hover {
  background-color: rgba(0, 0, 0, 0.7);
}

.delete-btn:hover {
  background-color: #f56c6c;
}

/* 无图片占位符样式 */
.no-image-placeholder {
  width: 200px;
  height: 200px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  background-color: #fafafa;
}

.small-placeholder {
  width: 150px;
  height: 150px;
}

.avatar-wrapper {
  position: relative;
  display: inline-block;
}

.avatar {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 4px;
}

.small-avatar {
  width: 150px;
  height: 150px;
}

/* 食品经营许可证容器 */
.food-license-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  justify-content: flex-start;
}

/* 食品经营许可证单项 */
.food-license-item {
  position: relative;
  display: inline-block;
  text-align: center;
}

/* 添加按钮样式 */
.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px dashed #d9d9d9;
  background-color: #fafafa;
  width: 150px;
  height: 150px;
}

.add-btn:hover {
  border-color: #409EFF;
  background-color: #f0f7ff;
}


</style>
