<template>
  <div style="padding: 20px">
    <header style="display: flex; justify-content: space-between; align-items: center">
      <h1 style="font-weight: 600; font-size: 20px">{{ $t("会员详情") }}</h1>
      <div>
        <el-button type="primary" v-has-permi="['member:certificate']" @click="guarantee(details)">{{ $t("保函证书") }}</el-button>
        <el-button type="primary" v-has-permi="['member:log']" @click="operationLogFn(details)">{{ $t("操作日志") }}</el-button>
        <el-button type="primary" v-has-permi="['member:id-card']" @click="identityFn(details, '1')">{{ $t("身份证") }}</el-button>
        <el-button type="primary" v-has-permi="['member:business-license']" @click="identityFn(details, '2')">{{ $t("营业执照") }}</el-button>
        <el-button type="danger" v-has-permi="['member:delete']" @click="deleteFn(details)">{{ $t("删除") }}</el-button>
      </div>
    </header>
    <!--lanbm 2024-05-15 修改信息显示BUG-->
    <el-descriptions :title="$t('基础信息')" :labelStyle="{ width: '146px' }" :contentStyle="{ width: '278px' }" :column="4" border>
      <el-descriptions-item :label="$t('会员编号')">{{ details.memberCode }}</el-descriptions-item>
      <el-descriptions-item :label="$t('会员昵称')">{{ details.nickname }}</el-descriptions-item>
      <el-descriptions-item :label="$t('英文名称')">{{ details.englishName }}</el-descriptions-item>
      <el-descriptions-item :label="$t('真实姓名')">{{ details.identityName || "-" }}</el-descriptions-item>
      <el-descriptions-item :label="$t('联系方式')"
        ><span style="margin-right: 10px">+{{ details.areaCode }}</span
        ><span>{{ details.mobile }}</span>
      </el-descriptions-item>
      <el-descriptions-item :label="$t('绑定邮箱')">{{ details.email }}</el-descriptions-item>
      <el-descriptions-item :label="$t('生日')">{{ details.birthday }}</el-descriptions-item>
      <el-descriptions-item :label="$t('性别')">{{ details.gender === 0 ? "女" : details.gender === 1 ? "男" : "保密" }} </el-descriptions-item>
      <el-descriptions-item :label="$t('地址')">{{ details.address }}</el-descriptions-item>
      <el-descriptions-item :label="$t('部门')">{{ details.department }}</el-descriptions-item>
      <el-descriptions-item :label="$t('职位')">{{ details.jobPosition }}</el-descriptions-item>
      <el-descriptions-item :label="$t('创建时间')">{{ details.createTime }}</el-descriptions-item>
      <el-descriptions-item :label="$t('绑定客户')">{{ details.customerCode }}</el-descriptions-item>
      <el-descriptions-item :label="$t('国家')">{{ isChinese ? details.countryTitleZh : details.countryTitleEn }}</el-descriptions-item>
      <el-descriptions-item :label="$t('城市')">{{ isChinese ? details.cityTitleZh : cityTitleEn }}</el-descriptions-item>
      <el-descriptions-item :label="$t('上次登录')">{{ details.loginDate }}</el-descriptions-item>
    </el-descriptions>

    <!--lanbm 2024-05-15 修改信息显示BUG-->
    <el-descriptions style="margin-top: 20px" :title="$t('公司信息')" :labelStyle="{ width: '146px' }" :contentStyle="{ width: '278px' }" :column="4" border>
      <el-descriptions-item :label="$t('公司名称')">{{ details.enterpriseName }}</el-descriptions-item>
      <el-descriptions-item :label="$t('公司英文名称')">{{ details.enterpriseNameEn }}</el-descriptions-item>
      <el-descriptions-item :label="$t('档口')">{{ details.enterpriseStall }}</el-descriptions-item>
      <el-descriptions-item :label="$t('品牌')">{{ details.enterpriseBrand }}</el-descriptions-item>
      <el-descriptions-item :label="$t('公司地址')">{{ details.enterpriseAddress }}</el-descriptions-item>
      <el-descriptions-item :label="$t('公司简介')">{{ details.enterpriseDesc }}</el-descriptions-item>
    </el-descriptions>
    <el-descriptions style="margin-top: 20px" :title="$t('认证信息')" :labelStyle="{ width: '146px' }" :contentStyle="{ width: '278px' }" :column="4" border>
      <el-descriptions-item :label="$t('成交')">{{ details.customerStatus === 3 ? "成交" : "未成交" }}</el-descriptions-item>
      <el-descriptions-item :label="$t('认证')">
        <span v-if="details.identityAuditStatus === 2 && details.enterpriseAuditStatus === 2">{{ $t("双认证") }}</span>
        <span v-else-if="details.identityAuditStatus === 2 && details.enterpriseAuditStatus !== 2">{{ $t("身份证") }}</span>
        <span v-else-if="details.identityAuditStatus !== 2 && details.enterpriseAuditStatus === 2">{{ $t("企业") }}</span>
        <span v-else-if="details.identityAuditStatus !== 2 && details.enterpriseAuditStatus !== 2">{{ $t("否") }}</span>
      </el-descriptions-item>
      <el-descriptions-item :label="$t('身份证认证状态')">{{
        details.identityAuditStatus !== null
          ? $l(
              getDictDatas(this.DICT_TYPE.AUDIT_STATUS).find((i) => i.value == details.identityAuditStatus),
              "label"
            )
          : ""
      }}</el-descriptions-item>
      <el-descriptions-item :label="$t('营业执照认证状态')">{{
        details.enterpriseAuditStatus !== null
          ? $l(
              getDictDatas(this.DICT_TYPE.AUDIT_STATUS).find((i) => i.value == details.enterpriseAuditStatus),
              "label"
            )
          : ""
      }}</el-descriptions-item>
    </el-descriptions>
    <!-- 积分信息 -->

    <el-descriptions style="margin-top: 20px" :title="$t('积分信息')" :column="6" direction="vertical" border>
      <!-- <el-descriptions-item :label="$t('会员图标')">

        </el-descriptions-item
      > -->
      <el-descriptions-item :label="$t('会员等级')">
        <el-image v-if="this.levelDetails.configId&&details.userScoreLevelInfo!=null&&details.userScoreLevelInfo.levelIcon!=''" :src="details.userScoreLevelInfo!=null?details.userScoreLevelInfo.levelIcon:null" style="width: 20px; height: 20px">{{ $t("无") }}</el-image>
        {{ details.userScoreLevelInfo.level!=null?(isChinese ? handleMemberShipLevels(details.userScoreLevelInfo.level).label : handleMemberShipLevels(details.userScoreLevelInfo.level).labelEn):null }}
        <el-button v-has-permi="['member:detail']" type="primary" class="copy-btn" @click="openLevelDetail()">
          {{ $t("详情") }}
        </el-button>
        <el-button v-has-permi="['member:detail:update']" type="primary" @click="openLevelDetail(1)">
          {{ $t("更新") }}
        </el-button>
      </el-descriptions-item>
      <el-descriptions-item :label="$t('当前积分')">{{details.userScoreLevelInfo!=null? details.userScoreLevelInfo.holdScore:null }}</el-descriptions-item>
      <el-descriptions-item :label="$t('已兑换积分')">{{details.userScoreLevelInfo!=null? details.userScoreLevelInfo.usedScore :null}}</el-descriptions-item>
      <el-descriptions-item :label="$t('推荐码')">{{ details.userScoreLevelInfo!=null?details.userScoreLevelInfo.memberCode:null }}</el-descriptions-item>
      <el-descriptions-item :label="$t('操作')">
        <el-button type="text" class="copy-btn" :data-clipboard-text="details.memberCode">
          {{ $t("复制推荐码") }}
        </el-button>
        <el-button type="text" @click="handleExchangeRewards(details)">
          {{ $t("兑换礼品") }}
        </el-button>
      </el-descriptions-item>
    </el-descriptions>

    <!-- table Tab -->
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="reward">{{ $t("积分记录") }}</el-menu-item>
      <el-menu-item index="exchange">{{ $t("兑换记录") }}</el-menu-item>
      <el-menu-item index="level">{{ $t("等级记录") }}</el-menu-item>
    </el-menu>
    <div class="table-container">
      <div class="reward" v-show="activeIndex == 'reward'">
        <!-- 积分记录 -->

        <IntegralRecord :memberCode="$route.params.id"></IntegralRecord>
        <!-- <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="120px"
        >
          <el-form-item :label="$t('积分规则')">
            <dict-selector
              clearable
              :type="DICT_TYPE.SCORE_RULE_TYPE"
              v-model="queryParams.sourceType"
              @change="handleQuery"
            >
            </dict-selector>
          </el-form-item>
          <el-form-item :label="$t('规则说明')">
            <el-input
              style="width: 300px"
              v-model.trim="queryParams.ruleDesc"
              :placeholder="$t('请输入关键词查找')"
              clearable
              @keyup.enter.native="handleQuery"
              onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"
            />
          </el-form-item>
          <el-form-item :label="$t('兑换时间')">
            <el-date-picker
              type="datetimerange"
              clearable
              placement="bottom-start"
              v-model="dateRangeCreateTime"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="-"
              :start-placeholder="$t('开始日期')"
              :end-placeholder="$t('结束日期')"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="handleQuery"
              >{{ $t("搜索") }}</el-button
            >
            <el-button icon="el-icon-refresh" @click="resetQuery">{{
              $t("重置")
            }}</el-button>
          </el-form-item>
        </el-form>
        <el-table ref="multipleTable" v-loading="loading" :data="memberList">
          <el-table-column
            width="140"
            :label="$t('积分记录ID')"
            align="center"
            prop="id"
          ></el-table-column>

          <el-table-column :label="$t('积分来源')" align="center">
            <template slot-scope="scope">
              {{
                isChinese
                  ? handleSourceType(scope.row.sourceType).label
                  : handleSourceType(scope.row.sourceType).labelEn
              }}
            </template>
          </el-table-column>
          <el-table-column
            :label="$t('规则标题')"
            align="center"
            :prop="isChinese ? 'ruleTitleZh' : 'ruleTitleEn'"
          >
          </el-table-column>
          <el-table-column
            :label="$t('规则说明')"
            align="center"
            :prop="isChinese ? 'ruleDescZh' : 'ruleDescEn'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            :label="$t('分值')"
            prop="scoreCount"
          ></el-table-column>
          <el-table-column :label="$t('操作积分时间')" align="center">
            <template v-slot="{ row }">
              {{ parseTime(row.createTime) || "/" }}</template
            >
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="handleQueryPagination"
        /> -->
      </div>
      <div class="exchange" v-show="activeIndex == 'exchange'">
        <el-form :model="queryParamsRecord" ref="queryForm" size="small" :inline="true" label-width="120px">
          <el-form-item :label="$t('礼品')">
            <el-input style="width: 300px" v-model.trim="queryParamsRecord.rewardTitle" :placeholder="$t('请输入礼品名称')" clearable @keyup.enter.native="handleQuery" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
          </el-form-item>
          <el-form-item :label="$t('领取方式')">
            <dict-selector clearable :type="DICT_TYPE.WAY_OF_RECEIVING" v-model="queryParamsRecord.redeemType"> </dict-selector>
          </el-form-item>

          <el-form-item :label="$t('兑换时间')">
            <el-date-picker type="datetimerange" clearable placement="bottom-start" v-model="dateRangeCreateTimeRecord" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" range-separator="-" :start-placeholder="$t('开始日期')" :end-placeholder="$t('结束日期')" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQueryRecord">{{ $t("搜索") }}</el-button>
            <el-button icon="el-icon-refresh" @click="resetQueryRecord">{{ $t("重置") }}</el-button>
          </el-form-item>
        </el-form>

        <el-table ref="multipleTable" v-loading="loading" :data="memberRecordList">
          <el-table-column :label="$t('记录ID')" width="160" align="center">
            <template #default="{ row }">
              <el-button type="text" @click="handleViewRecord(row)">{{ row.redemptionNumber }}</el-button>
            </template>
          </el-table-column>
          <el-table-column width="140" :label="$t('礼品ID')" align="center">
            <template #default="{ row }">
              <el-button type="text" @click="handleShowRewardsDetail(row)">{{ row.rewardCode }}</el-button>
            </template>
          </el-table-column>
          <el-table-column width="180" :label="$t('礼品')" align="center" :prop="isChinese ? 'rewardTitleZh' : 'rewardTitleEn'"></el-table-column>
          <el-table-column :label="$t('会员')" align="center" :prop="isChinese ? 'memberNameZh' : 'memberNameEn'"></el-table-column>
          <el-table-column width="180" :label="$t('时间')" align="center">
            <template v-slot="{ row }">
              {{ parseTime(row.redemptionTime) || "/" }}
            </template>
          </el-table-column>
          <el-table-column width="140" :label="$t('数量')" align="center" prop="rewardCount"></el-table-column>
          <el-table-column :label="$t('积分')" align="center" prop="totalCount"></el-table-column>
          <el-table-column width="140" :label="$t('入口')" align="center">
            <template v-slot="{ row }">
              {{ isChinese ? handleExchangeEntrance(row.entrance).label : handleExchangeEntrance(row.entrance).labelEn }}
            </template>
          </el-table-column>
          <el-table-column width="140" :label="$t('网点')" align="center" :prop="isChinese ? 'nodeTitleZh' : 'nodeTitleEn'"> </el-table-column>
          <el-table-column width="140" :label="$t('领取方式')" align="center">
            <template v-slot="{ row }">
              {{ isChinese ? handleExchangeRedeemType(row.redeemType).label : handleExchangeRedeemType(row.redeemType).labelEn }}
            </template>
          </el-table-column>
          <el-table-column width="140" :label="$t('状态')" align="center">
            <template v-slot="{ row }">
              {{ isChinese ? handleExchangeStatus(row.status).label : handleExchangeStatus(row.status).labelEn }}
            </template>
          </el-table-column>
          <el-table-column width="140" :label="$t('备注')" align="center" prop="remark"></el-table-column>、

          <el-table-column width="140" :label="$t('创建人')" align="center" prop="creatorName"></el-table-column>
          <el-table-column width="140" :label="$t('更新人')" align="center" prop="updaterName"></el-table-column>
        </el-table>
        <!-- //分页列表 -->
        <pagination v-show="totalRecord > 0" :total="totalRecord" :page.sync="queryParamsRecord.pageNo" :limit.sync="queryParamsRecord.pageSize" @pagination="handleQueryPaginationRecord" />
      </div>
      <div class="exchange" v-show="activeIndex == 'level'">
        <el-table ref="multipleTable1" v-loading="loading" :data="memberOperateLevelList">
          <el-table-column  :label="$t('状态')" align="center">
            <template v-slot="{ row }">
              {{ isChinese ? handleMemberUserOperateLog(row.operateType).label : handleMemberUserOperateLog(row.operateType).labelEn }}
            </template>
          </el-table-column>
          <el-table-column  :label="$t('时间')" align="center">
            <template v-slot="{ row }">
              {{ parseTime(row.createTime) || "/" }}
            </template>
          </el-table-column>
          <el-table-column  :label="$t('匹配规则')" align="center">
            <template v-slot="{ row }" >
              <el-button type="text" @click="$router.push('/member/operatingLevel?pageStatus=view&id=' + row.configId)">{{row.configName}}</el-button>
            </template>
          </el-table-column>
          <el-table-column  :label="$t('等级')" align="center">
            <template v-slot="{ row }">
              {{ isChinese ? handleMemberShipLevels(row.level).label : handleMemberShipLevels(row.level).labelEn }}
            </template>
          </el-table-column>
          <el-table-column  :label="$t('说明')" align="center">
            <template v-slot="{ row }">
              {{ row.remarks }}
            </template>
          </el-table-column>
          <el-table-column  :label="$t('操作人')" align="center">
            <template v-slot="{ row }">
              {{ row.operator }}
            </template>
          </el-table-column>
        </el-table>
        <!-- //分页列表 -->
        <pagination v-show="totalLevelLog > 0" :total="totalLevelLog" :page.sync="queryParamsLevel.pageNo" :limit.sync="queryParamsLevel.pageSize" @pagination="handleQueryPaginationOperateLevelLog" />
      </div>
    </div>

    <el-dialog
      title="保函/证书"
      :visible.sync="guaranteeShow"
      :before-close="
        () => {
          guaranteeUrl = ''
          guaranteeShow = false
        }
      "
      width="50%"
    >
      <el-form>
        <el-form-item :label="$t('保函/证书')">
          <el-row :gutter="20" type="flex" justify="center">
            <el-col :span="12">
              <el-input v-model="guaranteeUrl"></el-input>
            </el-col>
            <el-col :span="4">
              <div style="height: 45px; overflow: hidden">
                <file-upload v-model="guaranteeUrl" :fileType="['png', 'jpg', 'jpeg', 'pdf']" :limit="1" :isShowTip="false"></file-upload>
              </div>
            </el-col>
            <el-col :span="6">
              <div>{{ $t("可上传图片,pdf文档") }}</div>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
      <div style="text-align: center">
        <el-button @click="setGuarantee">{{ $t("保 存") }}</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="$t('操作日志')" :visible.sync="operationLogShow" width="50%">
      <el-table :data="operationLogList">
        <el-table-column :label="$t('标题')" prop="title"></el-table-column>
        <el-table-column :label="$t('操作内容')" prop="content"></el-table-column>
        <el-table-column :label="$t('操作人')" prop="userId">
          <template v-slot="{ row }">
            {{ details.identityName }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作时间')">
          <template v-slot:default="scope">
            {{ parseTime(scope.row.createTime) }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作ip')" prop="ip"></el-table-column>
      </el-table>
      <pagination v-show="totalLog > 0" :total="totalLog" :page.sync="operationLogFrom.page" :limit.sync="operationLogFrom.row" @pagination="getOperationLogList" />
    </el-dialog>
    <el-dialog :title="$t('认证')" :visible.sync="attestationShow" width="80%">
      <div class="details">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :label="$t('身份证')" name="1">
            <div style="padding: 0 40px; box-sizing: border-box">
              <el-form :disabled="[2, 3].includes(IdDetails.status) && modifyIdCard" ref="formId" label-position="left" label-width="100px" :rules="rulesId" :model="IdDetails">
                <el-form-item :label="$t('姓名')" prop="name">
                  <el-input v-model="IdDetails.name"></el-input>
                </el-form-item>
                <el-form-item :label="$t('证件类型')" prop="cardType">
                  <dict-selector v-model="IdDetails.cardType" :type="DICT_TYPE.CERTIFICATE_TYPE"></dict-selector>
                </el-form-item>
                <el-form-item :label="$t('证件号码')" prop="cardNumber">
                  <el-input v-model="IdDetails.cardNumber"></el-input>
                </el-form-item>
                <el-form-item :label="$t('证件正面照')" prop="img1">
                  <div>
                    <el-input readonly style="margin-bottom: 20px" v-model="IdDetails.img1"></el-input>
                    <ImageUpload :isShowTip="false" v-model="IdDetails.img1" :limit="1"></ImageUpload>
                  </div>
                </el-form-item>
                <el-form-item :label="$t('证件背面照')" prop="img2">
                  <div>
                    <el-input readonly style="margin-bottom: 20px" v-model="IdDetails.img2"></el-input>
                    <ImageUpload :isShowTip="false" :limit="1" v-model="IdDetails.img2"></ImageUpload>
                  </div>
                </el-form-item>
                <el-form-item :label="$t('审核状态')" v-if="modifyIdCard && IdDetails.status !== 0">
                  {{ getDictDatas(DICT_TYPE.AUDIT_STATUS)[IdDetails.status] ? getDictDatas(DICT_TYPE.AUDIT_STATUS)[IdDetails.status].label : "" }}
                </el-form-item>
                <el-form-item :label="$t('审核时间')" v-if="[2, 3].includes(IdDetails.status) && modifyIdCard">
                  {{ parseTime(IdDetails.auditTime) }}
                </el-form-item>
                <el-form-item v-if="modifyIdCard && IdDetails.status !== 0" :label="$t('审核备注')">
                  <el-input v-model="IdDetails.auditRemark" :disabled="IdDetails.status === 3" type="textarea"></el-input>
                </el-form-item>
              </el-form>
              <div v-if="IdDetails.status === 1" style="text-align: center; margin-top: 20px">
                <el-button type="primary" @click="idCardAuditFn(2)">{{ $t("审核通过") }}</el-button>
                <el-button type="primary" @click="idCardAuditFn(3)">{{ $t("审核不通过") }}</el-button>
                <el-button @click="attestationShow = false">{{ $t("取 消") }}</el-button>
              </div>
              <div v-if="IdDetails.status === 2 || IdDetails.status === 3" style="text-align: center; margin-top: 20px">
                <el-button type="primary" v-if="modifyIdCard" @click="modifyIdCard = false">{{ $t("修 改") }} </el-button>
                <el-button type="primary" v-else @click="setMemberUserUpdateIdCard">{{ $t("提交审核") }}</el-button>
                <el-button @click="attestationShow = false">{{ $t("取 消") }}</el-button>
              </div>
              <div v-if="IdDetails.status === 0" style="text-align: center; margin-top: 20px">
                <el-button type="primary" @click="submitId">{{ $t("上 传") }}</el-button>
                <el-button @click="attestationShow = false">{{ $t("取 消") }}</el-button>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="$t('营业执照')" name="2">
            <div style="width: 500px; padding: 0 40px; box-sizing: border-box">
              <el-form :disabled="modifyLicense && [2, 3].includes(enterpriseFrom.status)" :rules="rulesEnterprise" :model="enterpriseFrom" label-position="left" ref="formEnter" label-width="100px">
                <el-form-item :label="$t('企业名称')" prop="name">
                  <el-input v-model="enterpriseFrom.name"></el-input>
                </el-form-item>
                <el-form-item :label="$t('企业法人')" prop="legalName">
                  <el-input v-model="enterpriseFrom.legalName"></el-input>
                </el-form-item>
                <el-form-item :label="$t('证件号码')" prop="cardNumber">
                  <el-input v-model="enterpriseFrom.cardNumber"></el-input>
                </el-form-item>
                <el-form-item :label="$t('证件照')" prop="img1">
                  <div>
                    <el-input readonly style="margin-bottom: 20px" v-model="enterpriseFrom.img1"></el-input>
                    <ImageUpload :isShowTip="false" :limit="1" v-model="enterpriseFrom.img1"></ImageUpload>
                  </div>
                </el-form-item>
                <el-form-item :label="$t('附件')">
                  <el-input readonly v-model="enterpriseFrom.img2"></el-input>
                  <ImageUpload :isShowTip="false" :limit="1" v-model="enterpriseFrom.img2"></ImageUpload>
                </el-form-item>
                <el-form-item v-if="modifyLicense && enterpriseFrom.status !== 0" :label="$t('审核状态')">
                  {{ getDictDatas(DICT_TYPE.AUDIT_STATUS)[enterpriseFrom.status].label }}
                </el-form-item>
                <el-form-item v-if="[2, 3].includes(enterpriseFrom.status) && modifyLicense" :label="$t('审核时间')">
                  {{ parseTime(enterpriseFrom.auditTime) }}
                </el-form-item>
                <el-form-item v-if="modifyLicense && enterpriseFrom.status !== 0" :label="$t('审核备注')">
                  <el-input v-model="enterpriseFrom.auditRemark" :disabled="enterpriseFrom.status === 3" type="textarea"></el-input>
                </el-form-item>
              </el-form>
              <div v-if="enterpriseFrom.status === 1" style="text-align: center; margin-top: 20px">
                <el-button type="primary" @click="certificateVerificationFn(2)">{{ $t("审核通过") }}</el-button>
                <el-button type="primary" @click="certificateVerificationFn(3)">{{ $t("审核不通过") }}</el-button>
                <el-button @click="attestationShow = false">{{ $t("取 消") }}</el-button>
              </div>
              <div v-if="enterpriseFrom.status === 2 || enterpriseFrom.status === 3" style="text-align: center; margin-top: 20px">
                <el-button type="primary" v-if="modifyLicense" @click="modifyLicense = false">{{ $t("修 改") }} </el-button>
                <el-button type="primary" v-else @click="setMemberUserUpdateEnterprise">{{ $t("提交审核") }}</el-button>
                <el-button @click="attestationShow = false">{{ $t("取 消") }}</el-button>
              </div>
              <div v-if="enterpriseFrom.status === 0" style="text-align: center; margin-top: 20px">
                <el-button type="primary" @click="submit">{{ $t("上 传") }}</el-button>
                <el-button @click="attestationShow = false">{{ $t("取 消") }}</el-button>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-dialog>
    <el-dialog :title="levelDetailsTitle" :visible.sync="levelDetailsShow" width="50%">
        <el-form :rules="rulesDetails" :model="levelDetails" label-position="left" ref="formDetails" label-width="100px">
          <el-form-item :label="$t('编号:')">
            <el-input v-model="levelDetails.memberCode" style="width: 50%" disabled></el-input>
          </el-form-item>
          <el-form-item :label="$t('等级:')" prop="level">
            <dict-selector v-model="levelDetails.level"  :disabled="levelDetailsCanEdit" clearable :type="DICT_TYPE.MEMBERSHIP_LEVELS" />
          </el-form-item>
          <el-form-item :label="$t('等级有效期:')" prop="validityPeriod">
            <el-date-picker type="date" :placeholder="$t('请选择日期')" :disabled="levelDetailsCanEdit" v-model="levelDetails.validityPeriod" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item :label="$t('等级特殊设置')">
            <el-switch
              :disabled="levelDetailsCanEdit"
              v-model="levelDetails.specificSettings"
              active-color="#13ce66"
              inactive-color="#ff4949">
            </el-switch>
            <el-button style="margin-left: 10px;" type="info">{{ $t("不降级") }}</el-button>
          </el-form-item>
          <el-form-item :label="$t('更新原因')" prop="remarks">
            <el-input :disabled="levelDetailsCanEdit" v-model="levelDetails.remarks" style="width: 50%"  type="textarea" autosize :autosize="{ minRows: 2, maxRows: 4}"></el-input>
          </el-form-item>
          <el-form-item :label="$t('最后更新人')">
            <el-input v-model="levelDetails.updaterName" style="width: 50%" disabled></el-input>
          </el-form-item>
          <el-form-item :label="$t('最后更新时间')">
            <el-date-picker v-model="levelDetails.updateTime" style="width: 50%" type="datetime" disabled :placeholder="$t('请选择')"> </el-date-picker>
          </el-form-item>
        </el-form>
        <div style="text-align: center">
          <el-button @click="closeLevelDetail" type="primary">{{ $t("取 消") }}</el-button>
          <el-button @click="submitDetails" v-if="!levelDetailsCanEdit" type="primary">{{ $t("保 存") }}</el-button>
        </div>
    </el-dialog>
    <!-- 查看 礼品 -->
    <operating-gift ref="operatingGift" :title="operatingPagetitle" :rewards-details="rewardsItem" :show.sync="dialogVisible" :node-list="nodeList" />
  </div>
</template>
<script>
import { createAuditIdCard, deleteUser, memberGetAuthEnterpriseInfo, memberGetAuthIdcardInfo, memberUserAuditEnterprise, memberUserAuditIdCard, memberUserGet, memberUserUpdateEnterprise, memberUserUpdateIdCard, operationLogApi, seTupdateBackletter, userCreateAuditEnterprise } from "@/api/member/user"
import FileUpload from "@/components/FileUpload/index.vue"
import ImageUpload from "@/components/ImageUpload/index.vue"
import { DICT_TYPE, getDictDatas } from "@/utils/dict"
import ClipboardJS from "clipboard"
import {
  queryMemberScoreRecord,
  queryMemberExchangeRecord,
  queryMemberOperateLevelLog,
  queryMemberLevelDetails, updateMemberLevelDetails
} from "@/api/ecw/memberManagement"
import { getNodeList, getRewardsDetails } from "@/api/ecw/giftManagement"
import OperatingGift from "@/views/ecw/giftManagement/components/operatingGift.vue"
import IntegralRecord from "@/views/ecw/memberManagement/integralRecord"
import {parseTime} from "@/utils/ruoyi";
export default {
  name: "memberDetails",
  components: { ImageUpload, FileUpload, OperatingGift, IntegralRecord },
  data() {
    return {
      // 网点
      nodeList: [],
      //兑换记录:
      dateRangeCreateTimeRecord: [],
      memberRecordList: [],
      memberOperateLevelList: [],
      levelDetails: {
        configId: "",
        memberCode: "",
        memberId: "",
        level: "",
        validityPeriod: "",
        specificSettings: false,
        remarks: "",
        updateTime: "",
        updater: "",
        updaterName: ""
      },
      levelDetailsCanEdit:true,
      levelDetailsTitle:"",
      queryParamsRecord: {
        rewardTitle: "",
        memberId: this.$route.params.id,
        memberName: "", //会员昵称
        redeemType: "", //兑换方式
        status: "",
        rewardCount: "",
        rewardCountOperate: "",
        rewardCode: "",
        entrance: "", //兑换入口
        startTime: "",
        endTime: "",
        nodeId: "",
        pageNo: 1,
        pageSize: 10
      },
      queryParamsLevel: {
        memberId: this.$route.params.id,
        pageNo: 1,
        pageSize: 10
      },
      queryParamsDetails: {
        memberId: this.$route.params.id,
        pageNo: 1,
        pageSize: 10
      },
      queryParams: {
        ruleTitle: "",
        ruleDesc: "",
        key: "",
        sourceType: "",
        scoreCount: "",
        memberId: this.$route.params.id,
        scoreCountOperate: "",
        endTime: "",
        pageNo: 1,
        pageSize: 10,
        startTime: ""
      },
      dateRangeCreateTime: [],
      total: 0,
      totalRecord: 0,
      totalLevelLog: 0,
      activeIndex: "reward",
      // 表单校验
      rulesId: {
        name: [
          {
            required: true,
            message: this.$t("用户昵称不能为空"),
            trigger: "blur"
          }
        ],
        cardType: [
          {
            required: true,
            message: this.$t("证件类型不能为空"),
            trigger: "blur"
          }
        ],
        cardNumber: [
          {
            required: true,
            message: this.$t("证件号码不能为空"),
            trigger: "blur"
          }
        ],
        img1: [
          {
            required: true,
            message: this.$t("身份正面照不能为空"),
            trigger: ["blur", "change"]
          }
        ],
        img2: [
          {
            required: true,
            message: this.$t("身份正面照不能为空"),
            trigger: ["blur", "change"]
          }
        ]
      },
      rulesEnterprise: {
        name: [
          {
            required: true,
            message: this.$t("企业名称不能为空"),
            trigger: "blur"
          }
        ],
        legalName: [
          {
            required: true,
            message: this.$t("企业法人不能为空"),
            trigger: "blur"
          }
        ],
        cardNumber: [
          {
            required: true,
            message: this.$t("证件号码不能为空"),
            trigger: "blur"
          }
        ],
        img1: [
          {
            required: true,
            message: this.$t("证件照不能为空"),
            trigger: ["blur", "change"]
          }
        ]
      },
      rulesDetails: {
        level: [
          {
            required: true,
            message: this.$t("等级不能为空"),
            trigger: "blur"
          }
        ],
        validityPeriod: [
          {
            required: true,
            message: this.$t("等级有效期不能为空"),
            trigger: "blur"
          }
        ],
        remarks: [
          {
            required: true,
            message: this.$t("更新原因不能为空"),
            trigger: "blur"
          }
        ],
      },
      getDictDatas,
      DICT_TYPE,
      details: {
        address: "",
        areaCode: "",
        avatar: "",
        backLetterImg: "",
        birthday: "",
        createTime: "",
        customerStatus: "",
        department: "",
        email: "",
        englishName: "",
        enterpriseAddress: "",
        enterpriseAuditCreateTime: "",
        enterpriseAuditRemark: "",
        enterpriseAuditStatus: "",
        enterpriseAuditTime: "",
        enterpriseBrand: "",
        enterpriseDesc: "",
        enterpriseName: "",
        enterpriseNameEn: "",
        enterpriseStall: "",
        enterpriseWebsite: "",
        gender: "",
        groupCount: "",
        id: "",
        identityAuditCreateTime: "",
        identityAuditRemark: "",
        identityAuditStatus: "",
        identityAuditTime: "",
        identityName: "",
        isDeal: "",
        isSimplePassword: "",
        jobPosition: "",
        loginDate: "",
        loginIp: "",
        mobile: "",
        nickname: "",
        password: "",
        registDate: "",
        registerIp: "",
        status: ""
      },
      publicObj: {},
      guaranteeShow: false,
      guaranteeUrl: "",
      operationLogFrom: {
        page: 1,
        row: 10,
        userId: undefined
      },
      loading: true,
      dialogVisible: false,
      operatingPagetitle: "",
      rewardsItem: {},
      attestationShow: false,
      levelDetailsShow: false,
      modifyLicense: false,
      modifyIdCard: true, //修改身份证
      IdDetails: {},
      enterpriseFrom: {},
      operationLogShow: false,
      activeName: "1",
      operationLogList: [],
      totalLog: 0
    }
  },
  created() {
    this.getDetails()
    this.handleQuery()
    this.handleQueryRecord()
    this.handleQueryOperateLevelLog()
    this.handleQueryDetailsLog()
    this.getNodeListAPI()
  },
  computed: {
    isChinese() {
      return this.$i18n.locale === "zh_CN"
    }
  },
  mounted() {
    let clipboard = new ClipboardJS(".copy-btn")
    clipboard.on("success", () => {
      this.$message.success(this.$t("复制成功"))
    })
    clipboard.on("error", () => {
      this.$message.error(this.$t("复制失败"))
    })
  },
  methods: {
    handleViewRecord(row) {
      this.$router.push({
        path: "/member/memberManagement/exchangeRecordOperation",
        query: { exchangeRewardID: row.id, pageStatus: "view" }
      })
    },
    getNodeListAPI() {
      getNodeList().then((res) => {
        this.nodeList = res.data
      })
    },
    handleShowRewardsDetail(row) {
      let params = {
        id: row.rewardId
      }
      getRewardsDetails(params).then((res) => {
        this.dialogVisible = true
        this.operatingPagetitle = "1"
        this.rewardsItem = res.data
      })
    },
    handleExchangeRedeemType(id) {
      return this.getDictDatas(DICT_TYPE.WAY_OF_RECEIVING).filter((item) => item.value == id)[0]
    },
    //兑换入口
    handleExchangeEntrance(id) {
      return this.getDictDatas(DICT_TYPE.PLATFORM_TYPE).filter((item) => item.value == id)[0]
    },
    //兑换状态
    handleExchangeStatus(id) {
      return this.getDictDatas(DICT_TYPE.REWARD_REDEEM_STATUS).filter((item) => item.value == id)[0]
    },
    handleQueryRecord() {
      this.queryParamsRecord.pageNo = 1
      let params = { ...this.queryParamsRecord }
      if (this.dateRangeCreateTimeRecord) {
        params.startTime = this.dateRangeCreateTimeRecord[0]
        params.endTime = this.dateRangeCreateTimeRecord[1]
      }
      queryMemberExchangeRecord(params).then((res) => {
        this.loading = false
        this.memberRecordList = res.data.list
        this.totalRecord = res.data.total
      })
    },
    handleQueryOperateLevelLog() {
      this.queryParamsLevel.pageNo = 1
      let params = { ...this.queryParamsLevel }
      queryMemberOperateLevelLog(params).then((res) => {
        this.loading = false
        this.memberOperateLevelList = res.data.list
        this.totalLevelLog = res.data.total
      })
    },
    handleQueryDetailsLog() {
      this.queryParamsDetails.pageNo = 1
      let params = { ...this.queryParamsDetails }
      queryMemberLevelDetails(params).then((res) => {
        this.loading = false
        if (res.data.list.length > 0){
          this.levelDetails = res.data.list[0]
          this.levelDetails.validityPeriod=parseTime(this.levelDetails.validityPeriod)
        }
      })
    },

    resetQueryRecord() {
      this.loading = true
      this.dateRangeCreateTimeRecord = []
      this.queryParamsRecord = {
        country: null,
        city: null,
        endTime: null,
        holdScore: null,
        memberId: this.$route.params.id,
        holdScoreOperate: null,
        key: null,
        pageNo: 1,
        pageSize: 10,
        startTime: null,
        usedScore: null,
        usedScoreOperate: null
      }
      this.handleQueryRecord()
    },

    handleQueryPaginationRecord() {
      let params = { ...this.queryParamsRecord }
      if (this.dateRangeCreateTimeRecord) {
        params.startTime = this.dateRangeCreateTimeRecord[0]
        params.endTime = this.dateRangeCreateTimeRecord[1]
      }
      queryMemberExchangeRecord(params).then((res) => {
        this.loading = false
        this.memberRecordList = res.data.list
        this.totalRecord = res.data.total
      })
    },

    handleQueryPaginationOperateLevelLog() {
      let params = { ...this.queryParamsLevel }
      queryMemberOperateLevelLog(params).then((res) => {
        this.loading = false
        this.memberOperateLevelList = res.data.list
        this.totalLevelLog = res.data.total
      })
    },
    handleMemberUserOperateLog(id) {
      return this.getDictDatas(DICT_TYPE.MEMBER_USER_OPERATE_LOG).filter((item) => item.value == id)[0]
    },

    handleMemberShipLevels(id) {
      return this.getDictDatas(DICT_TYPE.MEMBERSHIP_LEVELS).filter((item) => item.value == id)[0]
    },
    handleSourceType(id) {
      return this.getDictDatas(DICT_TYPE.MEMBER_SCORE_SOURCE).filter((item) => item.value == id)[0]
    },
    handleholdScoreStatus(id) {
      return this.getDictDatas(DICT_TYPE.MEMBER_SCORE_OPERATE_TYPE).filter((item) => item.value == id)[0]
    },
    handleQuery() {
      this.queryParams.pageNo = 1
      let params = { ...this.queryParams }

      if (this.dateRangeCreateTime) {
        params.startTime = this.dateRangeCreateTime[0]
        params.endTime = this.dateRangeCreateTime[1]
      }
      queryMemberScoreRecord(params).then((res) => {
        this.loading = false
        this.memberList = res.data.list
        this.total = res.data.total
      })
    },
    handleQueryPagination() {
      let params = { ...this.queryParams }
      if (this.dateRangeCreateTime) {
        params.startTime = this.dateRangeCreateTime[0]
        params.endTime = this.dateRangeCreateTime[1]
      }
      queryMemberScoreRecord(params).then((res) => {
        this.loading = false
        this.memberList = res.data.list
        this.total = res.data.total
      })
    },
    resetQuery() {
      this.loading = true
      this.dateRangeCreateTime = []
      this.queryParams = {
        ruleTitle: "",
        ruleDesc: "",
        key: "",
        sourceType: "",
        scoreCount: "",
        memberId: this.$route.params.id,
        scoreCountOperate: "",
        endTime: "",
        pageNo: 1,
        pageSize: 100,
        startTime: ""
      }
      this.handleQuery()
    },
    handleCopyReferralCode(details) {},
    handleSelect(key, keyPath) {
      console.log(key, keyPath)
      this.activeIndex = key
    },
    handleExchangeRewards(details) {
      this.$router.push({
        path: "/member/memberManagement/exchangeRecordOperation",
        query: {
          memberId: details.userScoreLevelInfo.memberId,
          pageStatus: "add"
        }
      })
    },
    deleteFn(row) {
      const nickname = row.nickname
      this.$modal
        .confirm(`${this.$t("是否确认删除昵称为{nickname}的会员?", { nickname })}`)
        .then(function () {
          return deleteUser(row.id)
        })
        .then((res) => {
          this.$message.success(this.$t("删除成功"))
          this.$router.back()
        })
        .catch(() => {
          // this.$message.success(this.$t('删除失败'))
        })
    },
    getDetails() {
      memberUserGet({ id: this.$route.params.id }).then((r) => {
        this.details = r.data
      })
    },
    // 保函证书
    guarantee(row) {
      this.publicObj = row
      this.guaranteeShow = true
      this.guaranteeUrl = row.backLetterImg
    },
    // 操作日志
    operationLogFn(row) {
      this.publicObj = row
      this.operationLogFrom.page = 1
      this.operationLogFrom.userId = row.id
      this.operationLogShow = true
      this.operationLogList = []
      this.getOperationLogList()
    },
    getOperationLogList() {
      operationLogApi(this.operationLogFrom).then((r) => {
        if (r.code === 0) {
          this.operationLogList = r.data.list
          this.totalLog = r.data.total
        }
      })
    },
    identityFn(row, val) {
      this.attestationShow = true
      this.activeName = val
      this.publicObj = row
      if (val == 1) {
        this.getIdentityDetails()
      } else {
        this.getEnterpriseFn()
      }
    },
    openLevelDetail(val){
      this.levelDetailsShow=true;
      if (val == 1){
        this.levelDetailsCanEdit=false;
        this.levelDetailsTitle=this.$t("会员等级页面详情编辑");
      }else{
        this.levelDetailsCanEdit=true;
        this.levelDetailsTitle=this.$t("会员等级页面详情查看");
      }

    },
    closeLevelDetail(){
      this.levelDetailsShow=false;
    },
    submitDetails(){
      let params = { ...this.levelDetails }
      if (params.memberId==''){
        params.memberId = this.$route.params.id
      }
      this.$refs["formDetails"].validate((valid) => {
        if (valid){
          updateMemberLevelDetails(params).then((res) => {
            if (res.code == 0){
              this.loading = false;
              this.handleQueryOperateLevelLog();
              this.handleQueryDetailsLog();
              this.$message.success(this.$t("更新成功"));
              this.levelDetailsShow=false;
              this.getDetails()
            }
          })
        }
      })

    },
    handleClick(val) {
      if (val.name == 1) {
        this.getIdentityDetails()
      } else {
        this.getEnterpriseFn()
      }
    },
    getIdentityDetails() {
      this.resetId()
      memberGetAuthIdcardInfo({ userId: this.publicObj.id }).then((r) => {
        if (r.code === 0 && !!r.data) {
          this.IdDetails = r.data
        }
      })
    },
    getEnterpriseFn() {
      this.resetEnterprise()
      memberGetAuthEnterpriseInfo({ userId: this.publicObj.id }).then((r) => {
        if (r.code === 0 && !!r.data) {
          this.enterpriseFrom = r.data
        }
      })
    },
    //身份证审核
    idCardAuditFn(val) {
      let p = {
        auditStatus: val,
        userCardAuthId: this.IdDetails.id,
        auditRemark: this.IdDetails.auditRemark
      }
      memberUserAuditIdCard(p).then((r) => {
        if (r.code === 0) {
          this.$message.success(this.$t("修改成功"))
          this.getList()
          this.getIdentityDetails()
        }
      })
    },
    //  企业证书审核
    certificateVerificationFn(val) {
      let p = {
        auditStatus: val,
        userEnterpriseAuthId: this.enterpriseFrom.id,
        auditRemark: this.enterpriseFrom.auditRemark
      }
      memberUserAuditEnterprise(p).then((r) => {
        if (r.code === 0) {
          this.getList()
          this.getEnterpriseFn()
        }
      })
    },
    setMemberUserUpdateIdCard() {
      this.$refs.formId.validate(async (valid) => {
        if (valid) {
          let p = {
            cardNumber: this.IdDetails.cardNumber,
            cardType: this.IdDetails.cardType,
            img1: this.IdDetails.img1,
            img2: this.IdDetails.img2,
            name: this.IdDetails.name,
            userCardAuthId: this.IdDetails.id,
            auditPass: true
          }
          memberUserUpdateIdCard(p).then((r) => {
            if (r.code === 0) {
              this.$message.success(this.$t("修改成功"))
              if (p.auditPass === true) {
                this.getIdentityDetails()
              }
              this.getList()
              this.modifyIdCard = true
            }
          })
        }
      })
    },
    setMemberUserUpdateEnterprise() {
      this.$refs.formEnter.validate(async (valid) => {
        if (valid) {
          let p = {
            cardNumber: this.enterpriseFrom.cardNumber,
            img1: this.enterpriseFrom.img1,
            img2: this.enterpriseFrom.img2,
            legalName: this.enterpriseFrom.legalName,
            name: this.enterpriseFrom.name,
            userEnterpriseAuthId: this.enterpriseFrom.id,
            auditPass: true
          }
          memberUserUpdateEnterprise(p).then((r) => {
            if (r.code === 0) {
              if (p.auditPass === true) {
                this.getEnterpriseFn()
              }
              this.getList()
              this.modifyLicense = true
              this.$message.success(this.$t("修改成功"))
            }
          })
        }
      })
    },
    submit() {
      let p = {
        cardNumber: this.enterpriseFrom.cardNumber,
        img1: this.enterpriseFrom.img1,
        img2: this.enterpriseFrom.img2,
        legalName: this.enterpriseFrom.legalName,
        name: this.enterpriseFrom.name,
        userEnterpriseAuthId: this.enterpriseFrom.id,
        userId: this.publicObj.id
      }
      userCreateAuditEnterprise(p).then((r) => {
        if (r.code === 0) {
          this.$message.success(this.$t("添加成功!"))
          this.enterpriseFrom.status = 2
          this.enterpriseFrom.auditTime = new Date().getTime()
          this.getEnterpriseFn()
          this.getList()
        }
      })
    },
    submitId() {
      this.$refs.formId.validate(async (valid) => {
        if (valid) {
          let p = {
            cardNumber: this.IdDetails.cardNumber,
            cardType: this.IdDetails.cardType,
            img1: this.IdDetails.img1,
            img2: this.IdDetails.img2,
            name: this.IdDetails.name,
            status: 2,
            userId: this.publicObj.id
          }
          createAuditIdCard(p).then((r) => {
            if (r.code === 0) {
              this.$message.success(this.$t("添加成功!"))
              this.IdDetails.status = 2
              this.IdDetails.auditTime = new Date().getTime()
              this.getIdentityDetails()
              this.getList()
            }
          })
        }
      })
    },
    /** 表单重置 */
    resetId() {
      this.IdDetails = {
        auditRemark: undefined,
        auditTime: undefined,
        cardNumber: undefined,
        cardType: undefined,
        createTime: undefined,
        id: 0,
        img1: undefined,
        img2: undefined,
        name: "",
        status: 0,
        userId: 0
      }
    }, //清空身份证
    resetEnterprise() {
      this.enterpriseFrom = {
        auditRemark: undefined,
        auditTime: undefined,
        cardNumber: undefined,
        createTime: undefined,
        id: undefined,
        img1: undefined,
        img2: undefined,
        legalName: undefined,
        name: undefined,
        status: 0,
        userId: undefined
      }
    }, //清空企业
    setGuarantee() {
      seTupdateBackletter({
        userId: this.publicObj.id,
        backLetter: this.guaranteeUrl
      }).then((r) => {
        if (r.code === 0) {
          this.publicObj.backLetterImg = this.guaranteeUrl
          this.guaranteeShow = false
          this.$message.success(this.$t("保存成功"))
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.table-container {
  padding-top: 20px;
}
</style>
