<template>
  <div class="navbar">
    <div style="display: flex;align-items: center" >
      <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
      <div class="title-logo">

        <div>
          百业兴智慧油站欢迎您
        </div>

      </div>
    </div>

<!--    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav"/>-->

<!--    <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/>-->

    <div class="right-menu">
<!--      <template v-if="device!=='mobile'">-->
<!--        <search id="header-search" class="right-menu-item" />-->
<!--        <screenfull id="screenfull" class="right-menu-item hover-effect" />-->
<!--        <FuintDoc id="fuint-doc" class="right-menu-item hover-effect" />-->
<!--      </template>-->
      <div class="d-s"style="margin-right: 20px">
          <img src="../../assets/images/qp.png" style="width: 28px;height: 28px;margin-right: 5px">
        <div>全屏</div>
      </div>
      <div class="d-s"style="margin-right: 20px">
        <img src="../../assets/images/tzzx.png" style="width: 28px;height: 28px;margin-right: 5px">
        <div>通知中心</div>
      </div>
      <el-dropdown class="d-s" trigger="click">
        <div class="d-s">
          <div class="title_">{{ deptName }}</div>
          <img :src="avatar" style="width: 28px;height: 28px;margin: 0px 10px" />
          <span class="user-name">{{ name }}</span>
          <i class="el-icon-caret-bottom"/>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="prsswrod()">
            <span>修改密码</span>
          </el-dropdown-item>
          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>

    <el-dialog
      title="提示"
      :visible.sync="xg"
      :modal="false"
      width="30%"
      :before-close="handleClose">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="新密码" prop="password">
        <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
      </el-form-item>
        <el-form-item label="重复密码" prop="passwords">
          <el-input type="password" v-model="ruleForm.passwords" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="xg = false">取 消</el-button>
        <el-button type="primary" @click="postparssword('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>



  </div>
</template>

<script>
import { getAccountInfo ,resetPwd ,getDeptName} from '@/api/indexBanner/index'
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import TopNav from '@/components/TopNav'
import Hamburger from '@/components/Hamburger'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import Search from '@/components/HeaderSearch'
import FuintDoc from '@/components/Fuint/Doc'
import confirmLog from "@/views/coupon/confirmLog/index.vue";

export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.passwords !== '') {
          this.$refs.ruleForm.validateField('passwords');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.ruleForm.password) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        password:'',
        passwords:''
      },
      deptName:'',
      rules:{
        // password: [
        //   { required: true, message: '请输入密码', trigger: 'blur' },
        //   { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        // ],
        // passwords: [
        //   { required: true, message: '请输入新密码', trigger: 'blur' },
        //   { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        // ],
        password: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
        passwords: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' },
          { validator: validatePass2, trigger: 'blur' }
        ],
      },
      xg: false
    }
  },
  components: {
    Breadcrumb,
    TopNav,
    Hamburger,
    Screenfull,
    SizeSelect,
    Search,
    FuintDoc
  },
  created() {
    this.getDeptName()
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'device'
    ]),
    setting: {
      get() {
        return this.$store.state.settings.showSettings
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'showSettings',
          value: val
        })
      }
    },
    topNav: {
      get() {
        return this.$store.state.settings.topNav
      }
    }
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    prsswrod(){
      console.log('方法')
      this.xg =! this.xg
      getAccountInfo().then(res=>{
        console.log(res)
        this.accountId = res.data.accountId

      })

    },
    getDeptName(){
      getDeptName().then(res=>{
        // console.log("获取到的deptName",res)
        this.deptName = res.data.deptName
      })
    },
    postparssword(ruleForm){
      if (this.ruleForm.password !== this.ruleForm.passwords) {
        this.$message({
          type: 'info',
          message: '两次密码不一致'
        });
        return
      }
      console.log(111111111111111111111)
      this.$refs[ruleForm].validate((valid) => {
          if (valid) {
            let data = {
              acctId : this.accountId,
              password: this.ruleForm.password,
            }
            resetPwd(data).then(res=>{
              console.log(res)
              if(res.code == 200){
                this.xg =false
              }

            })
          }else {
            console.log('error submit!!');
            return false;
          }
      })


    },
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = '/';
        })
      }).catch(() => {});
    }
  },

}
</script>

<style lang="scss" scoped>

.d-s{
  display: flex;
  align-items: center;
}
.title_{
  font-weight: bold;
  font-size: 18px;
  color: #333333;
}
.navbar {
  height: 90px;
  overflow: hidden;
  //position: relative;
  background: white;
  //background-image: url("../../assets/images/kkx.png") ;
  background-size: 100% 100%;
  background-size: cover;
  background-repeat: no-repeat;

  box-shadow: 0 1px 4px rgba(0,21,41,.08);
  box-sizing: border-box;
 display: flex;
  align-items: center;
  justify-content: space-between;
  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;
    margin-left: 10px;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }
  .title-logo{
    //position: absolute;
    //top: 50%; /* 将元素垂直向上移动容器高度的50% */
    //left: 5%; /* 将元素水平向左移动容器宽度的50% */
    //transform: translate(-50%, -50%); /* 通过移动元素的左上角使其居中 */
    //color: #ffffff;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
  }

  .breadcrumb-container {
    float: left;
  }

  .topmenu-container {
    position: absolute;
    left: 50px;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    display: flex;
    height: 100%;
   align-items: center;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-name {
          font-weight: bold;
          line-height: 35px;
          display: block;
          margin-left: 5px;
          font-size: 14px;
          float: left;
        }

        .user-avatar {
          cursor: pointer;
          width: 35px;
          height: 35px;
          border-radius: 10px;
          float: left;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -15px;
          top: 12px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
