<style scoped>
.back {
  background: #ffffff;
}
.wapper {
  max-width: 1200px;
  margin: 0 auto;
}
.main {
  width: 930px;
  height: 370px;
  background: #e0e0e0;
  border-radius: 8px;
  object-fit: cover;
}
.card-img-box {
  width: 260px;
  margin-left: 10px;
}
.card-img {
  width: 260px;
  height: 180px;
  background: #e0e0e0;
  border-radius: 8px;
  object-fit: cover;
}
.margin-bottom {
  margin-bottom: 10px;
}
.nav-item {
  width: 276px;
  height: 100px;
  background: #ffffff;
  border: 1px solid #eeeeee;
  border-radius: 8px;
}
.nav-item:hover {
  background: #ffffff;
  border: 1px solid #efefef;
}
.nav-img {
  width: 50px;
  height: 50px;
  margin: 10px auto 3px auto;
  display: block;
}
.top-title {
  margin-top: 30px;
  font-size: 26px;
  font-family: Microsoft JhengHei;
  font-weight: bold;
  color: #000000;
  line-height: 44px;
}
.info-icon {
  width: 32px;
  height: 32px;
  margin-right: 10px;
}
.time-item {
  width: 25%;
}
#baidu-map {
  width: 400px;
  height: 196px;
  background: #ffffff;
  border-radius: 8px;
}
.name {
  top: 20px;
  left: 20px;
  font-weight: bold;
  font-size: 30px;
  color: #fff;
}
</style>
<template>
  <div class="back">
    <div v-if="detail" class="wapper">
      <q-breadcrumbs gutter="none">
        <q-breadcrumbs-el label="Home" />
        <q-breadcrumbs-el label="Components" />
        <q-breadcrumbs-el label="Breadcrumbs" />
      </q-breadcrumbs>

      <div class="flex relative">
        <div class="absolute name">{{detail.AreaName}}</div>
        <img
          class="main"
          :src="detail.ImageList[0]"
        />
        <div class="card-img-box">
          <img
            class="card-img q-mb-xs"
            :src="detail.ImageList[1] || detail.ImageList[0]"
          />
          <img
            class="card-img"
            src="https://imgfile.oytour.com/Upload/DMC/202110131151571540000000139.jpeg"
          />
        </div>
      </div>

      <div class="flex justify-between q-mt-sm">
        <div v-for="item in navList" :key="item.img" class="nav-item">
          <img
            class="nav-img"
            :src="require(`../../assets/img/${item.img}.png`)"
          />
          <div class="f16 bold text-center">{{ item.title }}</div>
        </div>
      </div>
      <div class="top-title">TOP榜单</div>
      <div>本地销量最好的商品</div>
      <div class="mt" style="height: 500px; width: 1200px; overflow-x: auto;">
        <div style="width: auto">
        <topCard v-for="item in detail.TopList" :data="item" :key="item.ID" /></div>
      </div>
      <div class="top-title">最新推荐</div>
      <div>已售出商品的最新榜單</div>
      <div class="flex justify-between flex-wrap mt">
        <likeCard v-for="item in detail.NewList" :data="item" :key="item.ID" />
      </div>
      <div class="top-title">關於{{detail.AreaName}}</div>
      <div class="flex justify-between">
        <div style="width: 720px">
          {{detail.Introduction}}
          </div>
        <div>
          <div id="baidu-map"></div>
        </div>
      </div>
      <!-- <div class="top-title">當地天氣</div> -->
      <div>
        <!-- <div class="flex">
          <div class="time-item" v-for="item in 4" :key="item">
            <div class="f16">12月-2月</div>
            <div class="f26 bold">-12° -17°</div>
          </div>
        </div> -->
        <div class="flex mt">
          <div class="flex items-center time-item">
            <img
              class="info-icon"
              :src="require(`../../assets/img/info-time.png`)"
            />
            <div>
              <div class="f16 bold">時區</div>
              <!-- <div>-12° -17°</div> -->
            </div>
          </div>
          <div class="flex items-center time-item">
            <img
              class="info-icon"
              :src="require('../../assets/img/info-currency.png')"
            />
            <div>
              <div class="f16 bold">貨幣</div>
              <!-- <div>-12° -17°</div> -->
            </div>
          </div>
          <div class="flex items-center time-item">
            <img
              class="info-icon"
              :src="require(`../../assets/img/info-ele.png`)"
            />
            <div>
              <div class="f16 bold">電壓</div>
              <!-- <div>-12° -17°</div> -->
            </div>
          </div>
          <div class="flex time-item">
            <img
              class="info-icon"
              :src="require(`../../assets/img/info-time.png`)"
            />
            <div>
              <div class="f16 bold q-mt-xs">旅遊時間</div>
              <!-- <div>-12° -17°</div> -->
            </div>
          </div>
        </div>
      </div>
      <nearCity :cityList="detail.AdjacentCityList" />
    </div>
  </div>
