<template>
  <div
    class="en-card-big"
    :class="{'disabled':disabled && disabled !== 'false'}"
    :style="{
      'width': width ? width : '600px',
      'height': height ? height : '110px'
    }"
    @mouseleave.stop="toggleMenu(false)"
  >
    <!-- 标签插槽 -->
    <div class="en-card-big-tag">
      <slot name="tag"></slot>
    </div>
    <!-- 无图标插槽时的图标区域 -->
    <div
      class="en-card-big-icon"
      :style="{
        'color': iconColor,
        'background-color':iconBg
      }"
      v-if="!withIcon && iconName && iconName !== ''"
    >
      <en-icon :name="iconName"></en-icon>
    </div>
    <!-- 图标插槽 -->
    <div class="en-card-big-icon" v-if="withIcon">
      <slot name="icon"></slot>
    </div>
    <!-- 无内容、右侧 插槽时的主内容区 -->
    <div
      class="en-card-big-main"
      v-if="!withContent && !withRight"
    >
      <!-- 带提示的标题 -->
      <el-tooltip :content="title" v-if="showTips">
        <div class="en-card-big-main-title">
          {{ title }}
        </div>
      </el-tooltip>
      <!-- 带提示的副标题 -->
      <el-tooltip :content="subTitle" v-if="showTips">
        <div class="en-card-big-main-sub-title">
          {{ subTitle}}
        </div>
      </el-tooltip>
      <!-- 带提示的描述 -->
      <el-tooltip :content="description" v-if="showTips && !withDescription">
        <div class="en-card-big-main-description">
          {{ description }}
        </div>
      </el-tooltip>
      <!-- 不带提示的标题 -->
      <div class="en-card-big-main-title" v-if="!showTips">
        {{ title }}
      </div>
      <!-- 不带提示的副标题 -->
      <div class="en-card-big-main-sub-title" v-if="!showTips">
        {{ subTitle}}
      </div>
      <!-- 不带提示的描述且无描述区域插槽 -->
      <div
        class="en-card-big-main-description"
        v-if="!withDescription && !showTips"
      >
        {{ description }}
      </div>
      <!-- 描述区域插槽 -->
      <div class="en-card-big-main-description" v-if="withDescription">
        <slot name="description"></slot>
      </div>
    </div>
    <!-- 内容区域插槽 -->
    <div class="en-card-big-main" v-if="withContent">
      <slot name="content"></slot>
    </div>
    <!-- 右侧整体插槽 -->
    <div class="en-card-big-main" v-if="withRight">
      <slot name="right"></slot>
    </div>
    <!-- 下拉菜单区域 -->
    <div class="en-card-big-menu" v-if="editAble && editAble !== 'false'">
      <en-icon
        name="bianji1"
        class="en-card-big-menu-icon"
        @mouseover.native.stop="toggleMenu(true)"
      >
      </en-icon>
      <div class="en-card-big-menu-container">
        <en-collapse-area>
          <div
            class="en-card-big-menu-list"
            v-show="showMenu"
          >
            <!-- 无菜单插槽时的下拉菜单 -->
            <div
              class="en-card-big-menu-item"
              v-for="item in menuList"
              :key="item[menuKey]"
              @click.stop="selectMenu(item)"
            >
              {{ item[menuLabel] }}
            </div>
            <!-- 菜单插槽 -->
            <slot name="menu" v-if="withMenu"></slot>
          </div>
        </en-collapse-area>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "big",
  props: {
    // 图标名称
    iconName: {
      type: String,
      default: ""
    },
    // 图标颜色
    iconColor: {
      type: String,
      default: ""
    },
    // 图标底色
    iconBg: {
      type: String,
      default: ""
    },
    // 卡片宽度
    width: {
      type: [String, Number],
      default: "600px"
    },
    // 卡片高度
    height: {
      type: [String, Number],
      default: "110px"
    },
    // 卡片标题
    title: {
      type: String,
      default: ""
    },
    // 卡片副标题
    subTitle: {
      type: String,
      default: ""
    },
    // 卡片描述
    description: {
      type: String,
      default: ""
    },
    // 是否需要显示提示信息
    showTips: {
      type: [Boolean, String],
      default: true
    },
    // 卡片类型=>目前只提供 常用尺寸、大尺寸两种尺寸
    type: {
      type: String,
      default: "big",
      validator: (val) => {
        return ["big", "big"].indexOf(val) > -1;
      }
    },
    // 是否禁用
    disabled: {
      type: [Boolean, String],
      default: false
    },
    // 卡片数据源信息
    dataInfo: {
      type: Object,
      default: () => {
        return {};
      }
    },
    // 是否可编辑=>与menuList搭配使用
    editAble: {
      type: [String, Boolean],
      default: false
    },
    // 下拉菜单数组
    menuList: {
      type: Array,
      default: () => {
        return [];
      }
    },
    // 下拉菜单显示文本字段
    menuLabel: {
      type: String,
      default: "name"
    },
    // 下拉菜单唯一标识字段
    menuKey: {
      type: String,
      default: "id"
    }
  },
  data() {
    return {
      showMenu: false
    };
  },
  computed: {
    // 检测是否有内容区插槽
    withContent() {
      return this.$slots.content;
    },
    // 检测是否有图标插槽
    withIcon() {
      return this.$slots.icon;
    },
    // 检测是否有菜单插槽
    withMenu() {
      return this.$slots.menu;
    },
    // 检测是否有右侧整体插槽
    withRight() {
      return this.$slots.right;
    },
    // 检测描述区域是否有插槽
    withDescription() {
      return this.$slots.description;
    }
  },
  methods: {
    /**
     * @description 切换菜单显示状态
     * @param status Boolean
     */
    toggleMenu(status) {
      this.showMenu = status;
    },
    /**
     * @description 选中某一菜单后，触发回调并隐藏下拉菜单
     * @param menu
     */
    selectMenu(menu) {
      this.showMenu = false;
      this.$emit("change", menu, this.dataInfo);
    }
  }
};
</script>

