<template>
  <div class="block_radius">
    <div class="right_cont">
      <div v-if="show_header" class="block_header">
        <div class="icon_box">
          <bg-icon style="font-size: 14px; color: #fff" :icon="bgIcon"></bg-icon>
        </div>
        <div class="top_title">{{ title }}</div>
        <div v-if="selectArr.length > 0">
          <el-select @change="selectChange" v-model="currentSelectValue" placeholder="请选择">
            <el-option v-for="item in selectArr" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </div>
        <div v-if="buttons_arr" class="block_header_button_group">
          <div
            v-for="(item, index) in buttons_arr"
            :key="index"
            class="block_header_button"
            :class="active_button == index ? 'active' : ''"
            @click="changeButton(index)">
            {{ item }}
          </div>
        </div>
      </div>
      <div class="block_main" :class="noPadding ? 'no_padding' : ''">
        <slot name="main" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, toRefs, onBeforeMount } from "vue";

const props = defineProps({
  show_header: {
    type: Boolean,
    default: false,
  },
  selectValue: {
    type: [String, Number],
    default: "",
  },
  selectArr: {
    type: Array,
    default: () => {
      return [];
    },
  },
  buttons_arr: {
    type: Array,
    default: () => {
      return [];
    },
  },
  bgIcon: {
    type: String,
    default: "",
  },
  title: {
    type: String,
    default: "",
  },
  background_color: {
    type: String,
    default: "#fff",
  }, // header条背景色
  showLeft: {
    type: Boolean,
    default: true,
  },
  noPadding: {
    type: Boolean,
    default: false,
  },
});

const emit = defineEmits(["selectChange", "changeButton"]);
const state = reactive({
  currentSelectValue: null,
  active_button: 0,
});

const selectChange = (val) => {
  state.currentSelectValue = val;
  emit("selectChange", val);
};
const changeButton = (index) => {
  if (state.active_button != index) {
    state.active_button = index;
    emit("changeButton", index);
  }
};
onBeforeMount(() => {
  state.currentSelectValue = props.selectValue;
});

const { currentSelectValue, active_button } = toRefs(state);
</script>

<style scoped>
.block_header {
  display: flex;
  justify-content: space-between;
  padding: 16px;
  height: 52px;
  border-bottom: 1px solid #000;
}
.block_header_button_group {
  background-color: #f4f7fc;
  border-radius: 4px;
}
.block_header_button {
  display: inline-block;
  font-size: 12px;
  padding: 2px 6px;
  color: #8890a7;
  cursor: pointer;
}
.block_header_button.active {
  color: #f8f9fd;
  background-color: #3f4f9c;
  border-radius: 4px;
}
</style>

<style lang="scss" scoped>
.block_radius {
  width: 100%;
  margin-bottom: 20px;
  display: flex;
  border-radius: 6px;
  .right_cont {
    flex: 1;
    border-radius: 6px;
    background-color: #fff;
    .icon_box {
      width: 20px;
      height: 20px;
      border-radius: 4px;
      background-color: #2a4aa7;
      display: flex;
      align-items: center;
      justify-content: space-around;
    }
    .top_title {
      // width: 100%;
      flex: 1;
      // height: 36px;
      // line-height: 36px;
      font-weight: 700;
      padding: 0 8px;
      box-sizing: border-box;
    }
    .block_main {
      padding: 16px;
    }
    .no_padding {
      padding: 0;
    }
  }
}
</style>
