<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-10 14:44:45
 * @LastEditors: 无尘
 * @LastEditTime: 2019-09-25 17:12:26
 -->
<template>
  <div class="navwrap boxbttom">
    <el-breadcrumb separator="/">
      <template v-for="(item, index) in navpath">
        <template v-if="!!item.path">
          <el-breadcrumb-item :key="'nav' + index" :to="{ path: item.path }" @click="changeRoute(item.path, item.relocation)">
            <span class="el-breadcrumb__inner is-link" @click="changeRoute(item.path, item.relocation)">
              {{ item.name }}
            </span>
          </el-breadcrumb-item>
        </template>
        <template v-else>
          <el-breadcrumb-item :key="'nav' + index">{{ item.name }}</el-breadcrumb-item>
        </template>
      </template>
    </el-breadcrumb>
    <h1 class="navtitle" v-if="!slotFlag">{{ navpath[navpath.length - 1].name }}</h1>
    <slot v-if="slotFlag"></slot>
    <div class="navmTop" v-if="subNavText">
      {{ subNavText }}
    </div>
    <div class="navtip navmTop" v-if="navtip == true"><i class="el-icon-info navtipcolor"></i>变更导航个数，移动顺序，更换页面链接均需提交小程序审核后重新发布生效，其他变更立即生效。小程序审核请联系品牌项目经理。</div>
  </div>
</template>

<script>
import { postRequest } from '@/api/api';
import errMsg from '@/common/js/error';
export default {
  name: 'navpath',
  data() {
    return {
      projectName: 'member' // 当前项目名
      // navpath: [
      //   {
      //     name: '首页',
      //     path: ''
      //   },
      //   {
      //     name: '会员标签',
      //     path: ''
      //   },

      // ],
    };
  },
  props: {
    navpath: {
      type: Array,
      default: function() {
        return [];
      }
    },
    slotFlag: {
      type: Boolean,
      default: false
    },
    navtip: {
      type: Boolean,
      default: false
    },
    subNavText: {
      type: String,
      default: ''
    }
  },
  methods: {
    changeRoute(path, relocation) {
      let that = this;
      if (relocation) {
        window.location.href = path;
      } else {
        that.$router.push(path);
      }
    },
    // get nav path
    getNavPath() {
      let that = this;
      let para = {
        project: that.projectName,
        path: that.$route.path.split('/')[1]
      };

      postRequest('/api-auth/get-current-memu-data', para)
        .then(res => {
          // console.log(res,res.data,res.data.errorCode)
          var resData = res.data;
          if (resData.errorCode == 0) {
            if (!resData.result) {
              return false;
            }

            that.navpath = [];
            if (!!resData.result.list && !!resData.result.list.length) {
              resData.result.list.forEach(function(ele, index) {
                ele.name = ele.menuName;
                ele.path = '';
                if (index == resData.result.list.length - 1) {
                  ele.path = '/' + ele.menuUrl;
                }

                if (index > 0) {
                  that.navpath.push(ele);
                }
              });

              // that.navpath = resData.result.list
            }

            // that.navpath[0].name = resData.result.level2.menuName;
            // that.navpath[0].path = ''

            // that.navpath[1].name = resData.result.level3.menuName;
            // that.navpath[1].path = ''
            // if (!!resData.result.level4) {
            //   that.navpath[2] = {
            //     name:'',
            //     path: ''
            //   }
            //   that.navpath[2].name = resData.result.level4.menuName;
            //   that.navpath[2].path = ''
            // }

            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          // that.toLogin()
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  /* eslint-disable */
  mounted() {
    // var that = this;
    // that.getNavPath();
  }
};
</script>

<style scoped>
.navwrap {
  padding: 20px 24px;
  /*margin-top: 20px;*/
  background-color: #fff;
  border-radius: 2px;
}
.boxbttom {
  border-bottom: 1px solid #e4e7ed;
}
.boxshow {
  border-bottom: 1px solid #e4e7ed;
  box-shadow: 5px -1px 5px #dfdfdf;
}
.navtitle {
  margin: 24px 0 0 0;
  font-size: 20px;
  color: #303133;
  font-weight: 500;
}
.navtip {
  width: 100%;
  height: 38px;
  line-height: 38px;
  font-size: 13px;
  border-radius: 2px;
  color: #606266;
  background-color: #f4f4f5;
}
.navmTop {
  margin-top: 25px;
}
.navtipcolor {
  margin: 0 12px;
  color: #1890ff;
}

.el-breadcrumb__item:last-child .el-breadcrumb__inner,
.el-breadcrumb__item:last-child .el-breadcrumb__inner a,
.el-breadcrumb__item:last-child .el-breadcrumb__inner a:hover,
.el-breadcrumb__item:last-child .el-breadcrumb__inner:hover {
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  color: #303133;
}
</style>
