<template>
  <div class="tunnel-bgc">
    <div class="box-top">
      <div class="back-tunnel" @click="router.back(-1)">
        <div class="back-icon"></div>
        <span>返回</span>
      </div>
      <div class="tunnel-title"></div>
      <div class="all-del-btn">
        <div class="all-btn" style=" margin-right: 40px;" v-if="!showAddIcon" @click="handleAdd">
          添加
        </div>
        <div class="all-btn" @click="handleChooseAll">
          全选
        </div>
        <div class="all-btn del-btn" @click="handleMoreDelete">
          删除
        </div>
      </div>
    </div>
    <div class="box-content">
      <div class="site-box" v-for="item in tunnelList" :key="item.tunnelId">
        <div class="top">
          <span>{{ item.tunnelName }}</span>
          <span>施工长度{{ item.constructionLength }}米 隧道长度{{ item.totalLength }}公里</span>
          <el-checkbox v-model="item.checked" size="large" @change="handleClickSite(item)"/>
        </div>
        <div class="box-center">
          <div>
            <div class="left-img"></div>
            <div>
              <div class="edit-btn" @click.stop="handleGoToEditTunnel(item.tunnelId)">
                <div class="edit-icon"></div>
                <div>隧道编辑</div>
              </div>
              <div class="edit-btn" @click.stop="handleEditDevice">
                <div class="edit-icon-two"></div>
                <div>设备管理</div>
              </div>
            </div>
          </div>
          <div class="tunnel-right">
            <div>
              <div class="fan-icon"></div>
              <span>风机异常</span>
            </div>
            <div class="icons-block">
              <div v-for="equItem in iconsList" :key="item.icon" class="icon-text">
                <div :style="{ backgroundImage: 'url(' +getImageUrl(equItem.icon)+')' }" class="icon"></div>
                <span>{{ equItem.name }}：{{ item.tunnelEquipmentAmountInfo[equItem.type] }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="site-box add-box" @click="handleAdd">
        <div class="add-icon"></div>
        <div style="cursor: pointer">添加隧道</div>
      </div>
    </div>
    <el-dialog :close-on-click-modal="false" v-model="isVisited" width="1958px">
      <div class="siteId">
        <span>{{ title }}</span>
      </div>
      <el-form :model="form" :label-position="right" label-width="168px">
        <el-form-item label="隧道名称">
          <el-input v-model="form.name" placeholder="请输入隧道名称"/>
        </el-form-item>
        <el-form-item label="序列号">
          <el-input v-model="form.serialNumber" placeholder="请输入序列号"/>
        </el-form-item>
        <el-form-item label="隧道长度">
          <el-input type="number" v-model="form.tunnelLength" placeholder="请输入隧道长度"/>
        </el-form-item>
        <el-form-item label="隧道备注">
          <el-input v-model="form.remarks" placeholder="请输入隧道备注"/>
        </el-form-item>
      </el-form>
      <div class="btns">
        <div class="cancel-btn" @click="isVisited=false">
          取消
        </div>
        <div class="sure-btn" @click="handleAddTunnel">
          确定
        </div>
      </div>
    </el-dialog>
    <div class="pagination">
      <span>首页</span>
      <el-pagination background v-model:current-page="pageInfo.pageNum" v-model:page-size="pageInfo.pageSize"
                     :total="total" prev-text="上一页" next-text="下一页" layout="prev, pager, next"
                     @current-change="handleCurrentChange"/>
      <span>尾页</span>
    </div>
  </div>
</template>

<script setup>
import {ElMessage, ElMessageBox} from "element-plus";
import {getTunnelList} from "@/api/tunnelManage";
import {deleteTunnel} from "../../api/tunnelManage";

const router = useRouter()
const showAddIcon = ref(true)
const siteId = reactive(router.currentRoute.value.params.siteId)
const tunnelList = ref([
  {
    tunnelName: '一号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '二号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  },
  {
    tunnelName: '三号隧道',
    num: 1,
    constructionLength: 500,
    implementationLength: 10
  }
])
const iconsList = ref([
  {
    icon: 'sd_icon_fj.png',
    name: '风机',
    type: 'frequency',
    num: 0
  },
  {
    icon: 'sd_icon_sd.png',
    name: '湿度',
    type: 'humidness',
    num: 0
  },
  {
    icon: 'sd_icon_fy.png',
    name: '风压',
    type: 'windPressure',
    num: 0
  },
  {
    icon: 'sd_icon_yq.png',
    name: '氧气',
    type: 'oxygen',
    num: 0
  },
  {
    icon: 'sd_icon_fs.png',
    name: '风速',
    type: 'windSpeed',
    num: 0
  },
  {
    icon: 'sd_icon_fc.png',
    name: '粉尘',
    type: 'dust',
    num: 1
  },
  {
    icon: 'sd_icon_wd.png',
    name: '温度',
    type: 'temperature',
    num: 0
  },
  {
    icon: 'sd_icon_qt.png',
    name: '有害气体',
    type: 'harmfulGas',
    num: 0
  },
])
const title = ref('新增隧道')
const isVisited = ref(false);
const tunnelIds = ref([])
const tunnelNameList = ref([])
const form = ref({
  name: '',
  serialNumber: '',
  tunnelLength: '',
  remarks: ''
});
const isEdit = ref(false)
const pageInfo = reactive({
  pageNum: 1,
  pageSize: 12
});
const total = ref(10);
const getList = () => {
  getTunnelList({
    ...pageInfo
  }).then(res => {
    if (res.code === 1000) {
      total.value=res.data.total
      tunnelList.value = res.data.rows
    }
  })
}
getList()
//点击页码进行分页功能
const handleCurrentChange = (val) => {
  pageInfo.pageNum = val
  getList()
}
const handleAddTunnel=()=>{

}
const handleGoToEditTunnel = (tunnelId) => {
  isEdit.value = true
  router.push('/edit/' + tunnelId)
}
const handleChooseAll = () => {
  tunnelList.value.map(item => {
    item.checked = !item.checked
  })
}
const handleEdit = () => {
  title.value = '编辑隧道'
  // isVisited.value = true
}
const handleEditDevice = () => {
  router.push('/device/' + 1)
}
const restFrom = () => {
  form.value = {
    address: '',
    siteName: '',
    describe: ''
  }
}
const handleAdd = () => {
  restFrom()
  title.value = '新增隧道'
  isVisited.value = true
}
const getImageUrl = (name) => {
  return new URL(`../../assets/images/tunnel/${name}`, import.meta.url).href
}
const handleClickSite = (type) => {
  if (type.checked) {
    tunnelIds.value.push(type.tunnelId)
    tunnelNameList.value.push(type.tunnelName)
  } else {
    tunnelIds.value.map((item, index) => {
      if (item === type.tunnelId) {
        tunnelIds.value.splice(index, 1)
      }
    })
    tunnelNameList.value.map((item, index) => {
      if (item === type.tunnelName) {
        tunnelNameList.value.splice(index, 1)
      }
    })
  }
}
const handleMoreDelete = () => {
  if (tunnelIds.value.length === 0) {
    ElMessage.warning('请先选择隧道进行删除')
  } else {
    ElMessageBox.confirm(`是否确定删除该隧道`, '系统提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
      customClass: 'delBox'
    }).then(() => {
      deleteTunnel(tunnelIds.value).then(res => {
        if (res.code === 1000) {
          ElMessage.success(res.msg)
          getList()
          tunnelIds.value = []
          tunnelNameList.value = []
        } else {
          ElMessage.error(res.msg)
        }
      })
    })
  }
}

