<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">
              <span>申请信息</span>
            </div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="通告主" prop="nickname">
                  <el-input :disabled="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>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="申请描述">
                  <el-input :disabled="true" type="textarea" v-model="form.content" placeholder="请输入申请描述"/>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注" prop="remark">
                  <el-input :disabled="true" type="textarea" v-model="form.remark" placeholder="请输入内容"/>
                </el-form-item>
              </el-col>
              <el-col>
                <el-form-item label="附件" prop="images">
                  <ImageUpload v-model="form.images" :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="identityType">
                  <el-select :disabled="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 :disabled="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: '2',
        label: '不通过'
      }],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approvalStatus:10,
        nickname: null,
        identityType: null,
      },
      //创建时间段
      startEndTime: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 通告主认证申请表格数据
      applyList: [],
      // 表单参数
      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.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>

</style>
