<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]"
          />
          <div class="card-img" id="map"></div>
        </div>
      </div>

      <div class="flex justify-between q-mt-sm">
        <div v-for="item in navList" :key="item.img" class="nav-item" @click="navClick(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="width: 1200px; overflow-x: auto;">
        <div style="width: 2920px">
        <topCard @click.native="navToDetail(item)" 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 @click.native="navToDetail(item)" 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 class="mt pt">
        <!-- <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">時區 {{detail.TimeZones}}</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">貨幣 {{detail.CurrencyName}}</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">電壓 {{detail.Voltage}}</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 v-for="(item, index) in detail.BestTravelTimeList" :key="index">
                <span class="bold">{{item.Month}}</span><span class="q-ml-sm ">{{item.Description}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <nearCity :name="detail.AreaName" :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();
    var newStartDate = new Date();
    var newStartDateStr = this.formatDate(
      newStartDate.getFullYear(),
      newStartDate.getMonth() + 1,
      newStartDate.getDate()
    );
    var newEndDate = this.AddMonth(newStartDateStr, 2);
    var newEndDateStr = this.formatDate(
      newEndDate.getFullYear(),
      newEndDate.getMonth() + 1,
      newEndDate.getDate()
    );
    this.searchDate = newStartDateStr;
    this.searchEndDate = newEndDateStr;
  },
  methods: {
    navClick(item) {
      this.CommonJump(
        "/search",
        {
        qsearchKey: this.detail.AreaName,
        qsearchDate: this.searchDate,
        qsearchEndDate: this.searchEndDate,
        CategoryName: item.title}
      );
    },
    navToDetail(item) {
      console.log('navToDetail', item)
    },
    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();
          this.$nextTick(() => {
            this.createMap();
    this.addMarker();
    this.addLabel()
          })
        },
        null
      );
    },
    createMap() {
      if (!BMapGL) {
        return;
      }
      let map = new BMapGL.Map("baidu-map"); // 创建地图实例
      this.map = map;
      var myGeo = new BMapGL.Geocoder();
      const that = this
      let address = '日本东京'
      console.log('address', address)
      myGeo.getPoint(address, function(point){
    if(point){
      console.log('get point', point)
      that.point = point
      let pointA = new BMapGL.Point(point.lng, point.lat); // 创建点坐标
      map.centerAndZoom(pointA, 8); // 初始化地图，设置中心点坐标和地图级别
    }else{
        alert('您选择的地址没有解析到结果！');
    }
},'东京')
    },
    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(this.point.lng, this.point.lat); // 创建点坐标
      // 创建标注对象并添加到地图
      var marker = new BMapGL.Marker(point, { icon: myIcon });
      this.map.addOverlay(marker);
    },
    addLabel() {
      var point = new BMapGL.Point(this.point.lng, this.point.lat);
      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>