<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-row">
        <div class="filter-group">
          <div class="filter-lable"> 关键字：</div>
          <el-input v-model="KEYWORDS" placeholder="搜索" clearable style="width: 200px;" @clear="getQuery"/>
        </div>
        <div class="filter-group">
          <div class="filter-lable"> 反馈类型：</div>
          <el-select v-model="FEEDBACK_TYPE" placeholder="反馈类型" clearable style="width: 150px" class="filter-item">
            <el-option v-for="item in feedbacktype" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </div>
        <el-button v-waves class="ml-10" type="primary" icon="el-icon-search" @click="getQuery">
          搜索
        </el-button>
        <el-button v-waves type="success" icon="el-icon-refresh" @click="goKeyReset">
          重置
        </el-button>
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      ref="multipleTable"
      :data="varList"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        :reserve-selection="true"
        type="selection"
        width="55"
        align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="FEEDBACK_TITLE" label="标题" />
      <el-table-column prop="FEEDBACK_TYPE" label="反馈类型" align="center" >
        <template slot-scope="{row}">
          <div v-if="row.FEEDBACK_TYPE =='1'">系统错误</div>
          <div v-if="row.FEEDBACK_TYPE =='2'">界面优化</div>
          <div v-if="row.FEEDBACK_TYPE =='3'">设计缺陷</div>
          <div v-if="row.FEEDBACK_TYPE =='4'">性能问题</div>
          <div v-if="row.FEEDBACK_TYPE =='9'">其他</div>
        </template>
      </el-table-column>
      <el-table-column prop="CORP_NAME" label="企业名称" />
      <el-table-column prop="NAME" label="用户姓名" />
      <el-table-column prop="CREAT_NAME" label="反馈用户手机号" />
      <el-table-column prop="FEEDBACK_IMG" label="照片或截图" >
        <template slot-scope="{row}">
          <el-tooltip placement="top">
            <div slot="content">
              <viewer v-if="row.FEEDBACK_IMG.length > 0">
                <img v-for="item in row.FEEDBACK_IMG" :key="item" :src="config.fileUrl + item" alt="" width="50" height="50">
              </viewer>
              <div v-else>暂无图片</div>
            </div>
            <el-tag>预览</el-tag>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="FEEDBACK_CONTENT" label="意见" align="center" />
      <el-table-column prop="CREAT_TIME" label="反馈时间" />
      <!--      <el-table-column label="操作" align="center" width="100">-->
      <!--        <template slot-scope="{row}">-->
      <!--          <div class="clear_interval">-->
      <!--            <el-button v-show="del" type="danger" icon="el-icon-delete" size="mini" @click="handleDelete(row.APPFEEDBACK_ID)">删除</el-button>-->
      <!--          </div>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <div class="page-btn-group">
      <div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
