<template>
  <div class="ng-scope pb-8">
    <navbar :user="userInfo" @openLoginDialog="openLoginDialog"></navbar>
    <div class="p-wrap-full clear pt30">
      <div class="w-full">
        <img class="rounded-xl" src="/static/images/login-banner-1.jpg"/>
      </div>
    </div>
    <div class="p-wrap-full pt-6 flex">
      <div class="mr-6">
        <div class="m-login opacity-bg mb-4">
          <is-login v-if="loginOk" :user="userInfo" @logout="logout"></is-login>
          <un-login v-else @login="login" :err="err"></un-login>
        </div>
        <div class="bg-white flex-auto rounded-xl px-6 py-2">
          <div class="text-xl text-center leading-10 pb-2 border-gray-200 border-b text-blue">
            证书查询
          </div>
          <div class="text-center p-2">
            <el-button @click="gotoOutlink()" type="primary"> 前往证书查询 </el-button>
          </div>
        </div>
      </div>
      <div class="bg-white flex-auto rounded-xl px-6 py-2" >
        <div class="text-xl text-center leading-10 pb-2 border-gray-200 border-b text-blue">
            新闻通知
        </div>
        <el-table :data="postList"  highlight-current-row
        :show-header="false" min-height="310px" style="overflow: hidden;" >
          <el-table-column class-name="t-column" min-width="600px">
            <template slot-scope="{row, $index}">
              <span class="px-4 py-6 cursor-pointer hover:text-blue-light" @click="gotoDetail(row.postId)">{{$index+1}}、{{ row.title }}</span>
            </template>
          </el-table-column>
          <el-table-column width="160px">
            <template slot-scope="{row}">
              <span>{{ row.publishTime  }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>

    </div>
    <div class="p-wrap-full ng-scope mt30">
      <div class="title-box mt5">
        <h1 class="title" style="font-size: 20px;color: #3876da">友情链接</h1>
      </div>
      <friendlink></friendlink>
    </div>
    <el-dialog
      class="fc tc login-dialog"
      :visible.sync="loginDialog"
       :show-close='false'
      width="330px"
      style="padding:0px;"
      @close="closeDialog"
    >
      <div class="m-login" style="background: none;">
        <un-login @login="login" :err="err"></un-login>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import isLogin from "./components/isLogin.vue";
import unLogin from "./components/unLogin.vue";
import LearnTime from "./components/learnTime/learnTime.vue";
import navbar from "@/components/nav/navbar.vue";
import Friendlink from "./components/friendlink/friendlink.vue";
import { httpServer } from "@/components/httpServer/httpServer.js";
import { mapGetters,mapActions } from "vuex";
import settings from '@/settings.js';

export default {
  components: {
    LearnTime,
    isLogin,
    unLogin,
    Friendlink,
    navbar
  },
  data() {
    return {
      loginOk: false,
      periodObj: {
        userName: "",
        idNum: "",
      },
      postList:[],
      loginDialog: false,
      err: {},
    };
  },
  computed: {
  	...mapGetters("user", ["typeList", "userInfo"])
  },
  beforeMount(){
     if( this.userInfo && this.userInfo.token){
       this.loginOk = true
     }else{
       this.loginOk = false
     }
  },
  created(){
    this.getPostList()
  },
  methods: {
    ...mapActions("user", ["loadBaseInfo", "doLogout", "doLogin"]),
    logout() {
      this.doLogout().then( res=>{
        this.loginOk = false;
      } )
    },
    login(param, cb) {
      this.doLogin( param ).then( res => {
        if( !res ){
          this.err.loginErrorEnter = "登入失败"
          this.loginOk = false;
          cb &&cb()
        }else{
          this.loginOk = true;
          this.loginDialog = false;
        }
      })
    },
    getPostList(){
      httpServer("course.getPostList", {page:1,type:'操作指南', size:6}).then( res=>{
        this.postList = res.data.list.slice(0,6)
      })
    },
    gotoDetail(postId){
      this.$router.push({name:'news', query:{postId}})
    },
    gotoCourse(item){
      if ( !localStorage.token ) {
        this.$message.successMsg("请先登入", 1)
        return
      }
      if( !item.isOpen ){
         this.$message.errorMsg("暂未开放", 1)
         return
      }
      this.$router.push( {path:'/center/market', query:{type: item.name}})
    },
    closeDialog() {
      this.loginDialog = false;
    },
    openLoginDialog() {
      this.loginDialog = true
    },
    gotoOutlink(){
      window.open( settings.outLink, '_brank');
    },
  },
};
</script>

<style>
@import url("login.css");
.floatbox{
  position: fixed;
  width: 160px;
  height: 60px;
  right: 60px;
  top: 90px;
  border-radius: 1.25rem;
  font-size: 30px !important;
  background-color: orange;
  line-height: 40px;
  text-align: center;
  color: #fff;
}
.right-nav {
    width: 135px;
    height: 180px;
    background-color: #8bbdf5;
    position: fixed;
    transition: bottom ease .9s;
    z-index: 0;
    right: 5%;
    top: 260px;
    text-align: center;
    border-radius: 5px;
}
.right-img {
    display: inline-block;
    border-radius: 30%;
    width: 80%;
    height: 64%;
    margin: 11px auto 0;
}
</style>
<style lang="less" scoped>
.ng-scope{
  color: red;
  & /deep/ .t-column{
      padding: 0;
    }
}
</style>
