<template>
  <div class="select-area">
    <div class="select-box flex-up-down" @click="showCombo = !showCombo">
      {{ showString }}
      <i class="el-icon-caret-bottom ml-auto" />
    </div>
    <div class="combo-box-area">
      <div v-show="showCombo" class="combo-box mt-21">
        <label>
          <input class="combo-input mt-10 ml-10 hide-border" :placeholder="placeholder" />
        </label>
        <div
          v-for="item in selectList"
          :key="item.id"
          class="combo-item flex-up-down pointer"
          @click="$emit('select', item)"
        >
          {{ item.label }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Index',
  props: {
    // 默认的选择框
    defaultSelectExist: {
      type: Boolean,
      default: true
    },
    showString: {
      type: String,
      default: '展示数据'
    },
    placeholder: {
      type: String,
      default: 'Search'
    },
    bindData: {
      type: Object,
      default: () => ({}),
      require: true
    }
  },
  data() {
    return {
      showCombo: false,
      selectList: [
        {
          id: 1,
          label: '选项1'
        },
        {
          id: 2,
          label: '选项2'
        }
      ]
    }
  }
}
</script>

<style lang="scss" scoped>

.select-area{
  --width: 251px;

  position: relative;

  .combo-box-area{
    position: absolute;
    top: 15px;
    left: 0;
  }

  .select-box {
    display: flex;
    align-items: center;
    padding: 0 12px;
    width: var(--width);
    height: 28px;
    border: 1px solid #ddd;
    border-radius: 5px;
  }
  .combo-box {
    position: relative;
    width: var(--width);
    background-color: #fff;
    box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2);
    z-index: 1;

    @mixin triangle {
      content: '';
      position: absolute;
      background-color: #fff;
      z-index: -1;
    }

    &::before {
      @include triangle;
      top: -1px;
      left: 30px;
      width: 20px;
      height: 20px;
      box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2);
      transform: rotate(45deg);
    }

    &::after {
      @include triangle;
      top: 0;
      left: 0;
      width: 80px;
      height: 40px;
    }

    .combo-input {
      padding: 0 11px;
      width: calc( var(--width) - 20px );
      height: 36px;
      border-radius: 5px;
      background-color: #f4f4f4;
    }

    .combo-item {
      margin: 0 auto;
      padding-left: 10px;
      width: 226px;
      height: 39px;
      border-bottom: 1px solid #f2f2f2;

      &:last-child {
        border-bottom: none;
      }

    }
  }

}
</style>
