<template>
    <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="keyWord">
          <el-input
            v-model="queryParams.keyWord"
            placeholder="请输入关键字"
            clearable maxlength="20"
            style="width: 200px" 
          />
        </el-form-item>
        <!-- <el-form-item label="证件编号" prop="certificateNo">
          <el-input
            v-model="queryParams.certificateNo"
            placeholder="请输入证件编号"
            clearable maxlength="20"
            style="width: 200px" 
          />
        </el-form-item> 
        <el-form-item label="证件类型" prop="certificateType">
          <el-select v-model="queryParams.certificateType" placeholder="证件类型" clearable style="width: 200px"> 
            <el-option
              v-for="dict in dict.type.sys_certificate_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="核验状态" prop="verifyState">
          <el-select v-model="queryParams.verifyState" placeholder="核验状态" clearable style="width: 200px"> 
            <el-option  label="待验证" value="0" />
            <el-option  label="已验证" value="1" />
          </el-select>
        </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"> 
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row> 
      <el-table v-loading="loading" :data="tableListData" height="800"> 
        <el-table-column label="序号" align="center" width="80" type="index">
            <template slot-scope="scope">
                <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
        </el-table-column>
        <el-table-column label="姓名" align="center" prop="createBy" :show-overflow-tooltip="true"/>
        <el-table-column label="联系方式" align="center" prop="contacts" :show-overflow-tooltip="true"/> 
        <el-table-column label="类型" align="center" prop="type" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              <span v-if="scope.row.type==1">后台问题</span>
              <span v-if="scope.row.type==2">APP问题</span> 
          </template>
        </el-table-column>
        <el-table-column label="问题/建议描述" align="center" prop="detail" :show-overflow-tooltip="true"/>
        <el-table-column label="附件" align="center" prop="" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span v-if="scope.row.fileUrl!=''" @click="checkFile(scope.row)" style="cursor: pointer;color: #46a6ff;">查看</span>
            <span v-else>无附件</span>
          </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="openFile" width="500px" append-to-body>
        <div style="width: 100%;height: 240px;padding: 10px;color: #46a6ff;display: flex;flex-wrap: wrap;">
          <div v-for="(item,index) in fileList" :key="index" style="margin: 10px;">
            <div style="margin-bottom: 10px;"><img :src="item.url" @click="handlePictureCardPreview(item)" style="width: 60px;height: 60px;margin-right: 8px;"/></div>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="openFile=false">关 闭</el-button>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="dialogVisible" width="700px">
        <img style="width: 100%;height: 100%;" :src="dialogImageUrl" alt="">
      </el-dialog>
    </div>
  </template>

  <script>
    import { getFeedbackListPageApi } from "@/api/certificateManage/index";
    import base64 from 'base-64';
    import { getToken } from '@/utils/auth'
    import { downloadFileByUrl } from '@/utils/download'
    import Treeselect from '@riophae/vue-treeselect'
    import '@riophae/vue-treeselect/dist/vue-treeselect.css'
    export default {
        name: "",
        dicts: ["sys_certificate_type"],
        components: { Treeselect },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                //表格数据
                tableListData: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false, 
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    keyWord:null,
                },
                fileList:[], 
                openFile:false,//查看附件 
                dialogVisible:false,//图片弹窗
                dialogImageUrl:"",//图片弹窗 
            };
        },
        mounted(){
            this.getList();

        },

        methods: { 
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.queryParams = {
                  pageNum: 1,
                  pageSize: 10,
                  keyWord:null,//姓名 
                }
                this.resetForm("queryForm");
                this.handleQuery();
            },
            /** 查询列表 */
            getList() { 
                let param = {
                    "pageNum":this.queryParams.pageNum,
                    "pageSize":this.queryParams.pageSize, 
                    "keyWord":this.queryParams.keyWord, 
                }
                console.log("param",param)
                getFeedbackListPageApi(param).then(response => {
                    this.tableListData = response.rows;
                    this.total = Number(response.total);
                    this.loading = false;
                });
            },
            checkFile(row){
              this.fileList=[] 
              if(row.fileUrl&&row.fileUrl!=''){
                let arr =  row.fileUrl.split(","); 
                arr.forEach((item,index)=>{
                  this.fileList.push({url:item}) 
                })
              }
              this.openFile = true
            },
            //图片点击查看
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url
                this.dialogVisible = true
            }, 
            formatDate(date) {
                // 格式化为 YYYY-MM-DD
                const year = date.getFullYear();
                const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
                const day = String(date.getDate()).padStart(2, '0');
                return `${year}-${month}-${day}`;
            },
        }
    };
  </script>
  <style scoped lang="scss">
    .form-title{
        display: flex;
        align-items: flex-end;
        // width: 100%;
        // height: 40px;
        background: #e7f0fa;
        border-left: 3px solid #46a6ff;
        margin: 10px 0;
        padding: 5px;
    }
    .form-item{
        width: 100%;
        font-size: 14px !important;
    }
  </style>
