<template>
  <div id="heads">
    <el-row>
      <div class="headTop">
        <a href="" class="headImg">
          <img src="../../assets/default_logo.png" width="60" height="60" />
        </a>
        <!-- <a class="headXinyong">信用等级</a> -->
        <h3 class="headCompany">{{ user.corpname }}</h3>
      </div>
      <div class="headBtn">
        <!-- <notice :list="noticeList" :total="total" @delete="noticeDelete"></notice> -->
        <!-- <span class="mr14">|</span> -->
        <!-- <a href="" class="mr14" style="color:red" title="云校招企业服务平台简明使用手册"> <span class="el-icon-question info_icon"></span> 帮助 </a> -->
        <span class="mr14">|</span>
        <span class="mr14">
          <span class="el-icon-s-custom info_icon"></span>
          &nbsp;{{ user.name }}
        </span>
        <a class="mr14" @click="dialog = true">
          <el-link class="el-icon-edit-outline info_icon">修改密码</el-link>
        </a>
        <span class="mr14">|</span>
        <a @click="logout" style="color: #333;"
          ><span class="el-icon-switch-button info_icon"></span>
          &nbsp;退出
        </a>
      </div>
    </el-row>
    <el-dialog width="30%" title="修改密码" :visible.sync="dialog">
      <el-form :model="form" :rules="rules" ref="form" label-width="auto" label-position="left">
        <el-form-item label="新密码：" prop="passwd">
          <el-input v-model="form.passwd" autocomplete="off" type="password" show-password></el-input>
        </el-form-item>
        <!-- <el-form-item label="重复输入新密码：">
          <el-input v-model="form.date2" autocomplete="off"></el-input>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="toClose">取 消</el-button>
        <el-button type="success" @click="toSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import notice from '@publics/src/components/notice.vue';
import { mapActions, mapState, mapMutations } from 'vuex';
const jwt = require('jsonwebtoken');
export default {
  name: 'heads',
  props: {},
  components: {
    // notice,
  },
  data: () => ({
    dialog: false,
    form: {},
    rules: {
      passwd: [{ required: true, message: '请输入新密码', trigger: 'blur' }],
    },
    formLabelWidth: '120px',
    html: '<ul class="popoverCon"><li>没有消息</li></ul><a class="popoverBtn">点击进入信息中心<span class="el-icon-d-arrow-right info_icon"></span></a>',
    noticeList: [],
    total: 0,
  }),
  created() {
    this.setUser();
    this.check();
  },
  watch: {
    // $route: {
    //   handler(val) {
    //     this.getNoticeList();
    //   },
    // },
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...mapMutations(['setUser']),
    ...mapActions(['userOperation', 'noticeOperation']),
    check() {
      if (!this.user.corpid) this.$router.push({ path: '/login' });
    },
    toClose() {
      this.$refs.form.resetFields();
      this.dialog = false;
    },
    toSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submit();
        }
        return false;
      });
    },
    async submit() {
      let result = await this.userOperation({ type: 'passwd', data: { info: this.form, id: this.user.id } });
      this.$message({
        type: `${result.errcode}` === '0' ? 'success' : 'error',
        message: `${result.errcode}` === '0' ? '修改成功' : result.errmsg,
      });
      if (`${result.errcode}` === '0') {
        this.form = {};
        this.dialog = false;
      }
    },
    logout() {
      sessionStorage.removeItem('token');
      sessionStorage.removeItem('user');
      this.setUser(undefined);
      this.$router.push('/login');
    },
    async getNoticeList() {
      let result = await this.noticeOperation({ type: 'list', data: { userid: this.user.corpid, type: 1 } });
      if (`${result.errcode}` === '0') {
        this.$set(this, `total`, result.total);
        this.$set(this, `noticeList`, result.data ? result.data : []);
      }
    },
    async noticeDelete(id) {
      let result = await this.noticeOperation({ type: 'delete', data: { id: id } });
      if (`${result.errcode}` === '0') {
        this.getNoticeList();
      }
    },
  },
};
</script>

<style lang="less" scoped>
img {
  max-height: 100%;
  max-width: 100%;
}
a {
  text-decoration: none;
}
.headTop {
  float: left;
  width: 50%;
  padding: 0 0 0 50px;
}
.headImg {
  float: left;
  width: 65px;
  height: 60px;
}
.headXinyong {
  float: left;
  width: 70px;
  height: 40px;
  margin: 13px 0 0 10px;
}
.headCompany {
  float: left;
  font-size: 21px;
  width: 244px;
  padding: 18px 0;
  margin: 0;
  color: #333;
  font-family: 'inherit';
  font-weight: 500;
}
.headBtn {
  float: right;
  width: 40%;
  text-align: right;
  padding: 0 60px 0 0;
  margin-top: 20px;
  font-size: 14px;
  color: #333;
}
.headBtn .mr14 {
  margin-right: 14px;
  color: #333;
}
.headBtn .el-button {
  border-radius: 0px;
  border: none;
  width: 0;
  height: 0px;
}
.headBtn .el-button:hover {
  background: none;
}
.popover-content {
  margin: 0;
  padding: 0;
  .el-col {
    border-bottom: 1px dashed #cccccc;
    font-size: 0.8rem;
    height: 1.25rem;
  }
}
/deep/.el-popper {
  border: 1px solid #ccc;
  border-radius: 0px;
  height: 100px;
  padding: 0;
}
/deep/.popoverCon {
  width: 400px;
  height: 70px;
  text-align: center;
  padding: 0;
  margin: 0;
}
/deep/.popoverCon li {
  list-style: none;
}
/deep/.popoverBtn {
  position: absolute;
  bottom: 0;
  left: 0px;
  width: 424px;
  height: 30px;
  line-height: 30px;
  text-align: right;
  color: #333;
  border-radius: 0 0 4px 4px;
  background: #f6f6f6;
  margin: 0;
  padding: 0;
}
/deep/.popoverBtn:hover {
  text-decoration: underline;
  color: #409eff;
}
/deep/.el-form-item__label {
  padding: 0px 0px 0 0;
}
/deep/.el-dialog__header {
  background-color: #40a44c;
}
/deep/.el-icon-close:before {
  color: #000;
}
/deep/.el-dialog__footer {
  padding: 0px 20px 10px;
}
/deep/.el-dialog__body {
  padding: 15px 20px;
}
</style>
