<template>
  <div class="top-bar">
    <!-- 左侧地区下拉选择框 -->
    <div class="dropdown-container">
      <div class="selected" @click="toggleDropdown">
        {{ selectedArea || '地区' }}
        <span class="arrow" :class="{ rotated: isDropdownOpen }">&#9660;</span>
      </div>
      
      <transition name="fade">
        <div v-if="isDropdownOpen" class="options">
          <div
            v-for="area in areas"
            :key="area.value"
            @click="selectArea(area)"
          >
            {{ area.label }}
          </div>
        </div>
      </transition>
    </div>

    <!-- 中间地区搜索栏 -->
    <div class="search-container">
      <van-search
        v-model="searchKeyword"
        clearable
        :show-action="showAction"
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @cancel="onCancel"
        @focus="onFocus"
        @clear="clearSearch"
      />
    </div>


    <van-popover v-model:show="showPopover" theme="dark" :actions="actions">
  <template #reference>
 <!-- 右侧+图标栏 -->
    <div class="add-icon" @click="showAddPopup">
      <span>&#43;</span>
    </div>
  </template>
</van-popover> 

  </div>

</template>

<script>
import {ref} from 'vue';

export default {
  setup() {
    const showPopover = ref(false);
    const actions = [
      { text: '扫一扫' },
      { text: '版本切换' },
    ];

    return {
      actions,
      showPopover,
    };
  },
  data() {
    return {
      isDropdownOpen: false,
      selectedArea: null,
      areas: [
        { label: '杭州市', value: 'area1' },
        { label: '武汉市', value: 'area2' },
        { label: '岳阳市', value: 'area3' },
        // 可以根据需要添加更多地区选项
      ],
      searchKeyword: '',
    };
  },
  methods: {
    toggleDropdown() {
      this.isDropdownOpen = !this.isDropdownOpen;
    },
    selectArea(area) {
      this.selectedArea = area.label;
      this.isDropdownOpen = false;
    },
    showAddPopup() {
      // 处理+图标点击事件
    },
  },
};
</script>

<style scoped>
.top-bar {
  display: flex;
  justify-content: space-between;
  padding: 16px;
  font-size: 30px;
  background-color: #f7f7f7;
}

.dropdown-container {
  position: relative;
  width: 150px;
  height: 100px;
  background-color: #f1f3f5;
}

.selected {
  padding: 10px;
  border: 0px solid #ccc;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 85px;
  background-color: #f0f3f6;
}

.arrow {
  margin-left: 8px;
}

.rotated {
  transform: rotate(180deg);
}

.options {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background-color: #a85959;
  border: 1px solid #ccc;
  border-top: none;
  z-index: 1;
}

.options div {
  padding: 10px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.options div:hover {
  background-color: #f5f5f5;
}

.search-container {
  flex: 1;
  margin: 0 16px;
}

.search-container input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
}

.add-icon {
  padding: 10px;
  background-color: #007bff;
  color: #fff;
  cursor: pointer;
}
</style>
