<script>
export default {
  data() {
    return {
    };
  },
  props:{
    value: {
      type: Number,
      default: 0,
    },
  },
  computed: {
    activeIndex: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("update:value", val);
      },
    },
  },
  methods: {
    setActive(index) {
      this.activeIndex = index;
    },
  },
};
</script>

<template>
  <view class="menu-container">
    <view
      class="menu-item"
      :class="{ active: activeIndex === 0,left: activeIndex === 0 }"
      @click="setActive(0)"
    >
      承诺列表
    </view>
    <view
      class="menu-item"
      :class="{ active: activeIndex === 1,right: activeIndex === 1 }"
      @click="setActive(1)"
    >
      企业列表
    </view>
  </view>
</template>

<style lang='scss' scoped>
.menu-container {
  display: flex;
  overflow: hidden;
  transition: all 0.3s ease;
  background-color: #e0f7ff;
  width: 100%;
  border-radius: 14px 14px 0 0;
}
.menu-item {
  flex: 1;
  text-align: center;
  line-height: 43px;
  cursor: pointer;
}
.active {
  background-image: url("@/static/images/commitment/bg2.png");
  background-repeat: no-repeat;
  background-size: 100%;
  color: #1492ff;
  position: relative;
}
 .left {
    background-position: -3px center; /* 向左偏移10像素 */
  }
  .right {
    background-position: 3px center; 
  }
.active::after {
  content: "";
  display: block;
  width: 9%;
  height: 3px;
  background-color: #1492ff;
  position: absolute;
  bottom: 5px;
  left: 45%;
  border-radius: 5px;
  transition: all 0.3s ease;
}
</style>