<template>
  <div class="engineering-manage" @keyup.enter="searchApi">
    <!-- 管道检测历史管理 -->
    <div class="table-box">
      <div class="top-tool">
        <div class="serch-engineering">
          <div class="title">关键字：</div>
          <el-input
            size="small"
            placeholder="请输入管段编号、道路名称"
            v-model="searchParams.keyword"
            clearable
            class="serch-input"
          >
          </el-input>
          <div class="title">检测日期：</div>
          <div class="sampleTime">
            <el-row style="display: flex; justify-content: center; align-items: center">
              <el-col :span="11">
                <el-date-picker
                  v-model="searchParams.startDate"
                  type="date"
                  placeholder="选择开始日期"
                  value-format="yyyy-MM-dd"
                  size="small"
                  :picker-options="sOpition"
                  @change="sDateChange"
                ></el-date-picker>
              </el-col>
              <el-col :span="1" style="text-align: center; margin: 0 5px">至</el-col>
              <el-col :span="12">
                <el-date-picker
                  v-model="searchParams.finishDate"
                  type="date"
                  placeholder="选择结束日期"
                  value-format="yyyy-MM-dd"
                  size="small"
                  :picker-options="eOpition"
                  @change="eDateChange"
                ></el-date-picker>
              </el-col>
            </el-row>
          </div>

          <div class="title">结构性缺陷等级：</div>
          <el-select clearable v-model="searchParams.funcClass" placeholder="全部">
            <el-option v-for="(item, i) in gradeArr" :key="i + gradeArr.length" :label="item" :value="item"></el-option>
          </el-select>
          <div class="title">功能性缺陷等级：</div>
          <el-select clearable v-model="searchParams.structClass" placeholder="全部">
            <el-option v-for="(item, i) in gradeArr" :key="i" :label="item" :value="item"></el-option>
          </el-select>
        </div>
        <div class="right-btn">
          <el-button size="small" style="margin-left: 26px" type="primary" @click="searchApi"> 搜索 </el-button>
          <el-button size="small" type="primary" @click="resetBtn"> 重置 </el-button>
        </div>
      </div>

      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        height="250"
        stripe
        style="width: 100%"
        @selection-change="handleSelectionChange"
        @row-click="openPromptBox"
        :row-style="{ height: '40px' }"
        :default-sort="{ prop: 'date', order: 'descending' }"
      >
        <template slot="empty">
        <img src="@/assets/icon/null.png" alt="暂无数据" />
        </template>
        <el-table-column header-align="center" align="center" type="selection" width="55"> </el-table-column>
        <el-table-column  align="center" type="index" label="序号" width="50"> </el-table-column>
        <el-table-column
          :prop="v.name"
          header-align="center"
          :label="v.label"
          align="center"
          show-overflow-tooltip
          v-for="v in tableContent"
          :key="v.name"
          :width="v.width"
          :sortable="v.sortable"
        >
        </el-table-column>

        <el-table-column fixed="right" header-align="center" label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="openDetails(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          :page-sizes="[10, 20, 30, 50, 100, 1000]"
          :page-size="pagination.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="paginationTotal"
        >
        </el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import { queryPageHistory, histroyPipeData, downloadFile, getDefectData } from '@/views/pipelineDefect/api/pipelineDefect'

// 引入管道检测组件
import deleteDialog from '../../components/checkDetails.vue'
// 引入公共ip地址
// import { baseAddress } from '@/utils/request.ts'

import { baseAddress } from '@/utils/request'
import { projUtil } from '@/views/pipelineDefect/common/proj'
import axios from 'axios'
import { appconfig } from 'staticPub/config'
import { mapMixin } from '@/views/pipelineDefect/mixin/map'