</template>
<script>
import topCard from "./components/top-card.vue";
import likeCard from "./components/like-card.vue";
import nearCity from "./components/near-city.vue";
export default {
  components: { topCard, likeCard, nearCity },
  data() {
    return {
      detail: null,
      navList: [
        {
          title: "觀光行程",
          img: "nav-map",
        },
        {
          title: "景點門票",
          img: "nav-ticket",
        },
        {
          title: "住宿",
          img: "nav-hotal",
        },
        {
          title: "交通",
          img: "nav-trip",
        },
      ],
    };
  },
  mounted() {
    this.getData();
    this.createMap();
    this.addMarker();
    this.addLabel()
  },
  methods: {
    getData() {
      this.$q.loading.show();
      this.apipost(
        "b2c_get_GetB2CIndexCityList",
        { AreaId: decodeURIComponent(this.$route.params.id) },
        (r) => {
          this.detail = r.data.data
          this.$q.loading.hide();
        },
        null
      );
    },
    createMap() {
      if (!BMapGL) {
        return;
      }
      let map = new BMapGL.Map("baidu-map"); // 创建地图实例
      let point = new BMapGL.Point(116.404, 39.915); // 创建点坐标
      map.centerAndZoom(point, 15); // 初始化地图，设置中心点坐标和地图级别
      this.map = map;
    },
    addMarker() {
      let icon = require(`../../assets/img/info-time.png`);
      var myIcon = new BMapGL.Icon(icon, new BMapGL.Size(23, 25), {
        // 指定定位位置。
        // 当标注显示在地图上时，其所指向的地理位置距离图标左上
        // 角各偏移10像素和25像素。您可以看到在本例中该位置即是
        // 图标中央下端的尖角位置。
        anchor: new BMapGL.Size(10, 25),
        // 设置图片偏移。
        // 当您需要从一幅较大的图片中截取某部分作为标注图标时，您
        // 需要指定大图的偏移位置，此做法与css sprites技术类似。
        // imageOffset: new BMapGL.Size(0, 0 - 25)   // 设置图片偏移
      });
      let point = new BMapGL.Point(116.404, 39.915); // 创建点坐标
      // 创建标注对象并添加到地图
      var marker = new BMapGL.Marker(point, { icon: myIcon });
      this.map.addOverlay(marker);
    },
    addLabel() {
      var point = new BMapGL.Point(116.404, 39.915);
      var content = "label";
      var label = new BMapGL.Label(content, {
        // 创建文本标注
        position: point, // 设置标注的地理位置
        offset: new BMapGL.Size(10, -80), // 设置标注的偏移量
      });
      this.map.addOverlay(label); // 将标注添加到地图中
      label.addEventListener("click", function () {
        alert("您点击了标注");
      });
      label.setStyle({
        // 设置label的样式
        color: "#000",
        fontSize: "30px",
        border: "2px solid #1E90FF",
      });
    },
  },
};
</script>