<template>
  <u-popup :show="show" mode="left" :closeable="true" @close="handleClose">
    <view class="c-dialog-filter">
      <view class="title">供应商筛选</view>
      <view class="search">
        <u-search placeholder=" 请输入供应商名称 / 卡号搜索" v-model="keyword"></u-search>
      </view>
      <view class="dialog-product-layout">
        <!-- 自定义索引列表 -->
        <view class="address-book-container">
          <!-- 左侧通讯录 -->
          <scroll-view
            class="scroll-container"
            :scroll-y="true"
            :scroll-into-view="toView"
            :scroll-with-animation="true"
          >
            <view
              class="address-book"
              v-for="(item, index) in addressBook"
              :key="index"
              :id="item.id"
            >
              <view class="address-book-index">{{ item.id }}</view>
              <view
                class="contact-container"
                v-for="(cItem, index) in item.data"
                :key="index"
              >
                <!-- <img
                  class="contact-img"
                  src="http://www.lixia.gov.cn/picture/0/s_97b76c734a6f40f8abba95615cbff1e1.jpg"
                  alt=""
                /> -->
                <view class="contact-detail-container">
                  <view class="contact-name">{{ cItem.zh_title }}</view>
                  <view class="contact-address">{{ cItem.address }}</view>
                  <!-- <view class="contact-phone">{{ item.phone }}</view> -->
                </view>
              </view>
            </view>
          </scroll-view>

          <!-- 右侧字母导航条 -->
          <view class="letter-nav">
            <view
              class="item"
              :class="{ active: toView === item }"
              v-for="(item, index) in indexList"
              :key="index"
              @click="toSelectIndex(item)"
              >{{ item }}</view
            >
          </view>
        </view>
      </view>
    </view>
  </u-popup>
</template>
<script setup lang="ts">
const props = defineProps<{
  show: boolean;
}>();
const emit = defineEmits(["handleDialog"]);
const handleClose = () => {
  emit("handleDialog", false);
};

const keyword = ref()

const indexList = [
  "A",
  "B",
  "C",
  "D",
  "E",
  "F",
  "G",
  "H",
  "I",
  "J",
  "K",
  "L",
  "M",
  "N",
  "O",
  "P",
  "Q",
  "R",
  "S",
  "T",
  "U",
  "V",
  "W",
  "X",
  "Y",
  "Z",
];
const toView = ref("");
const addressBook = [
  {
    id: "A",
    data: [
      {
        zh_title: "阿联酋迪拉姆",
        en_title: "aa",
        address: "910289591",
        phone: "111111",
      },
      {
        zh_title: "阿尔巴尼亚列克",
        en_title: "aaaaa",
        address: "ALL",
        phone: "222222",
      },
    ],
  },
  {
    id: "B",
    data: [
      {
        zh_title: "孟加拉国塔卡",
        en_title: "bbb",
        address: "BDT",
        phone: "111111",
      },
      {
        zh_title: "保加利亚列瓦",
        en_title: "bbb",
        address: "BGN",
        phone: "222222",
      },
    ],
  },
  {
    id: "C",
    data: [
      {
        zh_title: "加拿大元",
        en_title: "ccc",
        address: "CAD",
        phone: "111111",
      },
      {
        zh_title: "瑞士法郎",
        en_title: "ccc",
        address: "CHF",
        phone: "222222",
      },
    ],
  },
  {
    id: "D",
    data: [
      {
        zh_title: "丹麦克朗",
        en_title: "ddd",
        address: "DKK",
        phone: "111111",
      },
      {
        zh_title: "多米尼加比索",
        en_title: "ddd",
        address: "DOP",
        phone: "222222",
      },
      {
        zh_title: "丹麦克朗",
        en_title: "ddd",
        address: "DKK",
        phone: "111111",
      },
      {
        zh_title: "多米尼加比索",
        en_title: "ddd",
        address: "DOP",
        phone: "222222",
      },
      {
        zh_title: "丹麦克朗",
        en_title: "ddd",
        address: "DKK",
        phone: "111111",
      },
      {
        zh_title: "多米尼加比索",
        en_title: "ddd",
        address: "DOP",
        phone: "222222",
      },
    ],
  },
  {
    id: "Z",
    data: [
      { zh_title: "z", en_title: "zz", address: "zzz", phone: "111111" },
      { zh_title: "zzz", en_title: "ddd", address: "ddd", phone: "222222" },
    ],
  },
];

const toSelectIndex = (item: any) => {
  toView.value = item;
};
</script>
<style lang="scss" scoped>
.c-dialog-filter {
  width: 95vw;
  padding: 25rpx;
  .title {
    font-weight: 500;
    font-size: 32rpx;
    color: #000000;
    text-align: center;
  }
  .search {
    margin: 30rpx 0px;
  }
}
.dialog-product-layout {
  height: 80vh;
  .address-book-container {
    height: 100%;
  }
  .address-book-index {
    font-size: 24rpx;
  }
  .contact-img {
    width: 20px;
    height: 20px;
  }
  .scroll-container {
    height: 100%;
  }
  .letter-nav {
    position: fixed;
    right: 25rpx;
    top: 100px;
    font-size: 22rpx;
    text-align: center;
    .item:hover,
    .active {
      color: $u-primary;
    }
  }
  .contact-container {
    display: flex;
    align-items: center;
    margin: 2%;
  }
  .contact-detail-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 80%;
    font-size: 22rpx;
    .contact-address {
      color: rgba(0,0,0,0.65);
    }
  }
}
</style>
