<template>
  <div>
    <el-dialog
      :visible.sync="StshowFormDias"
      width="85%"
      title="详情"
      max-height="650px"
      :before-close="handleClose"
    >
      <el-tabs v-model="current" @tab-click="handleClick">
        <el-tab-pane
          class="bbsl-tab"
          :label="e.name"
          v-for="(e, i) in tabList"
          :key="i"
        >
          <el-form
            class="bbsl-scroll-form"
            ref="formInfo"
            :rules="rules"
            style="overflow-y: auto;max-height: 500px;"
            :model="params"
            label-width="150px"
          >
            <div v-for="(x, xi) in tempList" :key="xi">
              <p class="from-title">
                <span>{{ x.position }}</span>
              </p>

              <el-row>
                <el-col :span="8">
                  <el-form-item label="是否正常：">
                    <span :style="{color: x.isNormal == 1 ? 'green' : 'red'}">{{
                      x.isNormal == 1 ? '正常' : x.isNormal == 2 ? '异常' : ''
                    }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="提交时间：">
                    {{ x.createTime }}
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item label="图像信息：" style="margin: 0;">
                    <el-image
                      style="width: 40px; height: 40px;margin-right: 2px;"
                      :src="urls + '/' + item.filePath"
                      v-for="(item, index) in x.pic"
                      :preview-src-list="x.srcList"
                      :key="index"
                    >
                    </el-image>
                    <!-- {{ x.pic.forEach(e=>  urls+'/'+e.filePath)}} -->
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="结论：">
                    {{ x.conclusion }}
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" v-if="x.isNormal == 2">
                  <el-form-item label="处理结果：">
                    <el-input
                      type="textarea"
                      :rows="2"
                      size="mini"
                      placeholder="请输入处理结果"
                      maxlength="16"
                      v-model="x.result"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-divider></el-divider>
            </div>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="goInfo" :disabled="falg"
          >处 理</el-button
        >
        <el-button @click="handleClose">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import dsmInsPosition from '@/api/resIns/dsmInsInin.js'
import req from '@/request.js'
export default {
  name: 'videoManger',
  props: {
    StshowFormDias: {
      type: Boolean,
      default: false
    },
    rowId: {
      type: String,
      default: ''
    },
    nol: {
      type: String,
      default: ''
    }
  },
  components: {},
  data() {
    return {
      falg: false,
      params: {},
      urls: 'http://183.230.17.146:9080',
      lists: [],
      tempList: [],
      tabList: [],
      temp: [],
      current: 0,
      rules: {
        excResult: [
          {
            required: true,
            message: '请输入处理结果',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
    // console.log(this.urls);
    if (this.nol == '正常') {
      this.falg = true
    } else {
      this.falg = false
    }
    // this.getDetailInfo()
    this.dome()
  },
  methods: {
    dome() {
      dsmInsPosition.structureList(this.rowId, res => {
        // 获取对象配置tabs标签
        this.lists = res.value
        dsmInsPosition.getInsResult(this.rowId, res => {
          this.lists.forEach((w, wi) => {
            res.value.forEach(e => {
              if (e.structure == w.structure) {
                if (e.position == w.position) {
                  e.srcList = []
                  e.pic.forEach(p => {
                    e.srcList.push(this.urls + '/' + p.filePath)
                  })
                  this.lists[wi] = e
                  // console.log(e);
                }
              }
            })
          })
          for (let i = 0; i < this.lists.length; i++) {
            let objTabList = {
              name: this.lists[i].structure
            }
            this.tabList.push(objTabList)
          }
          this.tabList = this.tabList.filter((element, index, self) => {
            return self.findIndex(x => x.name === element.name) === index
          })

          // 获取tabs标签对于列表内容
          this.temp = []
          this.tabList.forEach(e => {
            this.temp.push(this.lists.filter(i => i.structure === e.name))
          })
          let temp = this.temp[this.current]
          this.tempList = temp
        })
      })
    },

    handleClick(tab) {
      this.current = tab.index
      this.tempList = this.temp[this.current]
    },
    getDetailInfo() {
      if ((this.StshowFormDias = true)) {
        dsmInsPosition.detailId(this.rowId, res => {})
      }
    },
    goInfo() {
      let arr = []
      let newArr = []
      let types = true
      let times
      let date = new Date()
      let y = date.getFullYear()
      let MM = date.getMonth() + 1
      MM = MM < 10 ? '0' + MM : MM
      let d = date.getDate()
      d = d < 10 ? '0' + d : d
      let h = date.getHours()
      h = h < 10 ? '0' + h : h
      let m = date.getMinutes()
      m = m < 10 ? '0' + m : m
      let s = date.getSeconds()
      s = s < 10 ? '0' + s : s
      times = y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
      console.log(times)
      this.lists.forEach(e => {
        if (Object.keys(e).length > 3) {
          delete e.srcList
          arr.push(e)
        }
      })

      arr.forEach(a => {
        if (a.isNormal == '2' && a.result == '') {
          this.$message.warning('请填写处理结果')
          types = false
          return
        }
      })
      arr.forEach(item => {
        if (item.isNormal == 2) {
          newArr.push({
            excMemo: item.exceptionData.excMemo, //备注
            excResult: item.result, //处理结果
            excTime: times, //处理时间
            excUser: this.$store.state.login.currentUser.username, //处理用户
            id: item.exceptionData.id,
            insId: item.exceptionData.insId,
            isDele: item.exceptionData.isDele,
            pkVal: item.exceptionData.pkVal,
            resId: item.exceptionData.resId,
            tenantId: ''
          })
        }
      })
      if (types) {
        dsmInsPosition.saveBatch(newArr, res => {
          if (res.state) {
            this.$notify({
              type: 'success',
              message: '处理成功'
            })
            this.$emit('closeStshowForm')
            this.$emit('refList')
          }
        })
      }
    },
    handleClose() {
      this.$emit('closeStshowForm')
    }
  }
}
</script>
<style lang="scss" scoped></style>
