<template>
  <el-dialog
    width="90%"
    class="outerDialog modify_problem_dialog"
    title="查看稽察问题"
    @close="closeModal"
    :close-on-click-modal="false"
    :append-to-body="true"
    v-model="changeSupervisionVisible">
    <div id="eventDetailBody" style="padding: 3px;" :style="{'height':testHeight+'px',}">
      <div :style="{'height':testHeight+'px',}" style="width:46%;float:left;border:1px solid #d5d5ff;margin-right:5px;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;">基本信息</p>
        <el-form label-position="right" label-width="130px" :style="{'max-height':testHeight-30+'px',}"
                 style="overflow-y: auto;height:100%;margin:5px;" :model="changeSupervision">
          <el-form-item label="问题描述">
            <p class="item_content">{{changeSupervision.pblmsDesc}}</p>
          </el-form-item>
          <el-form-item label="法规条款:">
            <p class="item_content">{{changeSupervision.relativeLaw}}</p>
          </el-form-item>
          <el-form-item label="法规内容:">
            <p class="item_content">{{changeSupervision.lawContent}}</p>
          </el-form-item>
          <el-form-item label="备注:">
            <p class="item_content">{{changeSupervision.note}}</p>
          </el-form-item>
          <div v-for="(unit,index) in unitArray" :key="index">
            <el-form-item label="单位性质">
              <p class="item_content">{{unit.subName}}</p>
            </el-form-item>
            <el-form-item label="单位名称">
              <p class="item_content">{{unit.unitNm}}</p>
            </el-form-item>
          </div>
          <el-form-item label="排序序号:">
            <p class="item_content">{{changeSupervision.sn}}</p>
          </el-form-item>
          <el-form-item label="发现问题:">
            <p class="item_content">{{changeSupervision.pblmNm}}</p>
          </el-form-item>
          <el-form-item label="问题分类:">
            <p class="item_content">{{changeSupervision.pblmTypeDesc}}</p>
          </el-form-item>
          <el-form-item label="问题阐述:">
            <p class="item_content">{{changeSupervision.pblmDesc}}</p>
          </el-form-item>
          <el-form-item label="问题严重性:">
            <p class="item_content">{{pblmPasiFilter(changeSupervision.pblmPasi)}}</p>
          </el-form-item>
          <el-form-item label="是否为典型问题:">
            <span v-if="changeSupervision.ifCasePblm == 1">典型</span>
            <span v-if="changeSupervision.ifCasePblm == 0">非典型</span>
          </el-form-item>
          <el-form-item label="主要原因分析:">
            <p class="item_content">{{changeSupervision.pblmReason}}</p>
          </el-form-item>
          <el-form-item label="整改意见及建议:">
            <p class="item_content">{{changeSupervision.pblmSggtn}}</p>
          </el-form-item>
          <el-form-item label="稽察组长复核意见:">
            <p class="item_content">{{changeSupervision.spclRvwOptn}}</p>
          </el-form-item>
        </el-form>
      </div>
      <div :style="{'height':testHeight+'px',}" style="width:50%;float:left;border:1px solid #d5d5ff;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;">多媒体信息</p>
        <el-tabs style="overflow-y: auto;margin:5px;" :style="{'max-height':testHeight-40 +'px',}">
          <el-tab-pane :label="picturetabName" style="height: 350px;">
            <el-carousel :interval="4000" height="350px">
              <el-carousel-item v-for="(item,index) in pictureArray" :key="index">
                <a :href="`${hostUrl}/${item.filePath}`" target="_blank">
                  <img style="height:100%;" :src="`${hostUrl}/${item.filePath}`" alt>
                </a>
              </el-carousel-item>
              <el-carousel-item v-if="pictureArray.length==0">
                <p>暂无图片信息</p>
              </el-carousel-item>
            </el-carousel>
          </el-tab-pane>
          <el-tab-pane :label="audiotabName">
            <elaudio v-for="(audio,index) in audioArray" style="margin-left:15%"
                     :theUrl="`${hostUrl}/${audio.filePath}`" :key="index"></elaudio>
            <p v-if="audioArray.length==0">暂无音频信息</p>
          </el-tab-pane>
          <el-tab-pane :label="videotabName">
            <el-carousel :interval="4000" height="350px">
              <el-carousel-item v-for="(item,index) in videoArray" :key="index">
                <video-player class="vjs-custom-skin"
                              ref="videoPlayer"

                              :options="item"
                              :playsinline="true"
                >
                </video-player>
              </el-carousel-item>
              <el-carousel-item v-if="videoArray.length==0">
                <p>暂无视频信息</p>
              </el-carousel-item>
            </el-carousel>
          </el-tab-pane>
          <el-tab-pane :label="filetabName">
            <el-table border :data="fileArray" style="width: 100%;margin: 0 auto;">
              <el-table-column header-align="center" align="center" label="文档">
                <template #default="scope">
                  <p>
                    <a :href="`${hostUrl}/${scope.row.filePath}`" target="_blank" rel="noopener noreferrer">
                      {{scope.row.fileName}}
                    </a>
                  </p>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </el-dialog>

