<!--案卷详情 只读-->
<template>
  <app-container>
    <div class="detail-title">
      <div class="table-title">
        <div class="title-header"><i class="el-icon-menu"/>案卷详情</div>
        <div class="edit_btns">
          <el-button class="edit_btn" size="small" @click="dialogVisible = true">查看地图</el-button>
        </div>
      </div>
    </div>
    <div class="detail-block">
      <el-form ref="caseform" class="form" size="small" label-width="90px">

        <div class="detail-row">
          <div class="detail-item">
            <el-form-item label="案卷编号">
              <el-input :value="caseDetail.caseid"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="信息来源">
              <el-input :value="caseDetail.sourceName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="举报人/电话">
              <el-input :value="caseDetail.reporterName+'/'+caseDetail.reporterPhone"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="上报人员">
              <el-input :value="caseDetail.createUserName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="案卷类别">
              <el-input :value="caseDetail.eorcName"/>
            </el-form-item>
          </div>
        </div>
        <div class="detail-row">
          <div class="detail-item">
            <el-form-item label="案卷大类">
              <el-input :value="caseDetail.casetypeName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="案卷小类">
              <el-input :value="caseDetail.casetypeDetailName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="案卷等级">
              <el-input :value="caseDetail.caseLevelName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="所在区县">
              <el-input :value="caseDetail.areaName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="所在乡镇">
              <el-input :value="caseDetail.streetName"/>
            </el-form-item>
          </div>
        </div>
        <div class="detail-row">
          <div class="detail-item">
            <el-form-item label="所在社区">
              <el-input :value="caseDetail.communityName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="登记时间">
              <el-input :value="caseDetail.createTime"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="处理时限">
              <el-input :value="caseDetail.bzhours+'小时'+caseDetail.bzminis+'分钟'"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="完成时限">
              <el-input :value="caseDetail.nodeLimittime"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item label="是否回访">
              <el-input :value="isNeedVisit"/>
            </el-form-item>
          </div>
        </div>
        <div v-if="caseDetail.shopkeeperName || caseDetail.shopPhone" class="detail-row">
          <div class="detail-item">
            <el-form-item v-if="caseDetail.shopkeeperName" label="商户名称">
              <el-input :value="caseDetail.shopkeeperName"/>
            </el-form-item>
          </div>
          <div class="detail-item">
            <el-form-item v-if="caseDetail.shopPhone" label="商户电话">
              <el-input :value="caseDetail.shopPhone"/>
            </el-form-item>
          </div>
        </div>
        <div class="detail-row">
          <div class="detail-item" style="width: 99%;display: block;">
            <el-form-item label="立案标准">
              <el-input :value="caseDetail.casetypesTimeName"/>
            </el-form-item>
          </div>
        </div>
        <div class="detail-row">
          <div class="detail-item" style="width: 99%;display: block;">
            <el-form-item label="发生地点">
              <el-input :value="caseDetail.fieldintro"/>
            </el-form-item>
          </div>
        </div>
        <div class="detail-row">
          <div class="detail-item" style="width: 99%;display: block;">
            <el-form-item label="案卷描述">
              <el-input :value="caseDetail.description"/>
            </el-form-item>
          </div>
        </div>
        <div v-if="caseDetail.isSupervise" class="detail-row">
          <div class="detail-item" style="width: 99%;display: block;">
            <el-form-item label="督办意见">
              <el-input :value="caseDetail.superviseRemarks"/>
            </el-form-item>
          </div>
        </div>
        <div v-if="caseDetail.isUrge" class="detail-row">
          <div class="detail-item" style="width: 99%;display: block;">
            <el-form-item label="催办意见">
              <el-input :value="caseDetail.urgeRemarks"/>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>

    <div v-show="hasFile" class="detail-block">
      <div class="title">案卷附件
        <span v-if="!showFile" style="cursor: pointer" @click="funShowFile()"><i class="el-icon-arrow-right"/></span>
        <span v-if="showFile" style="cursor: pointer" @click="funHideFile()"><i class="el-icon-arrow-down"/></span>
      </div>
      <el-tabs v-show="showFile" type="border-card" class="image-container">
        <el-tab-pane v-if="showVerifyFile" label="案卷附件">
          <case-file
            :img-ids="caseDetail.fileIdVerify"
            :video-ids="caseDetail.videoIdVerify"
            :audio-ids="caseDetail.audioIdVerify"
          />
        </el-tab-pane>
        <el-tab-pane v-if="showProcessFile" label="处理附件">
          <case-file
            :img-ids="caseDetail.fileIdProcess"
            :video-ids="caseDetail.videoIdProcess"
            :audio-ids="caseDetail.audioIdProcess"
          />
        </el-tab-pane>
        <el-tab-pane v-if="showCheckFile" label="核查附件">
          <case-file
            :img-ids="caseDetail.fileIdCheck"
            :video-ids="caseDetail.videoIdCheck"
            :audio-ids="caseDetail.audioIdCheck"
          />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="detail-block" style="padding: 20px;">
      <el-table :data="recordList" :max-height="250" class="table" border>
        <el-table-column prop="operationTypeName" label="操作" align="center"/>
        <el-table-column prop="deptName" label="单位" align="center"/>
        <el-table-column prop="userName" label="人员" align="center"/>
        <el-table-column prop="time" label="时间" align="center"/>
        <el-table-column prop="remarks" label="意见" align="center"/>
      </el-table>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      :append-to-body="true"
      title="位置详情"
    >

      <leaflet-map-read :longitude="Number(caseDetail.lng)" :latitude="Number(caseDetail.lat)"/>
    </el-dialog>
  </app-container>
</template>