// import { upload } from '@/utils/upload'
import pdf from 'vue-pdf'
import SelectTree from '@/components/SelectTree'
export default {
  components: { Pagination, pdf, SelectTree },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      KEYWORDS_USER: '',
      dates: [],
      userListQuery: {
        page: 1,
        limit: 10
      },
      userTotal: 0,
      total: 0,
      config: config,
      KEYWORDS: '',
      FEEDBACK_TYPE: '',
      varList: [],
      feedbacktype: [{
        value: '1',
        label: '系统错误'
      }, {
        value: '2',
        label: '界面优化'
      }, {
        value: '3',
        label: '设计缺陷'
      }, {
        value: '4',
        label: '性能问题'
      }, {
        value: '9',
        label: '其他'
      }],
      pd: [],
      corpVarList: [],
      form: {
        TITLE: '',
        BEGIN_TIME: '',
        END_TIME: '',
        IS_PUBLISH: '',
        dialogVisible: false,
        fileIsType: true,
        trainingSection: [],
        relatedTerm: [],
        captureIsType: true
      },
      hideUpload: false, // 显示图片
      fileList: [],
      defaultProps: {
        value: 'id',
        children: 'nodes',
        label: 'name'
      },
      multipleSelectionAll: [], // 所有选中的数据包含跨页数据
      multipleSelection: [], // 当前页选中的数据
      dialogFormEdit: false,
      dialogFormUser: false,
      dialogType: 'add',
      LearnerCategoryList: [],
      // pdf预览
      dialogViewPdf: false,
      serverurl: config.fileUrl,
      pdfUrl: '',
      pageNum: 1,
      pageTotalNum: 1, // 总页数
      loadedRatio: 0 // 当前页面的加载进度，范围是0-1 ，等于1的时候代表当前页已经完全加载完成了
    }
  },
  created() {
    this.getList()
    this.getDict()
    // this.getIdcList()
  },
  methods: {
    getRowKey(row) {
      return row.SURVEY_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.FEEDBACK_TYPE = ''
      this.getQuery()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/feedback/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS,
          FEEDBACK_TYPE: this.FEEDBACK_TYPE,
          CREAT_TIME: this.CREAT_TIME
        }
      ).then((data) => {
        for (let i = 0; i < data.varList.length; i++) {
          data.varList[i].FEEDBACK_IMG = data.varList[i].FEEDBACK_IMG.split(';')
        }
        this.listLoading = false
        this.varList = data.varList
        this.hasButton()
        this.total = data.page.totalResult
        this.pd = data.pd
      }).catch((e) => {
        this.listLoading = false
      })
    },

    validStr(str) {
      if (str != null && str != '' && typeof (str) != 'undefined' && str != 0) { return true }
      return false
    },
    beforeDataFileUpload(file) {
      const types = ['doc', 'docx', 'pdf']
      const fileSuffix = file.name.slice(file.name.lastIndexOf('.') + 1)
      const isImage = types.includes(fileSuffix.toLowerCase())
      if (this.fileList.length > 0) {
        this.$message.error('文件超出个数限制!')
        return false
      }
      if (!isImage) {
        this.$message.error('上传文件格式只能是PDF 格式!')
        return false
      } else {
        const filistMap = {}
        filistMap.name = file.name
        filistMap.file = file
        this.fileList.push(filistMap)
        this.form.cfile = file
        this.form.COURSEWAREFILES = file
        this.$forceUpdate()
        return true
      }
    },
    handleRemoveData(file, fileList) { // 文件列表移除文件时的钩子
      if (file.file) {
        const types = ['doc', 'docx', 'pdf']
        const isImage = types.includes(file.file.type)
        if (isImage) {
          this.fileList = []
        }
      }
    },
    beforeCaptureFileUpload(file) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
      } else {
        this.form.ccfile = file
        this.form.COURSEWARECAPTURE = file
        this.$forceUpdate()
        return false
      }
    },
    handlePictureCardPreview(file, fileList) {
      this.form.ccfile = file
      this.form.COURSEWARECAPTURE = file
      this.form.dialogImageUrl = file.url
      this.form.dialogVisible = true
    },
    handleRemove(file, fileList) {
      this.form.ccfile = file
      this.form.COURSEWARECAPTURE = file
      this.hideUpload = fileList.length >= 1
    },
    handleEditChange(file, fileList) {
      this.form.ccfile = file
      this.form.COURSEWARECAPTURE = file
      this.hideUpload = fileList.length >= 1
    },
    // pdf 预览
    goViewPdf(filePath) {
      this.pageNum = 1
      this.pdfUrl = this.serverurl + filePath
      this.dialogViewPdf = true
    },
    // 上一页
    prePage() {
      let page = this.pageNum
      page = page > 1 ? page - 1 : this.pageTotalNum
      this.pageNum = page
    },

    // 下一页
    nextPage() {
      let page = this.pageNum
      page = page < this.pageTotalNum ? page + 1 : 1
      this.pageNum = page
    },

    handleDelete(id) {
      this.$confirm('确定要删除吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/feedback/delete',
          {
            SURVEY_ID: id
          }
        ).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.listLoading = false
          this.varList = []
          this.listQuery.page = 1
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    },

    batchDel() {
      const _selectData = this.$refs.multipleTable.selection
      if (_selectData == null || _selectData.length == 0) {
        this.$message({
          message: '请选中要删除的项...',
          type: 'error'
        })
        return false
      }
      const ids = _selectData.map((item, index) => {
        return item.DATACOURSEWARE_ID
      }).join(',')

      this.$confirm('确定要删除选中的数据吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/feedback/deleteAll',
          {
            DATA_IDS: ids
          }
        ).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.listLoading = false
          this.varList = []
          this.listQuery.page = 1
          this.$refs.multipleTable.clearSelection()
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    },
    // 判断按钮权限，用于是否显示按钮
    hasButton: function() {
      var keys = 'surveyquestion:add,surveyquestion:del,surveyquestion:edit,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys
        }
      ).then((data) => {
        this.add = data.surveyquestionfhadminadd		// 新增权限
        this.del = data.surveyquestionfhadmindel		// 删除权限
        this.edit = data.surveyquestionfhadminedit	// 修改权限
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 获取数据字典数据
    getDict: function() {
      // requestFN(
      //   '/dictionaries/getLevels',
      //   {
      //     DICTIONARIES_ID: '532282f9c48346b8b646531909c739df'
      //   }
      // ).then((data) => {
      //   this.LearnerCategoryList = data.list
      // }).catch((e) => {
      //
      // })
      // requestFN(
      //   '/dictionaries/getLevels',
      //   {
      //     DICTIONARIES_ID: '3c0d9b5e74834adfacb76139e5d731e5'
      //   }
      // ).then((data) => {
      //   this.dicListMap.outlineDicList = data.list
      // }).catch((e) => {
      // })
    },
    resetForm() {
      this.form = {
        TITLE: '',
        BEGIN_TIME: '',
        END_TIME: '',
        IS_PUBLISH: '',
        fileIsType: true,
        captureIsType: true
      }
      // if (this.$refs.pxTree) {
      //   this.$refs.pxTree.clearHandle()
      // }
      // if (this.$refs.gwTree) {
      //   this.$refs.gwTree.clearHandle()
      // }
      // if (this.$refs.dataUpload || this.fileList.length > 0) {
      //   this.fileList = []
      //   // this.form.ccfile = ''
      //   // this.form.COURSEWARECAPTURE = ''
      //   this.hideUpload = false
      //   this.$refs.dataUpload.clearFiles()
      // }
      // if (this.$refs.dataCaptureUpload) {
      //   this.form.cfile = ''
      //   this.$refs.dataCaptureUpload.clearFiles()
      // }
    },
    getDicListByPID(pId, listName) {
      requestFN(
        '/dictionaries/listAllDictToParId',
        {
          parentId: pId
        }
      ).then((data) => {
        this.dicListMap[listName] = JSON.parse(data.zTreeNodes)
      }).catch((e) => {

      })
    },
    // getIdcList() {
    //   this.getDicListByPID('052369aa22d242118236cde52d0c67ea', 'trainDicList')
    //   this.getDicListByPID('f6a7c4f5602f46e291d06b1390a3f820', 'postDicList')
    //   this.getDicListByPID('d538d11e4eec409ab428f5d2f3c67c24', 'trainingSectionList') // 培训板块
    //   this.getDicListByPID('4459d3ff36d1475d8b2266da959fcc44', 'relatedTermList') // 相关词条
    //   this.getTeacher()
    // },
    // 修改
    handleEditState(ID, state) {
      requestFN(
        '/survey/editState',
        {
          SURVEY_ID: ID,
          IS_PUBLISH: state
        }
      ).then((data) => {
        this.$message({
          message: '发布成功',
          type: 'success'
        })
        this.getList()
      }).catch((e) => {
        this.listLoading = false
      })
    },
    delFujian(item) {
      this.form.fileIsType = true
      this.form.COURSEWAREFILES = ''
    },
    delFujianTupian(item) {
      this.form.captureIsType = true
      this.form.COURSEWARECAPTURE = ''
      this.form.ccfile = ''
      this.hideUpload = false
    }

  }
}

</script>
<style lang="scss">
  .hide .el-upload--picture-card {
    display: none;
  }
  div.popContainer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
  }
</style>
