<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="80%" append-to-body>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="审核时间" prop="startEndTime">
          <el-date-picker
            v-model="startEndTime"
            clearable
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="类型" prop="identityType">
          <el-select v-model="queryParams.identityType" placeholder="请选择通告主身份类型" clearable>
            <el-option
              v-for="dict in dict.type.dl_identity_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="昵称" prop="nickname">
          <el-input
            v-model="queryParams.nickname"
            placeholder="请输入通告主昵称"
            clearable
            @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-table v-loading="loading" :data="applyList" >
        <el-table-column label="通告主昵称" align="center" prop="nickname"/>
        <el-table-column label="身份类型" align="center" prop="identityType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.dl_identity_type" :value="scope.row.identityType"/>
          </template>
        </el-table-column>
<!--        <el-table-column label="申请描述" align="center" prop="content"/>-->
<!--        <el-table-column label="备注" align="center" prop="remark"/>-->
        <el-table-column label="审核状态" align="center" prop="approvalStatus">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.dl_approval_status" :value="scope.row.approvalStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="detail(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="查看详情" :visible.sync="open" width="800px" append-to-body>
        <el-form ref="form" :model="form" label-width="80px">

          <el-card class="box-card">
            <div slot="header" class="clearfix">
              基本信息
            </div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="通告主" prop="nickname">
                  <el-input :readonly="true" v-model="form.nickname" placeholder="请输入申请者昵称"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="认证身份" prop="identityType">
                  <!--                <el-select :disabled="true" v-model="form.identityType" placeholder="请选择申请认证的通告主身份类型">-->
                  <!--                  <el-option-->
                  <!--                    v-for="dict in dict.type.dl_identity_type"-->
                  <!--                    :key="dict.value"-->
                  <!--                    :label="dict.label"-->
                  <!--                    :value="dict.value"-->
                  <!--                  ></el-option>-->
                  <!--                </el-select>-->
                  <dict-tag :options="dict.type.dl_identity_type" :value="form.identityType"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              资质认证
            </div>
            <el-row>
              <!-- 只有品牌方有-->
              <el-col v-if="form.identityType == '01'" :span="12">
                <el-form-item label="品牌名">
                  <el-input :readonly="true" v-model="applyJson.brandName"/>
                </el-form-item>
              </el-col>
              <el-col v-if="form.identityType == '01' || form.identityType == '02'" :span="12">
                <el-form-item label="公司全称">
                  <el-input :readonly="true" v-model="applyJson.corpName"/>
                </el-form-item>
              </el-col>
              <el-col v-if="form.identityType == '04'" :span="12">
                <el-form-item label="店铺名称">
                  <el-input :readonly="true" v-model="applyJson.shopName"/>
                </el-form-item>
              </el-col>
              <el-col v-if="form.identityType == '04'" :span="12">
                <el-form-item label="店铺链接">
                  <el-input :readonly="true" v-model="applyJson.shopLink"/>
                </el-form-item>
              </el-col>
              <el-col v-if="form.identityType == '03'" :span="12">
                <el-form-item label="授权公司">
                  <el-input :readonly="true" v-model="applyJson.authCorpName"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="行业领域">
                  <el-input :readonly="true" v-model="applyJson.industry" />
                </el-form-item>
              </el-col>
              <el-col v-if="form.identityType == '01' || form.identityType == '02' || form.identityType == '04'" :span="12">
                <el-form-item label="公司所在城市">
                  <el-input :readonly="true" v-model="applyJson.corpCityName"/>
                </el-form-item>
              </el-col>
              <el-col v-if="form.identityType == '03'" :span="12">
                <el-form-item label="个人所在城市">
                  <el-input :readonly="true" v-model="applyJson.personCityName"/>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <!-- 只有品牌方有-->
              <el-col v-if="form.identityType == '01'" :span="12">
                <el-form-item label="商标注册证" prop="images">
                  <ImageUpload v-model="applyJson.tradeImage" :limit="1" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
              <!-- 品牌方、代运营公司  -->
              <el-col v-if="form.identityType == '01' || form.identityType == '02' || form.identityType == '04'" :span="12">
                <el-form-item label="营业执照" prop="images">
                  <ImageUpload v-model="applyJson.busiImage" :limit="1" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="form.identityType == '02' || form.identityType == '03'">
              <el-col :span="24">
                <el-form-item label="沟通记录" prop="images">
                  <ImageUpload v-model="applyJson.recordImage" :limit="9" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="form.identityType == '03'">
              <el-col :span="24">
                <el-form-item label="授权合同" prop="images">
                  <ImageUpload v-model="applyJson.contractImage" :limit="9" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="form.identityType == '04'">
              <el-col :span="24">
                <el-form-item label="店铺后台截图" prop="images">
                  <ImageUpload v-model="applyJson.shopImage" :limit="9" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="form.identityType == '04'">
              <el-col :span="24">
                <el-form-item label="店铺物流截图" prop="images">
                  <ImageUpload v-model="applyJson.logisticsImage" :limit="9" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
            </el-row>

          </el-card>
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              身份认证
            </div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="姓名">
                  <el-input :readonly="true" v-model="applyJson.name"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="身份证号">
                  <el-input :readonly="true" v-model="applyJson.idCard"/>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="附言">
                  <el-input type="textarea" :rows="2" :readonly="true" v-model="applyJson.review"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="在职证明材料" prop="images">
                  <ImageUpload v-model="applyJson.jobImage" :limit="9" :isShowTip="false" :disabled="true"></ImageUpload>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>

          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>审核信息</span>
            </div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="审核状态" prop="approvalStatus">
                  <el-select :readonly="true" v-model="form.approvalStatus" placeholder="待审核">
                    <el-option
                      v-for="item in statusOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="审核备注" prop="approvalRemark">
                  <el-input :readonly="true" v-model="form.approvalRemark" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-form>
      </el-dialog>
    </div>
  </el-dialog>