export default {
  mixins: [mapMixin],
  props: ['data'],
  components: {
    deleteDialog
  },
  data() {
    return {
      multipleSelection: [], // 选中的表格
      id: null,
      checkdialogFormVisible: false,
      imgArrIndex: 0,
      urlArr: [],
      activeName: 'first',
      activeName2: "picnum",
      currentForm: {}, // 当前详情表单
      detailsTitle: {}, // 详情头部信息
      cardTableContent: [
        [
          { label: '管段编号', name: 'expNo' },
          { label: '管段类型', name: 'pipeType' }
        ],
        [
          { label: '起点埋深', name: 'startDepth' },
          { label: '终点埋深', name: 'endDepth' }
        ],
        [
          { label: '管径', name: 'diameter' },
          { label: '材质', name: 'material' }
        ],
        [
          { label: '敷设年代', name: 'constr' },
          { label: '长度', name: 'pipeLength' }
        ]
      ], // 详情表格参数
      currentIndex: 0, // 详情页数
      cardTable: [], // 详情表格数据
      activeIndex: '1', // 详情导航索引
      dialogFormVisible: false, // 详情弹框显影
      // 表格参数
      tableContent: [
        { width: '100', sortable: false, label: '管段编号', name: 'expNo' },
        { width: '100', sortable: false, label: '管段类型', name: 'pipeType' },
        { width: '120', sortable: true, label: '管径(mm)', name: 'diameter' },
        { width: '100', sortable: false, label: '材质', name: 'material' },
        // { width: '100',sortable: false,label: '道路名称', name: 'checkAddress' },
        { width: '100', sortable: false, label: '所属片区', name: 'checkAddress' },
        { width: '100', sortable: true, label: '检测次数', name: 'jcNum' },
        { width: '150', sortable: true, label: '最近检测日期', name: 'newJcDate' },
        { width: '180', sortable: true, label: '最新结构性缺陷等级', name: 'newStructClass' },
        { width: '180', sortable: true, label: '最新功能性缺陷等级', name: 'newFuncClass' },
        { width: '180', sortable: false, label: '最新结构性缺陷评价', name: 'newStructEstimate' },
        { width: '180', sortable: false, label: '最新功能性缺陷评价', name: 'newFuncEstimate' }
      ],
      gradeArr: ['Ⅰ', 'Ⅱ', 'Ⅲ', 'Ⅳ'], // 缺陷等级
      // 日期选择器规则
      // 日期选择器规则
      sOpition: {
        disabledDate: (time) => {
          time = time.getTime()
          if (this.searchParams.finishDate) {
            return time > new Date(this.searchParams.finishDate).getTime()
          }
          return time > new Date().getTime()
        }
      },
      eOpition: {
        disabledDate: (time) => {
          time = time.getTime()
          if (this.searchParams.startDate) {
            return time < new Date(this.searchParams.startDate).getTime() - 8.64e7 || time > new Date().getTime()
          }
          return time > new Date().getTime()
        }
      },
      // 搜索需要的参数
      searchParams: {
        jcStatus: [],
        keyword: '',
        startDate: '',
        finishDate: '',
        defectLevelA: '',
        defectLevelB: ''
      },
      // 分页需要的值
      pagination: { current: 1, size: 30 }, // 分页参数信息
      paginationTotal: 0, // 总页数
      tableData: [],
      isPromptBox: {}, // 当前列信息
      form: {},
      //
      vectorLayer: null,
      map: null,
      lightLayer: null,
      clickEvent: null,
      projUtil: null, // 坐标系工具
      currentDataProjName: appconfig.currPRJ, // 当前坐标系
      // 
      currentInfoCard2: false,
      currentForm2: [],
      currentIndex2: 0,
      popup: null,
      hasLoad: false,

      themLayerName: 'pipeAndDefectLayer',
      themLayer: null
    }
  },
  created() {
  },
  mounted() {
      this.upDateTable()
  },
  computed: {
  },
  methods: {
    sDateChange(t) {
      if (!this.searchParams.finishDate) {
        this.$nextTick(() => {
          this.searchParams.finishDate = this.searchParams.startDate
        })
      }
    },
    eDateChange(t) {
      if (!this.searchParams.startDate) {
        this.$nextTick(() => {
          this.searchParams.startDate = this.searchParams.finishDate
        })
      }
    },
    lastImg() {
      console.log('上一张照片', this.getCurrentForm.pipeDefects)

      if (this.imgArrIndex <= 0) {
        this.imgArrIndex = 0
        return
      }
      this.imgArrIndex--
    },
    nextImg() {
      if (this.imgArrIndex + 1 >= this.getCurrentForm.pipeDefects.length) {
        this.imgArrIndex = this.getCurrentForm.pipeDefects.length - 1
        return
      }
      this.imgArrIndex++
    },
    // 下载文档
    downloadDocx() {
      this.$message('正在加载文档地址...')
      let url = baseAddress + '/psjc/file' + this.tableForm.wordFilePath
      let label = this.tableForm.wordInfoName + '.docx'
      axios
        .get(url, { responseType: 'blob' })
        .then((response) => {
          const blob = new Blob([response.data])
          const link = document.createElement('a')
          link.href = URL.createObjectURL(blob)
          link.download = label
          link.click()
          URL.revokeObjectURL(link.href)
        })
        .catch(console.error)
    },
    downloadDocx2() {
      this.$message('正在加载文档地址...')
      let url = baseAddress + '/psjc/file' + this.getCurrentForm.wordFilePath
      let label = this.getCurrentForm.wordInfoName + '.docx'
      axios
        .get(url, { responseType: 'blob' })
        .then((response) => {
          const blob = new Blob([response.data])
          const link = document.createElement('a')
          link.href = URL.createObjectURL(blob)
          link.download = label
          link.click()
          URL.revokeObjectURL(link.href)
        })
        .catch(console.error)
    },
    // 照片缩略图列表滑动事件
    MouseWheel(e) {
      let eventDelta = -e.wheelDelta || -e.deltaY * 40

      let $scrollWrapper = this.$refs.scrollContainer
      console.log('触发滑动事件', eventDelta, $scrollWrapper)

      // console.log($scrollWrapper.scrollLeft)

      // 0到scrollLeft为滚动区域隐藏部分

      $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
      console.log('盒子位置', $scrollWrapper.scrollLeft)
    },
    // 打开管道详情
    openCheck(id) {
      // this.id = this.tableForm.id
      this.id = id
      // console.log("打开详情",this.tableForm.id);
      this.checkdialogFormVisible = true
    },
    // 关闭弹框
    getBool(bool) {
      this.checkdialogFormVisible = bool
    },
    // 下载附件
    fileLinkToStreamDownload(id) {
      let res = downloadFile(id)
      return baseAddress + res.url
    },
    clearAll() {
      this.vectorLayer && this.map.removeLayer(this.vectorLayer)
      this.lightLayer && this.map.removeLayer(this.lightLayer)
      this.clickEvent && unByKey(this.clickEvent)
      this.popup && this.popup.setPosition(null)
      this.currentInfoCard2 = false
      this.vectorLayer = this.lightLayer = this.clickEvent = null
    },
    // 根据状态设置每列表格样式
    modality(obj) {
      // 通过id标识来改变当前行的文字颜色
      let expNoArr
      if (this.multipleSelection != []) {
        expNoArr = this.multipleSelection.map((v) => v.expNo)
      }
      if (expNoArr.some((v) => v == obj.row.expNo)) {
        return 'rowBgBlue'
      }
    },

    openPromptBox(row) {
      this.setViewFromFeas(row.expNo, 1)
    },
    // 上一页
    lastPage() {
      if (this.currentIndex <= 0) {
        this.currentIndex = 0
        return
      }
      this.currentIndex--
      // this.openDetails(this.isPromptBox)
    },
    // 下一页
    nextPage() {
      if (this.currentIndex + 1 >= this.cardTable.length) {
        this.currentIndex = this.cardTable.length - 1
        return
      }
      this.currentIndex++
      // this.openDetails(this.isPromptBox)
    },
    // 上一页
    lastPageEv() {
      if (this.currentIndex2 <= 0) {
        this.currentIndex2 = 0
        return
      }
      this.currentIndex2--
      // this.openDetails(this.isPromptBox)
    },
    // 下一页
    nextPageEv() {
      if (this.currentIndex2 + 1 >= this.currentForm2.length) {
        this.currentIndex2 = this.currentForm2.length - 1
        return
      }
      this.currentIndex2++
      // this.openDetails(this.isPromptBox)
    },
    // 详情导航选择事件
    handleSelect(key, keyPath) {
      this.activeIndex = key
      console.log(key, keyPath)
      console.log(this.activeIndex)
    },
    // 详情
    openDetails(row) {
      this.currentForm = row // 保存当前列信息
      this.isPromptBox = { ...row }
      histroyPipeData({ expNo: row.expNo }).then(res => {
        this.detailsTitle = {
          expNo: row.expNo,
          pipeType: row.pipeType
        }
        this.cardTable = res.result
        this.activeName = 'first'
        this.urlArr = this.tableForm.pipeDefects.map((v) => {
          return baseAddress + '/psjc/file' + v.picPath
        })
        this.dialogFormVisible = true
      })
    },
    // 重置
    resetBtn() {
      this.pagination = { current: 1, size: 30 }
      this.searchParams = {
        keyword: '',
        startDate: '',
        finishDate: '',
        funcClass: '',
        structClass: ''
      }
      this.changeDate()
      this.upDateTable()
    },
    // 搜索
    searchApi() {
      this.upDateTable()
    },
    // 表格多选事件
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 分页触发的事件
    handleSizeChange(val) {
      this.pagination.size = val
      this.upDateTable()
    },
    handleCurrentChange(val) {
      this.pagination.current = val
      this.upDateTable()
    },
    // 查询数据
    upDateTable() {
      let data = { ...this.pagination }
      data.wordInfoState = 1

        data.jcStartDate = this.searchParams.startDate
        data.jcEndDate = this.searchParams.finishDate
        data.queryParams = this.searchParams.keyword
        data.state = this.searchParams.checkList
        data.funcClass = this.searchParams.funcClass
        data.structClass = this.searchParams.structClass

      console.log('最后传进去的参数', data)
      queryPageHistory(data).then((res) => {
        // console.log('接口返回', res)
        this.tableData = res.result.records
        this.paginationTotal = res.result.total
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.engineering-manage {
  height: 100vh;
  margin: 0;
  padding: 20px 0;
  box-sizing: border-box;
  position: relative;
  font-size: 12px;
  // 表格样式
  .table-box {
    width: 96%;
    margin: auto;
    display: flex;
    height: 100%;
    flex-direction: column;
    .top-tool {
      display: flex;
      justify-content: space-between;
      flex-direction: row;
      // flex-wrap: wrap;
      font-size: 12px;
      /deep/ .serch-engineering {
        display: flex;
        // justify-content: space-around;
        align-items: center;
        margin-bottom: 14px;
        .sampleTime {
          width: 308px !important;
          .el-input {
            width: 140px;
          }
        }
        .release-radio {
          display: flex;
          align-items: center;
          white-space: nowrap;
          .el-radio {
            margin-right: 10px;
          }
          .release-title {
            margin: 0 10px;
          }
          .el-checkbox {
            margin-right: 12px;
          }
        }
        .serch-input {
          width: 245px;
          // margin-right: 20px;
        }
        .el-input__inner {
          height: 34px;
        }
        .date-css {
          width: 140px;
        }

        .title {
          font-size: 14px;
          color: #606266;
          font-family: Arial;
          white-space: nowrap;
          margin-left: 10px;
        }
      }

      .right-btn {
        margin-bottom: 14px;
        display: flex;
        // display: flex;
        // align-items: center;
        // flex-direction: row;
        // flex-wrap: wrap;
      }
    }

    /deep/ .el-table {
      flex: 1;
      // overflow-y: scroll;
      th.el-table__cell > .cell {
        color: rgb(50, 59, 65);
        height: 40px;
        line-height: 40px;
        background: rgb(234, 241, 253);
      }
      .el-table__row--striped > td {
        background-color: #f3f7fe !important;
      }
      .hover-row {
        color: #e6a23c;
        background-color: rgba($color: #2d74e7, $alpha: 0.1);
      }
      .rowBgBlue {
        & > td {
          color: #fff;
          border-right: 1px solid #ebeef5;
          background-color: #69a8ea !important;
        }
      }
    }
  }

  .hd-input {
    /deep/.el-input__inner {
      width: 70%;
    }
  }
  .el-select {
    width: 8%;
  }
  /deep/ .is-required {
    position: relative;
    .select-btn {
      position: absolute;
      top: 0;
      left: 72%;
    }
  }

  .histroyPipeData {
    position: fixed;
    top: 120px;
    z-index: 999;
    right: 50px;
    // 详情卡片的样式
      /deep/.el-table .el-table__cell {
    padding: 0;
  }
    .detailsCrad {
      z-index: 9;
      .clearfix:before,
      .clearfix:after {
        display: table;
        content: '';
      }
      .clearfix:after {
        clear: both;
      }

      /deep/ .box-card {
        width: 500px;
        max-height: 80vh;
        .el-card__header {
          height: 48px;
          color: #fff;
          background-color: #2d74e7;
        }
        .el-card__body {
          padding: 0;
          .el-menu-item {
            height: 45px;
          }
        }
        .content {
          height: 600px;
          // padding: 22px;
          // box-sizing: border-box;
          .box1 {
            // max-height: 545px;
            height: 100%;
            padding: 10px 20px;
            .el-row {
              padding: 0 10px;
            }
            .historyList {
              .historyTitle {
                height: 30px;
                color: #555555;
                font-weight: bold;
                padding: 5px 10px;
                box-sizing: border-box;
                margin: 10px 0;
                display: flex;
                justify-content: space-between;
                align-items: center;
                background-color: #f6f9fe;
              }

              .info-box {
                height: 100%;
                display: flex;
                margin: 5px 0;
                justify-content: space-between;
                .info-text {
                  width: 48%;
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  .el-form {
                    .el-form-item {
                      margin-bottom: 10px;
                    }
                    .el-link--inner {
                      max-width: 140px;
                      /* 1.先强制一行内显示文本 */
                      white-space: nowrap;
                      /* 2.超出部分隐藏 */
                      overflow: hidden;
                      /* 3.文字用省略号替代超出的部分 */
                      text-overflow: ellipsis;
                    }
                  }
                }
                .info-video {
                  width: 48%;
                  .image-list {
                    height: 155px;
                    display: flex;
                    flex-direction: column;
                  }
                  .el-tabs {
                    .el-tabs__nav-wrap {
                      width: 100% !important;
                    }
                    .el-tabs__item {
                      margin: 11px 0 0 0 !important;
                      background: transparent !important;
                    }
                    .el-tabs__header {
                      border-top: 0 !important;
                      background: transparent !important;
                    }
                  }
                }
              }
            }

            .el-textarea__inner,
            .el-input__inner {
              color: #666;
            }
            .detailsTitle {
              position: relative;
              font-size: 16px;
              padding: 5px 10px;
              box-sizing: border-box;
            }
            .detailsTitle::after {
              position: absolute;
              top: 5px;
              left: -10px;
              content: '';
              width: 4px;
              height: 65%;
              background-color: #2d74e7;
            }
          }
          /deep/ .el-form {
            .is-disabled {
              .el-input__inner {
                background-color: transparent;
              }
              .el-textarea__inner {
                background-color: transparent;
              }
            }
            .el-form-item {
              margin-bottom: 10px;
            }
          }
        }
        .table-content {
          padding: 15px;
          /deep/ .content-info {
            font-size: 12px;
            display: flex;
            justify-content: space-between;

            .detailsTitle {
              position: relative;
              padding-left: 10px;
              box-sizing: border-box;
              margin-bottom: 10px;
            }
            .detailsTitle::after {
              position: absolute;
              left: 0;
              content: '';
              width: 4px;
              height: 100%;
              background-color: #2d74e7;
            }
          }
        }
      }
    }
  }
  .PipeEvData {
    position: fixed;
    top: 100px;
    right: 45px;
    z-index: 9;
    .detailsCrad {
      .clearfix:before,
      .clearfix:after {
        display: table;
        content: '';
      }
      .clearfix:after {
        clear: both;
      }

      .box-card {
        width: 550px;
        min-height: 310px;
        border: none;
        border-radius: 5px;
        /deep/ .el-card__header {
          height: 48px;
          color: #fff;
          background-color: #2d74e7;
        }
        /deep/.el-card__body {
          padding: 15px !important;
          .el-menu-item {
            height: 45px;
            font-size: 16px;
          }
        }
        .content {
          .content-info {
            overflow-y: scroll;
            height: 600px;
            padding: 10px 20px;
            .info-title {
              font-size: 14px;
              font-weight: bold;
              margin: 5px 0;
            }
            .info-box {
              height: 100%;
              display: flex;
              justify-content: space-between;
              .info-text {
                width: 37%;
                padding: 10px;
                box-sizing: border-box;
                background-color: #f3f7fe;
                border: 1px solid #dedede;
              }
              .info-video {
                width: 60%;
                border: 1px solid #dedede;
              }
            }
            /deep/.el-form {
              .el-link--inner {
                max-width: 416px;
                /* 1.先强制一行内显示文本 */
                white-space: nowrap;
                /* 2.超出部分隐藏 */
                overflow: hidden;
                /* 3.文字用省略号替代超出的部分 */
                text-overflow: ellipsis;
              }
              /deep/.is-disabled {
                .el-input__inner {
                  background-color: transparent;
                }
                .el-textarea__inner {
                  background-color: transparent;
                }
              }
              .el-form-item {
                margin-bottom: 10px;
              }
            }
            /deep/.el-textarea__inner,
            .el-input__inner {
              color: #666;
            }
            .detailsTitle {
              position: relative;
              font-size: 16px;
              padding: 5px 0;
              box-sizing: border-box;
            }
            .detailsTitle::after {
              position: absolute;
              top: 5px;
              left: -10px;
              content: '';
              width: 4px;
              height: 65%;
              background-color: #2d74e7;
            }
          }
        }
        .table-content {
          padding: 15px;
          .content-info {
            font-size: 12px;
            display: flex;
            justify-content: space-between;

            .left {
              flex: 1;
              .text-space {
                margin: 10px 0;
                /deep/.el-link--inner {
                  max-width: 240px;
                  // 1.先强制一行内显示文本
                  white-space: nowrap;

                  // 2.超出部分隐藏
                  overflow: hidden;
                  // 3.文字用省略号替换超出的部分
                  text-overflow: ellipsis;
                }
              }
            }
            .right {
              flex: 1;

              /deep/.is-top {
                margin: 0 0 10px;
              }
              // .el-tabs__header{
              //   border-top: none;
              //       margin-bottom: 6px;
              //   background-color: transparent !important;
              // }
              /deep/.el-tabs {
                .container {
                  height: 100%;
                  width: 100%;
                  padding-top: 5px;
                  box-sizing: border-box;
                }
                .el-tabs__content {
                  height: 150px;
                  width: 234px;
                }
                .el-tabs__item {
                  margin: 11px 0 0 0 !important;
                  background: transparent !important;
                }
                .el-tabs__header {
                  border-top: 0 !important;
                  background: transparent !important;
                }
              }
              // .el-tabs__nav-wrap::after {
              //   z-index: 2;
              // }
              // .el-tabs__active-bar
            }
            .detailsTitle {
              position: relative;
              margin: 6px 0;
              padding-left: 10px;
              box-sizing: border-box;
            }
            .detailsTitle::after {
              position: absolute;
              left: 0;
              content: '';
              width: 4px;
              height: 100%;
              background-color: #2d74e7;
            }
          }
        }
      }
    }
  }
}

.hide-scroller {
  &::-webkit-scrollbar {
    width: 0;
  }
  // &::-webkit-scrollbar-thumb {
  //   background: #99a9bf;
  //   border-radius: 20px;
  // }
}

#popupCardIns {
  &::after {
    content: '';
    display: block;
    width: 45px;
    height: 27px;
    background: url('../../components/testImg/corner.png');
    position: absolute;
    bottom: -26px;
    left: 50%;
    transform: translate(-50%, 0);
  }
}
</style>