</script>

<style scoped lang="scss">
:deep(.el-dialog) {
  border: 2px solid #05FEFF;
  background: #0D6578;
  border-radius: 20px;
  padding: 30px 40px;
  box-sizing: border-box;
  margin: 458px auto 0 auto;

  .el-dialog__header {
    padding: 0;
    display: none;
  }
}

:deep(.el-form-item) {
  margin-top: 40px;
}

:deep(.el-form-item__label) {
  font-size: 38px;
  font-family: MicrosoftYaHei;
  color: #FFFFFF;
  margin-right: 12px;
  line-height: 50px;
}

:deep(.el-input) {
  height: 75px;

  .el-input__wrapper {
    background-color: transparent;
    border: 1px solid #08B7B8;

    .el-input__inner {
      height: auto;
      color: #fff;
      font-size: 38px;
    }
  }
}

.siteId {
  display: flex;
  justify-content: center;
  margin: 0 0 60px 0;
  font-size: 50px;
  color: #FFFFFF;
}

.tunnel-bgc {
  background-color: #072348;
  padding: 85px 0 0 0;
  width: 100%;
  height: 100%;
  background-image: url('@/assets/images/tunnel/sd_bj.png');

  .box-top {
    display: flex;
    justify-content: space-between;

    .back-tunnel {
      cursor: pointer;
      margin: 0 0 0 70px;
      display: flex;
      align-items: center;
      width: 178px;
      height: 70px;
      line-height: 70px;
      border-radius: 11px;
      border: 2px solid #08B7B8;
      font-size: 38px;
      color: #FFFFFF;

      .back-icon {
        margin-right: 20px;
        margin-left: 23px;
        width: 33px;
        height: 33px;
        background-image: url('@/assets/images/site/zdgl_icon_fh.png');
      }
    }

    .all-del-btn {
      display: flex;

      .del-btn {
        width: 168px;
        height: 60px;
        background: #08B7B8;
        border-radius: 11px;
      }

      .all-btn {
        cursor: pointer;
        padding-left: 53px;
        width: 178px;
        height: 70px;
        line-height: 70px;
        border-radius: 11px;
        border: 2px solid #08B7B8;
        color: #FFFFFF;
        font-size: 38px;

        &:last-child {
          margin-left: 40px;
          margin-right: 70px;
        }
      }
    }
  }

  .box-content {
    height: 1850px;
    display: flex;
    flex-wrap: wrap;
    padding-left: 67px;
    padding-right: 70px;
    justify-content: space-between;
    box-sizing: border-box;
    overflow: hidden;

    .add-box {
      cursor: pointer;
      font-weight: bold;
      color: #60DDDE;
      font-size: 38px;
      display: flex;
      flex-direction: column;
      align-items: center;

      .add-icon {
        margin-top: 110px;
        margin-bottom: 87px;
        width: 220px;
        height: 220px;
        background-image: url('@/assets/images/site/zdgl_icon_tjz.png');
      }
    }

    .site-box {
      cursor: pointer;
      margin-top: 50px;
      margin-right: 1.5%;
      padding: 40px 30px;
      width: 925px;
      height: 550px;
      background-image: url('@/assets/images/tunnel/zdgl_bj.png');
      //box-sizing: border-box;
      position: relative;

      //&:hover {
      //  background-image: url('@/assets/images/tunnel/sdgl_bjtq.png');
      //}

      &:nth-child(4n) {
        margin-right: 0;
      }

      .top {
        display: flex;
        justify-content: space-between;
        font-size: 45px;
        font-weight: bold;
        color: #FFFFFF;
        line-height: 42px;

        > span:nth-child(2) {
          font-size: 38px;
          color: #5CE4F2;
        }

        > div:last-child {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border: 2px solid #05FEFF;
          border-radius: 25px;
          position: relative;

          .clickColor {
            position: absolute;
            top: 7px;
            left: 6.5px;
            width: 25px;
            height: 25px;
            background-color: #05FEFF;
            border-radius: 25px;
          }
        }
      }

      .box-center {
        display: flex;

        //flex-direction: column;
        > div:first-child {

          > div:nth-child(2) {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-right: 30px;
          }
        }

        .left-img {
          margin-top: 110px;
          margin-right: 50px;
          width: 340px;
          height: 148px;
          background-image: url('@/assets/images/tunnel/sdgl_sdt.png');
        }

        .edit-btn {
          cursor: pointer;
          margin-top: 100px;
          display: flex;
          align-items: center;
          justify-content: flex-start;
          font-size: 30px;
          color: #60DDDE;
          //margin-left: 175px;

          .edit-icon {
            width: 32px;
            height: 34px;
            background-image: url('@/assets/images/site/zdgl_icon_bj.png');
            margin-right: 10px;
          }

          .edit-icon-two {
            width: 32px;
            height: 34px;
            background-image: url('@/assets/images/tunnel/device.png');
            margin-right: 10px;
          }
        }

        .tunnel-right {
          padding-top: 40px;

          > div:first-child {
            display: flex;
            align-items: center;
            font-size: 36px;
            color: #FB3838;

            .fan-icon {
              margin-right: 10px;
              width: 32px;
              height: 32px;
              background-image: url('@/assets/images/tunnel/sp_icon_yc.png');
            }
          }

          .icons-block {
            margin-top: 30px;
            display: flex;
            flex-wrap: wrap;

            .icon-text {
              display: flex;
              justify-content: space-between;
              align-items: center;
              color: #FFFFFF;
              font-size: 34px;
              margin-right: 17px;
              margin-bottom: 30px;

              &:first-child {
                margin-right: 37px;
              }

              &:nth-child(2n) {
                margin-right: 0;
              }

              .icon {
                width: 32px;
                height: 32px;
                margin-right: 10px;
              }
            }
          }
        }
      }
    }
  }

  .pagination {
    display: flex;
    align-items: center;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    bottom: 50px;
    color: #60DDDE;
    font-size: 38px;
    font-weight: bold;

    > span:first-child {
      margin-right: 60px;
    }

    > span:last-child {
      margin-left: 71px;
    }

    :deep(.btn-prev) {
      background-color: transparent;
      font-size: 38px;
      font-weight: bold;
      color: #60DDDE;
      margin-right: 20px;

    }

    :deep(.btn-next) {
      background-color: transparent;
      font-size: 38px;
      font-weight: bold;
      color: #60DDDE;
      margin-left: 30px;
    }

    :deep(.el-pager li.is-active ) {
      width: 70px;
      height: 70px;
      background: #60DDDE;
      border-radius: 50%;
      color: #071F40;
      font-size: 38px;
      font-weight: bold;
    }

    :deep(.el-pager li) {
      margin-left: 40px;
    }

    :deep(.el-pager li:not(.is-active) ) {
      width: 70px;
      height: 70px;
      border: 1px solid #60DDDE;
      border-radius: 50%;
      background-color: transparent;
      font-size: 38px;
      font-weight: bold;
      color: #60DDDE;
    }
  }

}
</style>
