<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-10 14:44:45
 * @LastEditors  : 无尘
 * @LastEditTime : 2020-03-02 17:10:47
 -->
<template>
  <div class="navwrap border-box flex flex-space-between">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <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>
    <div class="my-customer-brand">
      <el-tooltip class="item" effect="dark" content="不同品牌的工作台可分别进行管理。点击后切换，可以管理不同品牌下的应用" placement="top-start">
        <span class="font-14 color-606266" style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">授权商户名称 </span>
      </el-tooltip>
      <el-select class="p-l-10" v-model="activeBrand" placeholder="请选择" @change="changeSelect">
        <el-option v-for="item in brandListData" :key="item.enterpriseId" :label="item.enterpriseName" :value="item.enterpriseId"> </el-option>
      </el-select>
    </div>
  </div>
</template>

<script>
import { postRequest } from '@/api/api';
import errMsg from '@/common/js/error';
export default {
  name: 'navpath',
  data() {
    return {
      projectName: 'haoban', // 当前项目名
      activeBrand: '',
      brandListData: []
    };
  },
  props: {
    navpath: {
      type: Array,
      default: function() {
        return [];
      }
    },
    slotFlag: {
      type: Boolean,
      default: false
    },
    navtip: {
      type: Boolean,
      default: false
    },
    subNavText: {
      type: String,
      default: ''
    }
  },
  watch: {
    brandId: function(newData, oldData) {
      const that = this;
      that.getBrandData();
    }
  },
  methods: {
    changeRoute(path, relocation) {
      let that = this;
      if (relocation) {
        window.location.href = path;
      } else {
        that.$router.push(path);
      }
    },
    /**
     * 选择品牌
     */
    changeSelect(val) {
      let that = this;
      let enterpriseId = '';
      that.brandListData.forEach(ele => {
        if (ele.enterpriseId == val) {
          enterpriseId = ele.enterpriseId;
        }
      });
      that.$emit('selectBrandId', val, enterpriseId);
    },

    /**
     * 获取品牌
     */
    getBrandData() {
      const that = this;
      postRequest('/haoban-manage3-web/wx-enterprise-list', {})
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result && !!resData.result.length) {
              that.brandListData = resData.result;
              if (!!that.$route.query.enterpriseId) {
                that.activeBrand = that.$route.query.enterpriseId;
                that.$emit('selectBrandId', that.$route.query.enterpriseId);
                return false;
              }
              that.activeBrand = that.brandListData[0].enterpriseId;
              // 由于门店选择组件中没有品牌id ,只有 groupId
              that.$emit('selectBrandId', that.brandListData[0].enterpriseId, that.brandListData[0].enterpriseId);
            }
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  mounted() {
    const that = this;
    that.getBrandData();
  }
};
</script>

<style type="text/less" lang="less" scoped>
.navwrap {
  height: 48px;
  line-height: 48px;
  padding: 0 20px;
  box-sizing: border-box;
  .el-breadcrumb {
    line-height: 48px;
  }
}
.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>