<script>
import 'element-ui/lib/theme-chalk/index.css'
import { getCaseDetail } from '@/api/coorBusiness/case'
import { historicalRecords } from '@/api/coorBusiness/process'
import LeafletMapRead from '@/components/Map/leafletMapRead'
import CaseFile from '@/components/caseCommon/caseFile'

export default {
  name: 'CaseDetail',
  components: { LeafletMapRead, CaseFile },
  data() {
    return {
      id: '',
      imgurl: process.env.BASE_API + '/static/',
      showNeedVisit: false,
      caseDetail: {},
      operationKey: '', // 案件处理按钮key
      fileIdVerify: [], // 核实照片id
      fileIdProcess: [], // 处理照片id
      fileIdCheck: [], // 核查照片id
      recordList: [], // 流转记录列表
      processForm: { // 提交案卷处理表单
        processId: '', // 流程实例ID
        bizId: '', // 业务表单ID(caseId)
        currState: '', // 当前案件状态
        changeState: '', // 案件流转后状态
        remarks: '', // 审批意见
        approvalResult: '' // 审批结果标志
      },
      commonLanguage: '', // 常用语
      commonLanguageList: [], // 常用语列表
      processRadioList: [], // 案件处理单选按钮
      processCompShow: '', // 案卷处理组件显示
      processCompObj: {}, // 案卷处理组件相关对象
      dialogVisible: false,
      showFile: false
    }
  },
  computed: {
    isNeedVisit: function() {
      return this.caseDetail.isNeedRevisit === 1 ? '需要回访' : '不需要回访'
    },
    // 是否显示案卷图片
    showImage: function() {
      if (this.fileIdVerify.length === 0 && this.fileIdProcess.length === 0 && this.fileIdCheck.length === 0) {
        return false
      } else {
        return true
      }
    },
    imgList() {
      return this.fileIdVerify.concat(this.fileIdProcess).concat(this.fileIdCheck)
    },
    showVerifyFile() {
      return this.caseDetail.fileIdVerify || this.caseDetail.audioIdVerify || this.caseDetail.videoIdVerify
    },
    showProcessFile() {
      return this.caseDetail.fileIdProcess || this.caseDetail.videoIdProcess || this.caseDetail.audioIdProcess
    },
    showCheckFile() {
      return this.caseDetail.fileIdCheck || this.caseDetail.videoIdCheck || this.caseDetail.audioIdCheck
    },
    hasFile() {
      return this.showVerifyFile || this.showProcessFile || this.showCheckFile
    }
  },
  mounted() {
    console.log('detail mounted')
    console.log(this.$route.params)
    this.id = this.$route.params.id
    this.initData()
  },
  methods: {
    async initData() {
      // 查询案件详情接口
      const resDetail = await getCaseDetail(this.id)
      console.log('detail', resDetail)
      this.caseDetail = resDetail.data[0]

      // 解析图片id
      const imgUrl = process.env.BASE_API + '/static/'
      if (this.caseDetail.fileIdVerify) {
        this.fileIdVerify = this.caseDetail.fileIdVerify.split(',')
        this.fileIdVerify = this.fileIdVerify.map(item => imgUrl + item)
      }
      if (this.caseDetail.fileIdProcess) {
        this.fileIdProcess = this.caseDetail.fileIdProcess.split(',')
        this.fileIdProcess = this.fileIdProcess.map(item => imgUrl + item)
      }
      if (this.caseDetail.fileIdCheck) {
        this.fileIdCheck = this.caseDetail.fileIdCheck.split(',')
        this.fileIdCheck = this.fileIdCheck.map(item => imgUrl + item)
      }
      // 查询流转记录接口
      this.processForm.processId = this.caseDetail.processId
      historicalRecords(this.processForm.processId).then(response => {
        this.recordList = response.data
      })
    },
    funShowFile() {
      this.showFile = true
    },
    funHideFile() {
      this.showFile = false
    }
  }

}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .detail-block {
    border-top: 12px solid #ebebeb;
    padding: 10px;
  }
  .detail-row {
    display: -webkit-flex;  /* 新版本语法: Chrome 21+ */
    display: -webkit-box;   /* 老版本语法: Safari, iOS, Android browser, older WebKit browsers. */
    display: -moz-box;      /* 老版本语法: Firefox (buggy) */
    display: -ms-flexbox;   /* 混合版本语法: IE 10 */
    display: flex;          /* 新版本语法: Opera 12.1, Firefox 22+ */
  }
  .detail-item {
    display: -webkit-flex;  /* 新版本语法: Chrome 21+ */
    display: -webkit-box;   /* 老版本语法: Safari, iOS, Android browser, older WebKit browsers. */
    display: -moz-box;      /* 老版本语法: Firefox (buggy) */
    display: -ms-flexbox;   /* 混合版本语法: IE 10 */
    display: flex;          /* 新版本语法: Opera 12.1, Firefox 22+ */
    width: 20%;
  }

  $tableTitleHeight:46px;
  .table-title{
    position: relative;
    height: 46px;
    background-color:#fff;
    .title-header{
      position: absolute;
      left: 15px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 15px;
      i{
        margin-left: 10px;
        margin-right: 5px;
      }
      i:focus{
        outline: none;
      }
    }
  }
  .edit_btns{
    float:right;
    .edit_btn{

      margin:7px 10px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .title{
    font-size: 14px;
    font-weight: bold;
    margin: 10px;
    margin-left: 20px;
  }
  .button{
    margin-bottom: 30px;
  }

  .image-container {
    margin-left: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
  }
  .el-image.image {
    width: 150px;
    height: 150px;
    margin-right: 20px;
  }
  /deep/ .gutter{
    background-color: #f3f3f3;
  }
  /deep/ .el-icon-circle-close{
    color: #e2e2e2
  }

</style>
