
<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      text-color="#333333"
      active-text-color="#FFFFFF"
      unique-opened
      @select="select"
    >
      <!--  background-color="#324157"
      text-color="#333333"
      active-text-color="#46B791"-->
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <!-- <i :class="item.icon"></i> -->
              <img
                :src="item.icon2"
                alt=""
                v-if="item.icon2 && onRoutes == item.index"
              />
              <img :src="item.icon" alt="" v-else />
              <span slot="title">{{ item.title }}</span>
            </template>

            <template v-for="subItem in item.subs">
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                  >{{ threeItem.title }}</el-menu-item
                >
              </el-submenu>

              <el-menu-item v-else
              :index="subItem.index" :key="subItem.index">
                <span>{{ subItem.title }}</span>
                <el-tooltip v-if="item.showBadge && orderTip.confirmed && subItem.title=='待确认'"
                class="item " effect="light" placement="right-end" >
                  <div slot="content">超过3天未处理的订单数量统计</div>
                  <el-badge v-if="subItem.showBadge " style="top:-10px;"
                :value="orderTip.confirmed"></el-badge>
                </el-tooltip>
                <el-tooltip v-if="item.showBadge && orderTip.receiving && subItem.title=='待发货'"
                class="item " effect="light" placement="right-end" >
                  <div slot="content">超过3天未处理的订单数量统计</div>
                  <el-badge v-if="subItem.showBadge " style="top:-10px;"
                :value="orderTip.receiving"></el-badge>
                </el-tooltip>

              </el-menu-item>
            </template>
          </el-submenu>
        </template>

        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <!-- <i :class="item.icon"></i> -->
            <img
              :src="item.icon2"
              alt=""
              v-if="item.icon2 && onRoutes == item.index"
            />
            <img :src="item.icon" alt="" v-else />
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import { _deepClone, _deal, _getStorage } from "@/utils/utils";
export default {
  name: "Aside",
  data() {
    return {
      itemsData: {
        items_0: [
          {
            icon: "iconfont iconquanbudingdan",
            index: "/home",
            title: "首页",
          },
        ],
        items_1: [
          {
            icon: require("@/assets/img/icons/dailishang.png"),
            index: "/order/orderlist",
            title: "E淘市级代理",
            showBadge: true,
            subs: [
              {
                icon: "iconfont icondaifukuan1",
                index: "/order/orderlist",
                title: "全部订单",
              },
              {
                icon: "iconfont icondaifukuan1",
                index: "/order/orderlist/0",
                title: "待付款",
              },
              {
                icon: "iconfont icondaiqueren",
                index: "/order/orderlist/1",
                title: "待确认",
                showBadge: true,
              },
              {
                icon: "iconfont icondaifahuo1",
                index: "/order/orderlist/2",
                title: "待发货",
                showBadge: true,
              },
              {
                icon: "iconfont iconyifahuo1",
                index: "/order/orderlist/3",
                title: "已发货",
              },
              {
                icon: "iconfont icondingdan-yichenggong",
                index: "/order/orderlist/4",
                title: "已成功",
              },
              {
                icon: "iconfont icondingdan-yichenggong",
                index: "/order/orderlist/5",
                title: "已关闭",
              },
              {
                icon: "iconfont iconjiaoyiguanbi",
                index: "/order/orderlist/6",
                title: "退款中",
              },
              // {
              //   icon: "iconfont iconjiaoyiguanbi",
              //   index: "/order/saomafu",
              //   title: "扫码付订单",
              // },
            ],
          },
          {
            icon: require("@/assets/img/icons/order.png"),
            index: "/aftersale/indexsale",
            title: "订单服务",
            showBadge: true,
            subs: [
              // {
              //   icon: "iconfont icondaifukuan1",
              //   index: "/aftersale/index",
              //   title: "售后/投诉工单",
              // },
              {
                icon: "iconfont icondaifukuan1",
                index: "/aftersale/indexsale",
                title: "售后工单",
              },

            ],
          },
          // {
          //   icon: require("@/assets/img/icons/dianpu.png"),
          //   index: "/order/orderlistbrand",
          //   title: "E淘品牌共享中心",
          //   subs: [
          //     {
          //       icon: "iconfont iconshangpinguanli",
          //       index: "/order/orderlistbrand",
          //       title: "全部订单",
          //     },
          //     {
          //       icon: "iconfont icondaiqueren",
          //       index: "/order/orderlistbrand/0",
          //       title: "待确认",
          //     },
          //     {
          //       icon: "iconfont icondaifahuo1",
          //       index: "/order/orderlistbrand/1",
          //       title: "待发货",
          //     },
          //     {
          //       icon: "iconfont iconyifahuo1",
          //       index: "/order/orderlistbrand/2",
          //       title: "已发货",
          //     },
          //     {
          //       icon: "iconfont icondingdan-yichenggong",
          //       index: "/order/orderlistbrand/3",
          //       title: "交易成功",
          //     },
          //     {
          //       icon: "iconfont icondingdan-yichenggong",
          //       index: "/order/orderlistbrand/4",
          //       title: "订单关闭",
          //     },
          //     {
          //       icon: "iconfont icondingdan-yichenggong",
          //       index: "/order/orderlistashop",
          //       title: "A店签约单",
          //     },
          //   ],
          // },
          // {
          // icon: require('@/assets/img/icons/yushou.png'),
          // index: "/ordernew/classify",
          // title: "新品预售",
          // subs: [
          //     {
          //     icon: "iconfont iconshangpinguanli",
          //     index: "/ordernew/classify",
          //     title: "全部订单"
          //     },
          // ]
          // },

        ],
        items_2: [
          {
            icon: require("@/assets/img/icons/shangpin.png"),
            index: "/goods/warnstock",
            title: "商品管理",
            subs: [
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/goods/listold",
              //     title: "旧数据迁移仓库"
              // },
              {
                  icon: "iconfont iconxiaoshou-",
                  index: "/goods/list",
                  title: "商品仓库"
              },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/goods/warnstock",
                title: "库存管理",
              }
            ]
          },
          // {
          //   icon: require("@/assets/img/icons/zqu.png"),
          //   index: "/goods/limit",
          //   title: "专区管理",
          //   subs: [
          //     {
          //       icon: "iconfont iconxiaoshou-",
          //       index: "/goods/limit",
          //       title: "限量专区",
          //     }
          //   ]
          // },
          // {
          //   icon: require("@/assets/img/icons/zqu.png"),
          //   index: "/goods/seckill",
          //   title: "专区管理",
          //   subs: [
          //     // {
          //     //   icon: "iconfont iconxiaoshou-",
          //     //   index: "/goods/seckill",
          //     //   title: "秒杀专区",
          //     // },
          //     {
          //       icon: "iconfont iconxiaoshou-",
          //       index: "/goods/xinPin",
          //       title: "新品专区",
          //     },
          //     // {
          //     //   icon: "iconfont iconxiaoshou-",
          //     //   index: "/goods/limit",
          //     //   title: "限量专区",
          //     // }
          //   ]
          // },
        ],
        // items_3: [
        //   {
        //     icon: "iconfont iconkefu",
        //     index: "",
        //     title: "活动管理",
        //   },
        // ],
        items_3: [
          {
            icon: require("@/assets/img/icons/dianpuguanli.png"),
            index: "/marketing/shoprenovation",
            title: "店铺管理",
            subs: [
              {
                icon: "iconfont iconxiaoshou-",
                index: "/marketing/shoprenovation",
                title: "店铺装修",
              },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/marketing/brandintroduce",
                title: "品牌介绍",
              }
            ],
          },
          // {
          //   icon: require("@/assets/img/icons/tuiguanggongju.png"),
          //   index: "/marketing/coupon",
          //   title: "推广工具",
          //   subs: [
          //     // {
          //     //   icon: "iconfont iconxiaoshou-",
          //     //   index: "/marketing/coupon",
          //     //   title: "优惠券",
          //     // },
          //     {
          //       icon: "iconfont iconxiaoshou-",
          //       index: "/marketing/pay",
          //       title: "EDS扫码付",
          //     },
          //   ],
          // },
          // {
          //   icon: require("@/assets/img/icons/guanggao.png"),
          //   index: "/marketing/advert",
          //   title: "广告服务",
          //   subs: [
          //     {
          //       icon: "iconfont iconxiaoshou-",
          //       index: "/marketing/advert",
          //       title: "广告管理",
          //     },
          //   ],
          // },
          {
            icon: require("@/assets/img/icons/xinxiguanli.png"),
            index: "/marketing/message",
            title: "信息管理",
            subs: [
              // {
              //   icon: "iconfont iconxiaoshou-",
              //   index: "/marketing/message",
              //   title: "消息通知",
              // },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/marketing/service",
                title: "店铺客服",
              },
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/marketing/stock",
              //     title: "库存预警"
              // },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/marketing/holiday",
                title: "放假通知",
              },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/marketing/msn",
                title: "订阅服务",
              },
            ],
          },
          // {
          //   icon: require("@/assets/img/icons/gongjuxiazai.png"),
          //   icon2: require("@/assets/img/icons/gongjuxiazai2.png"),
          //   index: "/marketing/soft",
          //   title: "工具下载",
          // },

          // 暂时属于-运营中心
          // {
          //   icon: require("@/assets/img/icons/xiaoshoupaiming.png"),
          //   icon2: require("@/assets/img/icons/xiaoshoupaiming2.png"),
          //   index: "/marketing/report",
          //   title: "运营数据",
          // },
          {
            index: "/marketing/activity",
            title: "活动管理",
            subs: [
              {
                index: "/marketing/activityMall",
                title: "活动报名",
              },
              // {
              //   index: "/marketing/brandActivity",
              //   title: "品牌活动",
              // },
            ],
          },
          // {
          //   index: "/marketing/sales",
          //   title: "数据分析",
          //   subs: [
          //     {
          //       index: "/marketing/salesOverview",
          //       title: "售后总览",
          //     },
          //     {
          //       icon: require("@/assets/img/icons/xiaoshoupaiming.png"),
          //       icon2: require("@/assets/img/icons/xiaoshoupaiming2.png"),
          //       index: "/marketing/salerank",
          //       title: "销售排名",
          //     },
          //   ],
          // },
          // {
          //   icon: "iconfont iconmimaguanli",
          //   index: "/password",
          //   title: "密码管理"
          // },
          // {
          //   icon: "iconfont iconweixin",
          //   index: "/pay",
          //   title: "微信收款"
          // },
        ],
        items_4: [
          {
            icon: require("@/assets/img/icons/duizhang.png"),
            // match:['/noticeDetial'],
            index: "/checking/order",
            title: "财务对账",
            subs: [
              {
                icon: "iconfont iconxiaoshou-",
                index: "/checking/order",
                title: "订单流水",
              },
              // {
              //   icon: "iconfont iconxiaoshou-",
              //   index: "/checking/record",
              //   title: "提现记录",
              // },
            ],
          },

          // {
          //   icon: "iconfont iconnewsicon",
          //   match:['/noticeDetial'],
          //   index: "/notice",
          //   title: "消息通知",
          //   },
          // {
          //   icon: "iconfont iconnewsicon",
          //   index: "/platform",
          //   title: "平台通知"
          // },
        ],
        items_20: [
          {
            icon: require("@/assets/img/icons/bangzuzhongxin.png"),
            index: "/help/exshort",
            title: "帮助中心",
            subs: [
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/help/exvip",
              //     title: "E淘工厂权益升级"
              // },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/exshort",
                title: "桌面快捷方式说明",
              },
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/help/exproducts",
              //     title: "关于商品说明"
              // },
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/help/exsalearea",
              //     title: "可售区域说明"
              // },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/exprice",
                title: "价格说明",
              },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/exstock",
                title: "库存说明",
              },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/exdelivery",
                title: "交货期说明",
              },
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/help/exrecommend",
              //     title: "店铺装修说明"
              // },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/exvideo",
                title: "视频说明",
              },
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/productImg",
                title: "商品图片规范说明",
              },
              // {
              //     icon: "iconfont iconxiaoshou-",
              //     index: "/help/logouser",
              //     title: "E淘Logo使用规范"
              // },
            ],
          },
          {
            // icon: require('@/assets/img/icons/bangzuzhongxin.png'),
            index: "/help/feedback",
            title: "反馈管理",
            subs: [
              {
                icon: "iconfont iconxiaoshou-",
                index: "/help/feedback",
                title: "功能反馈",
              },
            ],
          },
        ],
      },
      items_2_copy: [
        {
          icon: require("@/assets/img/icons/shangpin.png"),
          index: "/goods/list",
          title: "商品管理",
          subs: [
            // {
            //     icon: "iconfont iconxiaoshou-",
            //     index: "/goods/listold",
            //     title: "旧数据迁移仓库"
            // },
            {
              icon: "iconfont iconxiaoshou-",
              index: "/goods/list",
              title: "商品仓库",
            },
            {
              icon: "iconfont iconxiaoshou-",
              index: "/goods/warnstock",
              title: "库存管理",
            },
          ],
        },
      ],
    };
  },

  mounted() {
    // 时间钩子
    this.getSupplierhelp();
    this.checkItems();
    this.getOrderTimeOutTip();
    let { etaoOpenBankStatus,isHome,isEtaoVip,isLamp} = _getStorage("info");
    // 如果是铂金会员才显示菜单

    //放开限制
    // if (etaoOpenBankStatus == 1) {
    //   this.itemsData.items_2 = this.items_2_copy;
    // }
    // E淘家居权限
    if (isHome == 1) {
      // this.itemsData.items_1.push({
      //       icon: require("@/assets/img/icons/self.png"),
      //       index: "/order/orderlistself",
      //       title: "自营订单管理",
      //       subs: [
      //         {
      //           icon: "iconfont iconshangpinguanli",
      //           index: "/order/orderlistself",
      //           title: "快捷订单",
      //         },
	//
      //       ],
      //     })
    }
    else{
      if(this.$route.path=='/order/orderlistself'){
        this.$router.push('/home');
      }
    }

  },
  computed: {
    ...mapState("navBar", ["collapse", "actNavItem", "orderTip"]),
    onRoutes() {
      if(this.$route.meta.actName){
        return this.$route.meta.actName;
      }else{
        return this.$route.path;
      }
    },
    items() {
      // console.log(this['items_' + this.actNavItem])
      return this.itemsData["items_" + this.actNavItem];
    },
  },
  watch: {
    $route(e) {
      // if(localStorage.getItem('actSw')==0){
      //   this.itemsData.items_3.splice(3, 1);
      // }
      this.checkItems();
    },
  },
  methods: {
    // 执行方法
    ...mapMutations("navBar", ["clickNavItem", "getOrderTimeOutTip"]),
    select(e) {
        this.$router.push(e);
    },
    getSupplierhelp(){
      this.$axios.get('/supplierhelp/list',{
        params:{
          pageNum:1,
          pageSize:100,
          type:0
        }
      })
      .then((res) => {
        if(res.data.code == 200){
          this.itemsData.items_20[0].index = '/supplierhelp/' + res.data.data.list[0].id;
          var arr=[];
          res.data.data.list.forEach(element => {
            var obj = {
              icon: element.icon,
              index: '/supplierhelp/' + element.id,
              title: element.title,
            }
            arr.push(obj)
          });
          this.itemsData.items_20[0].subs = arr;
        }
      })
      .catch((err) => {console.log(err)})
    },
    checkItems() {
      let url = this.$route.path;

      let itemsData = this.itemsData;
      let getIndex = (key) => {
        let num = parseInt(key.substring(key.indexOf("_") + 1, key.length));
        this.clickNavItem(num);
      };
      for (let key in itemsData) {
        for (let k in itemsData[key]) {
          if (itemsData[key][k]["index"].indexOf(url) != -1) {
            getIndex(key);
            break;
          } else {
            for (let i in itemsData[key][k]["match"]) {
              if (itemsData[key][k]["match"][i].indexOf(url) != -1) {
                getIndex(key);
                break;
              }
            }
          }
        }
      }
    },
  },
  components: {
    // 传入组件
  },
};
</script>

<style lang="scss" scoped>
@import "../assets/styles/_var";
.sidebar {
  display: block;
  background: #fff;
  color: #000;
  position: relative;
  // overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  //   width: 200px;
  width: map-get($width, asideWidth);
}
.sidebar > ul {
  height: 100%;
  width: 100%;
  font-size: 14px;
}
/deep/.sidebar .el-menu-item.is-active {
  color: #fff;
  background: #f60;
}
</style>