<style lang="scss" scoped>
  .en-card-big {
    border-radius: 4px 4px 4px;
    border: 1px solid #E8ECF2;
    padding: 20px 20px 20px;
    transition: .3s ease-in-out all;
    display: flex;
    justify-content: flex-start;
    position: relative;
    cursor: pointer;
    // 标签区域样式
    .en-card-big-tag {
      position: absolute;
      top: 0;
      left: 0;
    }

    // 图标区域样式处理
    .en-card-big-icon {
      width: 70px;
      height: 70px;
      background-color: #F5F9FD;
      border-radius: 4px 4px 4px;
      padding: 22px 22px 22px;
      margin-right: 20px;
      color: #4694df;
      transition: 0.3s ease-in-out background-color;

      .en-icon {
        width: 26px;
        height: 26px;
      }
    }

    // 主体区域样式处理
    .en-card-big-main {
      width: calc(100% - 90px);

      .en-card-big-main-title {
        margin-top: 5px;
        font-size: 14px;
        line-height: 14px;
        color: #333333;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .en-card-big-main-sub-title {
        margin-top: 10px;
        color: #636C78;
        font-size: 12px;
        line-height: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .en-card-big-main-description {
        font-size: 12px;
        line-height: 12px;
        color: #636c78;
        margin-top: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    // 菜单样式处理
    .en-card-big-menu {
      position: absolute;
      right: 20px;
      top: 20px;
      z-index: 2;

      .en-card-big-menu-icon {
        width: 16px;
        height: 16px;
        color: #4694df;
        display: none;
      }

      .en-card-big-menu-container {
        position: absolute;
        right: -20px;
        top: 16px;

        .en-card-big-menu-list {
          width: 120px;
          background-color: #ffffff;
          border: 1px solid #E8ECF2;
          box-shadow: 0 5px 5px 0 rgba(236, 236, 236, 0.75);
          border-radius: 4px;
          margin-top: 17px;

          .en-card-big-menu-item {
            color: #636C78;
            cursor: pointer;
            line-height: 32px;
            font-size: 12px;
            padding-left: 13px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            &:hover {
              background-color: #4694df;
              color: #ffffff;
            }
          }
        }
      }
    }

    // 禁用状态下的样式处理
    &.disabled {
      background-color: #FBFBFB;

      .en-card-big-icon {
        opacity: .5;
      }

      .en-card-big-main {
        .en-card-big-main-title {
          color: rgba(51, 51, 51, 0.5);
        }

        .en-card-big-main-sub-title {
          color: rgba(99, 108, 120, 0.5);
        }

        .en-card-big-main-description {
          color: rgba(99, 108, 120, 0.5)
        }
      }
    }

    // 鼠标悬浮状态下的样式处理
    &:hover {
      box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1);
      background-color: #F5F9FD;

      .en-card-big-icon {
        background-color: #EAF2F9;
      }

      .en-card-big-menu-icon {
        display: block;
      }
    }
  }
</style>
