<template>
  <div class="template">
    <div class="top">
      <div class="location">数据管理 / <span>场景案例</span></div>
    </div>
    <div class="conten">
      <div class="search">
        <div class="txt">筛选查询</div>
        <div class="row">
          <span>输入搜索：</span>
          <el-input v-model="form.searchKey" placeholder="请输入"></el-input>
          <span>项目分类：</span>
          <el-select v-model="form.projectTypeId" placeholder="请选择">
            <el-option
              v-for="item in projectType"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
        <div class="btn" @click="search">搜 索</div>
      </div>
      <!-- 表格 -->
      <div class="table">
        <div
          class="privary"
          @mouseenter="privary = true"
          @mouseleave="privary = false"
        >
          <div class="tit">?</div>
          <ul v-show="privary">
            <li>一般--所有人可查阅</li>
            <li>秘密--查阅人为公司内部所有员工，经过允许可对外分享</li>
            <li>机密--查阅人为管理员、项目负责人、获得允许的员工</li>
            <li>绝密--查阅人仅为管理员、项目负责人</li>
          </ul>
        </div>
        <div class="title">
          <div class="txt">场景列表</div>
        </div>
        <el-table
          :header-cell-style="{ background: '#e3e6e9' }"
          :data="tableData"
          stripe
          style="width: 100%"
        >
          <el-table-column label="序号" width="60">
            <template slot-scope="scope">
              {{ scope.$index + (form.pageNum - 1) * form.pageSize + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="场景名称"></el-table-column>
          <el-table-column label="所属项目" #default="{ row }">
            <span style="cursor: pointer;" @click="jump(row.projectId)">{{row.projectName}}</span>
          </el-table-column>
          <el-table-column prop="projectTypeName" label="所属项目分类" width="160"></el-table-column>
          <el-table-column prop="updateTime" label="项目时间" width="180"> </el-table-column>
          <el-table-column label="链接" #default="{ row }">
            <a :href="row.url" target="_blank">{{ row.url }}</a>
          </el-table-column>
          <el-table-column prop="level" label="保密级别" width="120"> </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="paging">
        <el-pagination
        layout="prev, pager, next,sizes,jumper"
        :total="total"
          :current-page='form.pageNum'
          @current-change="currentChange"
          @size-change="sizeChange"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { getProjectType } from '@/apis/tab1'
import { getSceneList } from '@/apis/tab2'
export default {
  name: 'tab3',
  data () {
    // 这里存放数据
    return {
      privary: false,
      projectType: [],
      total: 0,
      form: {
        pageNum: 1,
        pageSize: 10,
        searchKey: '',
        projectTypeId: ''
      },
      tableData: []
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    jump (id) {
      this.$router.push({
        path: '/layout/tab1_look',
        query: { id }
      })
    },
    // 封装获取文物列表方法
    async getSceneList (data) {
      const res = await getSceneList(data)
      this.tableData = res.data.list
      // console.log(999, res)
      this.tableData.forEach(v => {
        v.level = this.myLevel(v.level)
      })
      this.total = res.data.total
    },
    // 分页器方法
    currentChange (val) {
      // console.log('当前页改变了', val)
      this.form.pageNum = val
      this.getSceneList(this.form)
    },
    sizeChange (val) {
      // console.log('条数改变了', val)
      this.form.pageNum = 1
      this.form.pageSize = val
      this.getSceneList(this.form)
    },
    // 点击搜索
    search () {
      this.form.pageNum = 1
      this.getSceneList(this.form)
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  async created () {
    this.getSceneList(this.form)
    // 获取项目类型
    const res1 = await getProjectType()
    this.projectType = res1.data
    this.projectType.unshift({ id: '', name: '全部' })
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {},
  beforeCreate () {}, // 生命周期 - 创建之前
  beforeMount () {}, // 生命周期 - 挂载之前
  beforeUpdate () {}, // 生命周期 - 更新之前
  updated () {}, // 生命周期 - 更新之后
  beforeDestroy () {}, // 生命周期 - 销毁之前
  destroyed () {}, // 生命周期 - 销毁完成
  activated () {} // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='less' scoped>
.template {
  /deep/.cell{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  }
  /deep/.el-table__row td:nth-of-type(3) {
    color: #E97B86;
  }
  /deep/.el-table__row td:nth-of-type(6) {
    color: #E97B86;
  }

  /deep/.el-table__body-wrapper {
    max-height: 450px;
    overflow-y: auto;
  }
  /deep/.cell {
    padding-left: 20px !important;
  }
  /deep/.el-table__row .el-table__cell {
    padding: 8px 0 !important;
  }
  /deep/.el-pager li {
    background: transparent !important;
  }
  /deep/.btn-prev {
    background: transparent !important;
  }
  /deep/.btn-next {
    background: transparent !important;
  }
  padding: 0px 30px;
  .top {
    display: flex;
    align-items: center;
    height: 58px;
    width: 100%;

    .location {
      font-size: 22px;
      color: #999;
      & > span {
        color: black;
      }
    }
  }
  .conten {
    position: relative;
    width: 100%;
    height: 780px;
    .txt {
      font-weight: 700;
      height: 40px;
      border-bottom: 1px solid #A3A2A9;
    }
    .search {
      position: relative;
      padding: 15px 20px 0;
      border-radius: 5px;
      box-shadow: 0px 0px 5px 0px;
      height: 130px;
      background-color: #d8dadc;
      .row {
        width: 100%;
        margin-top: 20px;
        display: flex;
        align-items: center;
        & > div {
          margin-right: 50px;
          width: 20%;
          display: flex;
          align-items: center;
        }
      }
      .btn {
        border-radius: 5px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: #fff;
        cursor: pointer;
        width: 170px;
        height: 40px;
        background-color: #dc3545;
        position: absolute;
        right: 50px;
        top: 75px;
      }
    }
        .table {
      border-radius: 8px;
      overflow: hidden;
      position: relative;
      margin-top: 25px;
      .title {
        position: relative;
        padding: 15px 20px 0;
        background-color: #e3e6e9;
      }
            a {
        color: #e97b86;
      }
      .privary {
        color: #fff;
        z-index: 999;
        position: absolute;
        right: 20px;
        top: 68px;
        .tit {
          background-color: #dc3545;
          width: 20px;
          height: 20px;
          border-radius: 50%;
          display: flex;
          justify-content: center;
          align-items: center;
          cursor: pointer;
        }
        ul {
          width: 450px;
          position: absolute;
          right: -20px;
          top: 34px;
          padding: 20px;
          color: #dc3545;
          background-color: #d8dadc;
          li {
            margin-bottom: 12px;
          }
        }
      }    }
    .paging {
      position: absolute;
      bottom: 15px;
      right: 50px;
    }
  }
}
</style>
