<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.typeId" placeholder="请选择">
            <el-option
              v-for="item in projectType"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
          <span>应用技术：</span>
          <el-select v-model="form.technology" placeholder="请选择">
            <el-option label="全部" :value="null"></el-option>
            <el-option label="实景拍摄" value="live"></el-option>
            <el-option label="虚拟建模" value="virtual"></el-option>
            <el-option label="四维看看" value="4dkk"></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 class="addBtn" @click="$router.push('/layout/tab1_add')" v-if="userLogo">
            + 新增
          </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
            width="200"
            prop="projectTypeName"
            label="项目分类"
          ></el-table-column>
          <el-table-column prop="technology" label="应用技术" width="150">
          </el-table-column>
          <el-table-column prop="application" label="展示形式" width="150">
          </el-table-column>
          <el-table-column prop="age" label="项目时间" width="180">
          </el-table-column>
          <el-table-column prop="level" label="保密级别" width="120"></el-table-column>
          <el-table-column label="操作" width="230">
            <template #default='{row}'>
              <el-button type="text" @click="look(row.id)">查 看</el-button>
              <el-button type="text" @click="projecEdit(row.id)" v-if="userLogo">编 辑</el-button>
              <el-button type="text" @click="projecDel(row.id)" v-if="userLogo">删 除</el-button>
            </template>
          </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 { projectList, getProjectType, projecDel } from '@/apis/tab1'
export default {
  name: 'tab1',
  data () {
    // 这里存放数据
    return {
      privary: false,
      userLogo: true, // 用户标识
      total: 0,
      projectType: [],
      form: {
        pageNum: 1,
        pageSize: 10,
        searchKey: '',
        typeId: null,
        technology: null
      },
      tableData: []
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 点击编辑
    projecEdit (id) {
      this.$router.push({
        path: '/layout/tab1_edit',
        query: { id }
      })
    },
    // 点击删除
    projecDel (id) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          await projecDel(id)
          this.$message.success('删除成功!')
          this.projectList(this.form)
        })
        .catch(() => {
          this.$message.info('已取消删除')
        })
    },
    // 点击搜索
    search () {
      this.form.pageNum = 1
      this.projectList(this.form)
    },
    // 分页器方法
    currentChange (val) {
      // console.log('当前页改变了', val)
      this.form.pageNum = val
      this.projectList(this.form)
    },
    sizeChange (val) {
      // console.log('条数改变了', val)
      this.form.pageNum = 1
      this.form.pageSize = val
      this.projectList(this.form)
    },
    // 点击查看
    look (id) {
      this.$router.push({
        path: '/layout/tab1_look',
        query: { id }
      })
    },
    // 封装获取列表方法
    async projectList (data) {
      const res = await projectList(data)
      this.total = res.data.total
      this.tableData = res.data.list
      this.tableData.forEach(v => {
        v.technology = this.myTechnology(v.technology)
        v.application = this.myApplication(v.application)
        v.level = this.myLevel(v.level)
      })
      // console.log(999, res)
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  async created () {
    this.projectList(this.form)
    // 获取项目类型
    const res1 = await getProjectType()
    this.projectType = res1.data
    this.projectType.unshift({ id: null, name: '全部' })
    // 获取用户信息
    const aaa = localStorage.getItem('SWKK_userInfo')
    // console.log(999, JSON.parse(res))
    const userData = JSON.parse(aaa)
    // 如果是普通用户---删掉场景案例
    if (userData.roleId === 2) {
      this.userLogo = false
    }
  },
  // 生命周期 - 挂载完成（可以访问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__body-wrapper {
    max-height: 450px;
    overflow-y: auto;
  }
  /deep/.cell {
    padding-left: 20px !important;
  }
  /deep/.el-table__row .el-table__cell {
    padding: 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;
      border-radius: 8px;
      // overflow: hidden;
      position: relative;
      margin-top: 25px;
      .title {
        position: relative;
        padding: 15px 20px 0;
        background-color: #e3e6e9;
        .addBtn {
          cursor: pointer;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #fff;
          width: 80px;
          height: 30px;
          background-color: #dc3545;
          border-radius: 12px;
          z-index: 999;
          position: absolute;
          right: 56px;
          top: 62px;
        }
      }
      .privary{
        color: #fff;
        z-index: 999;
        position: absolute;
        right: 253px;
        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: -253px;
            top: 34px;
            padding: 20px;
            color: #dc3545;
            background-color: #d8dadc;
            li {
              margin-bottom: 12px;
            }
          }
      }
    }
    .paging {
      position: absolute;
      bottom: 15px;
      right: 50px;
    }
  }
}
</style>
