<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="店铺名称" 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="licenseImages" width="100px">
              <template slot-scope="scope">
                <el-popover
                  placement="right"
                  title=""
                  trigger="hover">
                  <img slot="reference" :src="scope.row.licenseImages" width="80px">
                  <img :src="scope.row.licenseImages" style="max-width: 150px;">
                </el-popover>
              </template>
            </el-table-column>
            <el-table-column label="营业执照" align="center" prop="bizLicense" width="100px">
              <template slot-scope="scope">
                <el-popover
                  placement="right"
                  title=""
                  trigger="hover">
                  <img slot="reference" :src="scope.row.bizLicense" width="80px">
                  <img :src="scope.row.bizLicense" style="max-width: 150px;">
                </el-popover>
              </template>
            </el-table-column>-->
      <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="daysDiff" width="150px">
      </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 class="delete-mask" @click.stop="handleDeleteLogo">
                    <i class="el-icon-delete"></i>
                  </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>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </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>

                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
              <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="isDrugLicensePermanent">
                <el-switch
                  @change="switchChange()"
                  v-model="drugLicenseValue"
                  active-color="#13ce66"
                  inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
              <el-form-item label="药品经营许可证有效期" prop="drugLicenseExpiry" v-if="!drugLicenseValue">
                <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>
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
              <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>
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
              <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="isMedicalDevice3ExpiryPermanent">
                <el-switch
                  @change="switchChange()"
                  v-model="medicalDevice3ExpiryValue"
                  active-color="#13ce66"
                  inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
              <el-form-item label="3类器械经营许可证有效期" prop="medicalDevice3Expiry" v-if="!medicalDevice3ExpiryValue">
                <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="12">
              <el-form-item label="食品经营许可证上传" prop="foodLicense">
                <el-upload
                  class="avatar-uploader"
                  :action="uploadUrl"
                  :show-file-list="false"
                  :on-success="(response, file) => handleFileSuccess(response, file, 'foodLicense')"
                  :before-upload="beforeAvatarUpload"
                  :disabled="isDeleting"
                >
                  <!-- 图片容器（包含图片和删除按钮，仅在有图片时显示） -->
                  <div class="avatar-wrapper" v-if="form.foodLicense">
                    <img :src="form.foodLicense" class="avatar" width="200px">
                    <!-- 悬停显示的删除按钮 -->
                    <div class="delete-mask" @click.stop="handleDelete3">
                      <i class="el-icon-delete"></i>
                    </div>
                  </div>
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </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-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-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
      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 {
      // 新增：控制LOGO上传组件禁用状态
      isDeleting: false,
      promptList:[],
      dialogVisible: false,
      // 控制是否为查看模式（只读）
      isViewMode: false,
      // 店铺对话框相关
      storeDialogVisible: false,
      storeDialogMode: 'add', // add, edit, detail
      currentStoreData: {},
      auditLogs: [],
      switchValue:false,
      switchMedicalValue:false,
      drugLicenseValue:false,
      medicalDevice2ExpiryValue:false,
      medicalDevice3ExpiryValue:false,
      foodLicenseExpiryValue:false,
      medicalLicenseExpiryValue: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,
      },
      // 表单参数
      form: {
        settlementAgreementFileType: '', // 入驻协议文件类型（如 application/pdf）
        qualityAssuranceAgreementFileType: '', // 质量保证协议文件类型
        otherSpecialQualificationFileType: '', // 其他特殊资质文件类型
        settlementAgreement: null,
        settlementAgreementFileName: null, // 新增：存储文件名
        qualityAssuranceAgreement: null,
        qualityAssuranceAgreementFileName: null, // 新增：存储文件名
        otherSpecialQualification: null,
        otherSpecialQualificationFileName: null // 新增：存储文件名

      },
      // 表单校验
      rules: {
        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" }
        ],
        drugLicenseExpiry:[
          { required: true, message: "药品经营许可证有效期不能为空", trigger: "blur" }
        ],
        drugCode:[
          { required: true, message: "药品经营许可证编号不能为空", trigger: "blur" }
        ],
        medicalDevice2:[
          { required: true, message: "2类医疗器械备案证不能为空", trigger: "blur" }
        ],
        medicalDevice2Expiry:[
          { required: true, message: "2类医疗器械备案证有效期不能为空", trigger: "blur" }
        ],
        medicalDevice2Code:[
          { required: true, message: "2类医疗器械备案证编号不能为空", 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: {
    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);
      }
    },

    /** 查询店铺管理列表 */
    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: null,               // 食品经营许可证文件
        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,
        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.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', '图片');
    },
    handleDelete1() {
      this.deleteImage('medicalDevice1', '图片');
    },
    handleDelete2() {
      this.deleteImage('medicalDevice3', '图片');
    },
    handleDelete3() {
      this.deleteImage('foodLicense', '图片');
    },
    handleDelete4() {
      this.deleteImage('medicalLicense', '图片');
    },
    handleDelete5() {
      this.deleteImage('businessLicense', '图片');
    },
    handleDelete6() {
      this.deleteImage('drugLicense', '图片');
    },
    handleDelete7() {
      this.deleteImage('medicalDevice2', '图片');
    },
    // 通用图片删除方法
    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.isBusinessLicensePermanent == 1){
          this.switchValue = true;
        }
        if(this.form.isMedicalDevice1ExpiryPermanent == 1){
          this.switchMedicalValue = true;
        }
        if(this.form.isDrugLicensePermanent == 1){
          this.drugLicenseValue = true;
        }
        if(this.form.isMedicalDevice2ExpiryPermanent == 1){
          this.medicalDevice2ExpiryValue = true;
        }
        if(this.form.isMedicalDevice3ExpiryPermanent == 1){
          this.medicalDevice3ExpiryValue = true;
        }
        if(this.form.isFoodLicenseExpiryPermanent == 1){
          this.foodLicenseExpiryValue = true;
        }
        if(this.form.isMedicalLicenseExpiryPermanent == 1){
          this.medicalLicenseExpiryValue = true;
        }
        if(this.form.isEffectivePermanent1 == 1){
          this.medicalLicenseExpiryValue1 = 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
          ]);
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 处理表单数据
          const formData = Object.assign({}, this.form);

          // 处理城市ID
          if (formData.cityIds) {
            formData.cityIds = formData.cityIds.toString();
          }

          // 处理配送方式
          if (formData.shippingType) {
            formData.shippingType = formData.shippingType.toString();
          }

          // 处理日期范围字段
          if (formData.drugLicenseExpiry && formData.drugLicenseExpiry.length === 2) {
            formData.drugLicenseExpiryStart = formData.drugLicenseExpiry[0];
            formData.drugLicenseExpiryEnd = formData.drugLicenseExpiry[1];
          }

          if (formData.medicalDevice2Expiry && formData.medicalDevice2Expiry.length === 2) {
            formData.medicalDevice2ExpiryStart = formData.medicalDevice2Expiry[0];
            formData.medicalDevice2ExpiryEnd = formData.medicalDevice2Expiry[1];
          }

          if (formData.medicalDevice1Expiry && formData.medicalDevice1Expiry.length === 2) {
            formData.medicalDevice1ExpiryStart = formData.medicalDevice1Expiry[0];
            formData.medicalDevice1ExpiryEnd = formData.medicalDevice1Expiry[1];
          }

          if (formData.medicalDevice3Expiry && formData.medicalDevice3Expiry.length === 2) {
            formData.medicalDevice3ExpiryStart = formData.medicalDevice3Expiry[0];
            formData.medicalDevice3ExpiryEnd = formData.medicalDevice3Expiry[1];
          }

          if (formData.foodLicenseExpiry && formData.foodLicenseExpiry.length === 2) {
            formData.foodLicenseExpiryStart = formData.foodLicenseExpiry[0];
            formData.foodLicenseExpiryEnd = formData.foodLicenseExpiry[1];
          }

          if (formData.medicalLicenseExpiry && formData.medicalLicenseExpiry.length === 2) {
            formData.medicalLicenseExpiryStart = formData.medicalLicenseExpiry[0];
            formData.medicalLicenseExpiryEnd = formData.medicalLicenseExpiry[1];
          }
          if (formData.businessLicenseExpire && formData.businessLicenseExpire.length === 2) {
            formData.businessLicenseExpireStart = formData.businessLicenseExpire[0];
            formData.businessLicenseExpireEnd = formData.businessLicenseExpire[1];
          }

          if (formData.settlementAgreementExpiry && formData.settlementAgreementExpiry.length === 2) {
            formData.settlementAgreementStart = formData.settlementAgreementExpiry[0];
            formData.settlementAgreementEnd = formData.settlementAgreementExpiry[1];
          }else {
            if(formData.settlementAgreement != null){
              return this.$message.warning("其它资质-入驻协议，有效期开始日期或结束日期不能为空！");
            }
          }

          if (formData.qualityAssuranceAgreementExpiry && formData.qualityAssuranceAgreementExpiry.length === 2) {
            formData.qualityAssuranceAgreementStart = formData.qualityAssuranceAgreementExpiry[0];
            formData.qualityAssuranceAgreementEnd = formData.qualityAssuranceAgreementExpiry[1];
          }else {
            if(formData.qualityAssuranceAgreement != null){
              return this.$message.warning("质量保证协议，有效期开始日期或结束日期不能为空！");
            }
          }

          if (formData.otherSpecialQualificationExpiry && formData.otherSpecialQualificationExpiry.length === 2) {
            formData.otherSpecialQualificationStart = formData.otherSpecialQualificationExpiry[0];
            formData.otherSpecialQualificationEnd = formData.otherSpecialQualificationExpiry[1];
          }else {
            if(formData.otherSpecialQualification != null){
              return this.$message.warning("其它特殊资质，有效期开始日期或结束日期不能为空！");
            }
          }
          if(!!this.switchValue){
              formData.isBusinessLicensePermanent = 1;
          }else{
              formData.isBusinessLicensePermanent = 0;
          }
          if(!!this.switchMedicalValue){
            formData.isMedicalDevice1ExpiryPermanent=1;
          }else {
            formData.isMedicalDevice1ExpiryPermanent=0;
          }
          if(!!this.drugLicenseValue){
            formData.isDrugLicensePermanent=1;
          }else {
            formData.isDrugLicensePermanent=0;
          }
          if(!!this.medicalDevice2ExpiryValue){
            formData.isMedicalDevice2ExpiryPermanent=1;
          }else {
            formData.isMedicalDevice2ExpiryPermanent=0;
          }
          if(!!this.medicalDevice3ExpiryValue){
            formData.isMedicalDevice3ExpiryPermanent=1;
          }else {
            formData.isMedicalDevice3ExpiryPermanent=0;
          }
          if(!!this.foodLicenseExpiryValue){
            formData.isFoodLicenseExpiryPermanent=1;
          }else {
            formData.isFoodLicenseExpiryPermanent=0;
          }
          if(!!this.medicalLicenseExpiryValue){
            formData.isMedicalLicenseExpiryPermanent=1;
          }else {
            formData.isMedicalLicenseExpiryPermanent=0;
          }
          if(!!this.medicalLicenseExpiryValue1){
            formData.isEffectivePermanent1=1;
          }else {
            formData.isEffectivePermanent1=0;
          }
          if(!!this.medicalLicenseExpiryValue2){
            formData.isEffectivePermanent2=1;
          }else {
            formData.isEffectivePermanent2=0;
          }
          if(!!this.medicalLicenseExpiryValue3){
            formData.isEffectivePermanent3=1;
          }else {
            formData.isEffectivePermanent3=0;
          }
          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('文件已移除');
    },
  }
};
</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%;
}


</style>