</template>

<script>
  import draggable from "vuedraggable";
  import {updatelist, deleteFileById} from "@/api/duChaAPI.js";
  import {
    showDetailsXq,
    getProblemNatureApi,
    getSelectProblemList,
    getUnitNameListApi,
    getProblemDxListApi
  } from "@/api/InspectionReport.js";
  import request from "@/utils/gw_ajax_request.js";
  import elaudio from '../elAudioShort.vue'
  import { hostUrl } from "@/utils/global_variable.js";
  export default {
    props: ['problemId', 'pertype', 'listType'],
    data() {
      return {
        testHeight: window.innerHeight - 200,
        changeSupervisionVisible: true,
        changeSupervisionLoading: false,
        changeSupervision: {},
        supervision: [
          {
            value: "1",
            label: "是"
          },
          {
            value: "0",
            label: "否"
          }
        ],
        addPicPanel: false,
        gwComFileList: [],
        picturetabName: "",
        audiotabName: "",
        videotabName: "",
        filetabName: "",
        pictureArray: [],
        audioArray: [],
        videoArray: [],
        fileArray: [],
        updateIdXiuGai: "",
        pblmId: "",
        //稽察添加问题用到的参数
        keyword: '',
        problemList: [],
        problemInfo: {},
        gwComFileList: [],
        cateObjList: [],//严重程度列表
        objSubjectList: [], //单位性质列表
        unitNameList: [],  //单位名称列表
        unitArray: [
          {
            unitNm: '',
            subId: ''
          }
        ],
        //为稽察组长时禁用
        disabled: false,
        dialogImageUrl: '',
        previewDialogVisible: false,
        rotateDeg: {'transform': 'rotate(0deg)'},
        editPicDialog: false,
        editPicRefresh: true,
        picUrl: "",
        picId: "",
        problemDxList: [],    //问题分类列表
        relCode: '',
      }
    },
    components: {
      elaudio: elaudio,
      draggable,
      upload: resolve => {
        require(["@widget/uploadFileWithPic.vue"], resolve);
      },
      EditPicOnline: resolve => {
        require(["@widget/EditPicOnline/EditPicOnline.vue"], resolve);
      },
    },
    computed: {
      hostUrl() {
        return hostUrl
      },
      persId() {
        return localStorage.getItem("userid") ? localStorage.getItem("userid") : "1098101939614724096";
      }
    },
    mounted() {
      this.changeSup(this.problemId)
    },
    methods: {
      pblmPasiFilter(val) {
        if (val == 0) {
          return '一般'
        } else if (val == 1) {
          return '较重'
        } else if (val == 2) {
          return '严重'
        } else {
          return val
        }
      },
      editPicEvent(item) {
        this.picUrl = this.hostUrl + "/" + item.filePath;
        this.editPicDialog = true;
        this.editPicRefresh = false;
        this.picId = item.id;
      },
      cancelHandler() {
        this.editPicDialog = false;
        this.editPicRefresh = true;
      },
      editPicDataEvent(item) {
        request.post(`/file/updateFile?bizId=${this.changeSupervision.pblmId}&id=${this.picId}`, item, {headers: {'Content-Type': 'multipart/form-data'}}).then(res => {
          console.log(res);
          if (res.success) {
            this.pictureArray = [];
            showDetailsXq(this.updateIdXiuGai).then(res => {
              res.data.gwComFileList.forEach(item => {
                this.pictureArray.push(item);
                this.editPicDialog = false;
                this.editPicRefresh = true;
                this.$message.success('修改成功');
              });
              this.picturetabName = "图片资料(" + this.pictureArray.length + ")";
            });
          }
        });
      },
      // 修改弹窗显示
      changeSup(id) {
        this.pictureArray = [];
        this.audioArray = [];
        this.videoArray = [];
        this.fileArray = [];
        this.updateIdXiuGai = id;
        let _this = this
        showDetailsXq(this.updateIdXiuGai).then(res => {
          // if(this.usersId==)
          this.changeSupervision = res.data;
          this.keyword = this.changeSupervision.tacObjPblmstb ? this.changeSupervision.tacObjPblmstb.id : ''
          if (this.changeSupervision.pblmSubjectList) {
            this.unitArray = this.changeSupervision.pblmSubjectList
          }
          if (this.changeSupervision.tacObjPblmstb) {
            this.objSubjectList = this.changeSupervision.tacObjPblmstb.objSubjectList
            this.cateObjList = this.changeSupervision.tacObjPblmstb.cateObjList
            this.changeSupervision.pblmsDesc = this.changeSupervision.tacObjPblmstb.pblmsDesc
            this.changeSupervision.relativeLaw = this.changeSupervision.tacObjPblmstb.relativeLaw
            this.changeSupervision.lawContent = this.changeSupervision.tacObjPblmstb.lawContent
            this.changeSupervision.note = this.changeSupervision.tacObjPblmstb.note
          }
          this.changeSupervision.pblmQlttvCd = this.changeSupervision.pblmQlttvCd.toString()
          this.relCode = this.changeSupervision.pblmNm.substr(0, 3)
          if (this.unitArray.length) {
            this.unitArray.forEach((ele, index) => {
              _this.getUnitNameList(index)
            })
          }
          res.data.gwComFileList.forEach(item => {
            if (
              item.fileExt == "mp3" ||
              item.fileExt == "MP3" ||
              item.fileExt == "m4a"
            ) {
              this.audioArray.push(item);
            } else if (
              item.fileExt == "jpg" ||
              item.fileExt == "JPG" ||
              item.fileExt == "png" ||
              item.fileExt == "PNG" ||
              item.fileExt == "JPEG" ||
              item.fileExt == "jpeg"
            ) {
              this.pictureArray.push(item);
            } else if (item.fileExt == "mp4" || item.fileExt == "MP4") {
              this.videoArray.push({
                id:item.id,
                width: "130",
                height: "130",
                autoplay: false,
                muted: true,
                language: "en",
                playbackRates: [0.7, 1.0, 1.5, 2.0],
                sources: [
                  {
                    type: "video/mp4",
                    src: this.hostUrl + item.filePath
                  }
                ],
                id: item.id
              });
            } else {
              this.fileArray.push(item);
            }
          });

          this.picturetabName = "图片资料(" + this.pictureArray.length + ")";
          this.audiotabName = "音频资料(" + this.audioArray.length + ")";
          this.videotabName = "视频资料(" + this.videoArray.length + ")";
          this.filetabName = "其它资料(" + this.fileArray.length + ")";
        });
      },
      unitSelect() {
        let _this = this
        let unitIds = []
        this.unitArray.forEach((ele, index) => {
          _this.unitNameList.forEach(element => {
            if (ele.unitNm == element.sysNm) {
              this.unitArray[index].unitId = element.id
            }
          })
          unitIds.push(ele.unitId)
        })
        // this.changeSupervision.subjectIds = unitIds.join(',')
      },
      getUnitNameList(index) {
        let subId = this.unitArray[index].subId ? this.unitArray[index].subId : ''
        let paramsObj = {
          rgstrId: this.changeSupervision.rgstrId,
          sysType: subId
        }
        if (subId) {
          getUnitNameListApi(paramsObj).then(res => {
            if (res.success) {
              this.unitNameList = res.data
            } else {
              this.$message.error(res.message)
            }
          }).catch(err => {
            this.$message.error(err)
          })
        }
      },
      natureChange(val, index) {
        this.unitArray.forEach((ele, index) => {
          this.objSubjectList.forEach(element => {
            if (ele.subId == element.id) {
              this.unitArray[index].subName = element.subName
            }
          })
        })

        let subIds = []
        this.unitArray.forEach((ele, index) => {
          subIds.push(ele.subId)
        })
        this.changeSupervision.subjectIds = subIds.join(',')
        this.getUnitNameList(index)
      },
      dragChange(val) {
        console.log(val)
        console.log(this.pictureArray)
        let gwComFileList = []
        gwComFileList = gwComFileList.concat(this.pictureArray).concat(this.audioArray).concat(this.videoArray).concat(this.fileArray)
        this.changeSupervision.gwComFileList = gwComFileList
        console.log(this.changeSupervision.gwComFileList)
      },
      previewFile(url) {
        this.dialogImageUrl = `${this.hostUrl}/${url}`
        this.previewDialogVisible = true
      },
      closeModal() {
        this.$emit('dialogClose')
      },
    },
    watch: {
      problemId(val) {
        this.changeSup(val)
      }
    },
  }
</script>

<style scoped>
  .name {
    background-color: #ebf8ff;
  }

  .item_content {
    min-height: 24px;
    font-weight: bold;
    border-bottom: 1px dashed rgb(198, 226, 255);
  }

  .details >>> .el-tabs__content {
    height: 360px;
    overflow-y: auto;
  }

  .flexbody > div {
    display: flex;
    align-items: flex-start;
    line-height: 30px;
  }

  .flexbody div span:first-child {
    width: 100px;
    flex-shrink: 0;
  }

  .flexbody div span:first-child {
    color: blue;
  }

  .fileList span {
    margin-right: 10px;
    cursor: pointer;
  }

  .fileList span:hover {
    color: blueviolet;
  }

  .el-form-item {
    width: 100%;
    margin-bottom: 0;
  }
</style>