</template>

<script>
import {listApply, getApply,} from "@/api/member/apply";
import {formatDateDay} from "@/utils/index";
export default {
  name: "applyForm",
  dicts: ['dl_identity_type','dl_approval_status'],
  data(){
    return{
      // 弹出层标题
      dialogTitle: "审核历史",
      // 是否显示弹出层
      dialogVisible: false,
      open:false,
      statusOptions: [{
        value: '0',
        label: '待审核'
      }, {
        value: '1',
        label: '通过'
      }, {
        value: '9',
        label: '不通过'
      }],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approvalStatus:10,
        nickname: null,
        identityType: null,
      },
      //创建时间段
      startEndTime: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 通告主认证申请表格数据
      applyList: [],

      applyJson:{
        tradeImage: "",
        busiImage: "",
        recordImage: "",
        contractImage: "",
        shopImage: "",
        jobImage: "",
        logisticsImage: "",
        brandName: "",
        corpName: "",
        authCorpName: "",
        shopName: "",
        shopLink: "",
        industry: "",
        corpCityCode: null,
        corpCityName: "",
        personCityCode: null,
        personCityName: "",
        name: "",
        idCard: "",
        review: ""
      },
      // 表单参数
      form: {},


    }
  },
  methods: {
    initForm(){
      this.dialogVisible = true;
      this.getList()
    },

    /** 查询通告主认证申请列表 */
    getList() {
      this.loading = true;
      console.log(this.startEndTime, "startEndTime")
      if (this.startEndTime.length > 0) {
        this.queryParams.startTime = formatDateDay(this.startEndTime[0])
        this.queryParams.endTime = formatDateDay(this.startEndTime[1])
      } else {
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      }
      listApply(this.queryParams).then(response => {
        this.applyList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.startEndTime = []
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 详情 */
    detail(row) {
      this.reset();
      const id = row.id || this.ids
      getApply(id).then(response => {
        this.form = response.data;
        this.applyJson = JSON.parse(response.data.applyJson)
        this.open = true;
        this.title = "审核详情";
      });
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        nickname: null,
        identityType: null,
        content: null,
        remark: null,
        images: null,
        approvalStatus: null,
        approvalUserId: null,
        approvalTime: null,
        approvalRemark: null,
        creator: null,
        createTime: null,
        updater: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },

  }
}
</script>

<style scoped>
/deep/.el-dialog__body {
  padding: 0px 10px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
}
/deep/.el-form-item {
  margin-bottom: 10px;
}
</style>
