<!--案卷详情 督办-->
<template>
  <app-container>
    <el-row class="table-title">
      <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>案卷详情</div></el-col>
      <el-col :span="12" :offset="6" class="edit_btns">
        <!-- <el-button class="edit_btn" size="small">查看地图</el-button> -->
        <el-button class="edit_btn" size="small" @click="dialogVisible = true">查看地图</el-button>

      </el-col>
    </el-row>
    <el-form ref="caseform" class="form" label-width="90px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="案卷编号">
            <table-cell-read :text="caseDetail.caseid"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="信息来源">
            <table-cell-read :text="caseDetail.sourceName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="举报人/电话">
            <table-cell-read :text="caseDetail.reporterName+'/'+caseDetail.reporterPhone"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="上报人员">
            <table-cell-read :text="caseDetail.createUserName"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="案卷类别">
            <table-cell-read :text="caseDetail.eorcName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="案卷大类">
            <table-cell-read :text="caseDetail.casetypeName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="案卷小类">
            <table-cell-read :text="caseDetail.casetypeDetailName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="案卷等级">
            <table-cell-read :text="caseDetail.caseLevelName"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="所在区县">
            <table-cell-read :text="caseDetail.areaName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所在街道">
            <table-cell-read :text="caseDetail.streetName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属社区">
            <table-cell-read :text="caseDetail.communityName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属网格">
            <table-cell-read :text="caseDetail.communityCode"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="登记时间">
            <table-cell-read :text="caseDetail.createTime"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="处理时限">
            <table-cell-read :text="caseDetail.bzhours+'小时'+caseDetail.bzminis+'分钟'"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="完成时限">
            <table-cell-read :text="caseDetail.nodeLimittime"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item v-if="caseDetail.shopkeeperName" label="商户名称">
            <table-cell-read :text="caseDetail.shopkeeperName"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item v-if="caseDetail.shopPhone" label="商户电话">
            <table-cell-read :text="caseDetail.shopPhone"/>
          </el-form-item>
        </el-col>
        <el-col v-if="showNeedVisit==true" :span="6">
          <el-form-item label="是否回访">
            <table-cell-read :text="isNeedVisit"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item label="立案标准">
          <table-cell-read :text="caseDetail.casetypesTimeName"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="发生地点">
          <table-cell-read :text="caseDetail.fieldintro"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="事件描述">
          <table-cell-read :text="caseDetail.description"/>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row v-show="showImage">
      <div class="title">案卷图片:</div>
      <!-- 图片展示 -->
      <div class="image-container">
        <el-image v-for="img in fileIdVerify" :key="img" :src="img" fit="contain"/>
        <el-image v-for="img in fileIdProcess" :key="img" :src="img" fit="contain"/>
        <el-image v-for="img in fileIdCheck" :key="img" :src="img" fit="contain"/>
      </div>
    </el-row>
    <!--数据流转记录-->
    <el-row class="table-title">
      <el-col :span="6"><div class="title-header"><i class="el-icon-tickets"/>数据流转记录</div></el-col>
    </el-row>
    <el-row>
      <el-table :data="recordList" :header-cell-style="{background:'#f3f3f3'}" 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="superviseRemarks" label="意见" align="center"/>
      </el-table>
    </el-row>

    <!-- 案卷处理-->
    <el-row class="table-title">
      <el-col :span="6"><div class="title-header"><i class="el-icon-edit-outline"/>督办意见</div></el-col>
    </el-row>
    <el-row>
      <div class="case-process">
        <el-form ref="superviseForm" v-model="superviseForm" class="form" label-width="90px" >
          <el-row>
            <el-form-item label="督办意见">
              <el-input v-model="superviseForm.superviseRemarks" type="textarea" maxlength="50" show-word-limit/>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="">
              <el-select v-model="commonLanguage" placeholder="请选择常用处理意见" clearable style="width: 400px;" @change="selectCommonLang">
                <el-option
                  v-for="item in commonLanguageList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.name"
                />
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </el-row>
    <el-row style="text-align: center;">
      <el-button class="button" type="primary" plain @click="submit">提交</el-button>
    </el-row>

    <el-dialog
      :visible.sync="dialogVisible"
      :append-to-body="true"
      title="位置详情"
    >
      <leaflet-map-read :longitude="caseDetail.lng" :latitude="caseDetail.lat"/>
    </el-dialog>
  </app-container>
</template>

<script>
import { getCaseDetail } from '@/api/coorBusiness/case'
import { getCommonLanguage } from '@/api/coorBusiness/dict'
import { historicalRecords } from '@/api/coorBusiness/process'
import { superviseCaseTask } from '@/api/supervise/supervise'
import LeafletMapRead from '@/components/Map/leafletMapRead'

export default {
  name: 'CaseDetail',
  components: { LeafletMapRead },
  props: {
    id: {
      type: String,
      default: ''
    },
    row: {
      type: Object,
      default: null
    },
    showProcess: {
      type: Boolean,
      default: true
    },
    showNeedVisit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      caseDetail: {},
      operationKey: '', // 案件处理按钮key
      fileIdVerify: [], // 核实照片id
      fileIdProcess: [], // 处理照片id
      fileIdCheck: [], // 核查照片id
      recordList: [], // 流转记录列表
      superviseForm: { // 督办案卷表单
        id: '', // 流程实例ID
        superviseRemarks: '' // 审批意见
      },
      commonLanguage: '', // 常用语
      commonLanguageList: [], // 常用语列表
      processRadioList: [], // 案件处理单选按钮
      processCompShow: '', // 案卷处理组件显示
      processCompObj: {}, // 案卷处理组件相关对象
      dialogVisible: 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
      }
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    async initData() {
      // 查询案件详情接口
      const resDetail = await getCaseDetail(this.row.id)
      console.log('detail', resDetail)
      this.caseDetail = resDetail.data[0]

      // 解析图片id
      if (this.caseDetail.fileIdVerify) {
        this.fileIdVerify = this.caseDetail.fileIdVerify.split(',')
      }
      if (this.caseDetail.fileIdProcess) {
        this.fileIdProcess = this.caseDetail.fileIdProcess.split(',')
      }
      if (this.caseDetail.fileIdCheck) {
        this.fileIdCheck = this.caseDetail.fileIdCheck.split(',')
      }

      // 查询常用语列表
      const languageRes = await getCommonLanguage()
      this.commonLanguageList = languageRes.data

      // 查询流转记录接口
      this.superviseForm.id = this.caseDetail.processId
      const resRecord = await historicalRecords(this.superviseForm.processId)
      this.recordList = resRecord.data
      console.log(this.recordList)
    },
    /**
     * 选择常用语，更新审核意见
     */
    selectCommonLang(value) {
      this.superviseForm.superviseRemarks = value
    },
    submit() {
      const superviseForm = this.superviseForm
      this.$confirm('确定提交案件处理吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log('doing submit')
        // 点击“确定”后的操作
        debugger
        superviseCaseTask(superviseForm).then(response => {
          if (response.code === 200) {
            this.$message.success('提交成功')
            // this.$emit('submitProcess', this.caseDetail.caseid)
          } else {
            this.$message.error('提交失败')
          }
        })
      }).catch(() => {
        // 点击“取消”后的操作
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: 46px;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .app-container{
    // padding-top: 50px;
    margin-bottom: 20px;
  }
  .form{
    margin: 20px;
    // margin-left: 20px;
    // margin-right: 20px;
  }
  .table{
    margin: 20px;
    width: 98%;
  }
  .title{
    margin-left: 38px;
    font-size: 14px;
    font-weight: bold;
  }
  .button{
    margin-bottom: 30px;
  }
</style>
