<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;
}
#dialog-map {
  width: 800px;
  height: 400px;
  background: #ffffff;
  border-radius: 8px;
}
.name {
  top: 20px;
  left: 20px;
  font-weight: bold;
  font-size: 44px;
  color: #fff;
  text-shadow: rgb(0 0 0 / 50%) 2px 2px 5px;
}
@keyframes icon-bounce {
  0% {
    transform: translateY(0) scale(1.15, 0.5);
  }
  20% {
    transform: translateY(-20px) scaleY(1.1);
  }
  50% {
    transform: translateY(-5px) scale(1);
  }
  80% {
    transform: translateY(-10px) scale(1);
  }
  100% {
    transform: translateY(0) scale(1.15, 0.8);
  }
}
.desktop-navs {
  width: 100px;
}
.desktop-navs:hover img {
  animation-name: icon-bounce;
  animation-duration: 1s;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
}
</style>
<template>
  <div class="content-page" style="min-height: 80vh">
    <div v-if="detail" :class="{ 'q-mx-md': $q.platform.is.mobile }">
      <div class="row items-center q-pt-md q-mb-lg">
        <q-breadcrumbs class="col f12 no-wrap q-mr-md" style="font-size: 13px">
          <q-breadcrumbs-el
            icon="home"
            label="首頁"
            class="cursor-pointer"
            @click="CommonJump('/index', {})"
          />
          <q-breadcrumbs-el :label="detail.AreaName" class="cursor-pointer" />
        </q-breadcrumbs>
        <!-- <div class="text-grey-6 f12">Product No. # {{ dataList.id }}</div> -->
      </div>

      <div
        class="relative row"
        :style="{ height: $q.platform.is.mobile ? '200px' : '370px' }"
      >
        <div class="absolute name" style="z-index: 1">
          {{ detail.AreaName }}
        </div>
        <q-img
          :src="detail.ImageList[0]"
          spinner-color="dark"
          class="col rounded-borders full-height"
        />
        <q-img
          :src="detail.ImageList[1]"
          v-if="detail.ImageList.length > 1"
          spinner-color="dark"
          style="width: 260px"
          class="full-height desktop-only rounded-borders q-ml-md"
        />
        <div
          class="absolute q-py-sm q-px-md row items-center bg-dark text-white rounded-borders cursor-pointer"
          style="bottom: 20px; left: 20px"
        >
          <q-icon name="iconfont iconzhinanzhen" size="16px"></q-icon>
          <span class="q-ml-sm">訪前須知</span>
        </div>
        <div
          class="absolute q-py-sm q-px-md row items-center bg-dark text-white rounded-borders cursor-pointer"
          style="bottom: 20px; right: 20px"
          @click="showPreview(detail.ImageList, 0)"
        >
          <q-icon name="iconfont iconimage" size="16px"></q-icon>
          <span class="q-ml-sm">查看照片</span>
        </div>
        <!-- <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="q-mt-md row justify-center">
        <div
          class="bg-white row rounded-borders light-shadow"
          :class="{
            'q-pa-lg': $q.platform.is.desktop,
            'col-12 q-px-md q-pa-md': $q.platform.is.mobile,
          }"
          style="max-width: 100%"
        >
          <div
            class="text-center cursor-pointer"
            :class="{
              'desktop-navs ': $q.platform.is.desktop,
              'col-3  q-mb-md': $q.platform.is.mobile,
            }"
            v-for="item in navList"
            :key="item.img"
            @click="navClick(item)"
          >
            <img
              width="30"
              height="30"
              :src="require(`../../assets/img/${item.img}.png`)"
            />
            <div
              class="f12"
              :class="{
                'q-mt-md ': $q.platform.is.desktop,
                'q-mt-sm': $q.platform.is.mobile,
              }"
            >
              {{ item.title }}
            </div>
          </div>
        </div>
        <!-- <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 v-if="detail.TopList.length > 0">
        <div class="top-title">TOP榜单</div>
        <div>本地销量最好的商品</div>

        <q-carousel
          v-model="hotSilder"
          transition-prev="slide-right"
          transition-next="slide-left"
          swipeable
          animated
          control-color="dark"
          control-type="regular"
          padding
          arrows
          height="300px"
          flat
          class="bg-transparent rounded-borders q-mt-md"
        >
          <q-carousel-slide
            :name="index"
            v-for="(item, index) in Math.ceil(
              detail.TopList.length / topPageCount
            )"
            :key="index"
            class="column no-wrap"
          >
            <div
              class="row fit justify-start items-center q-gutter-md q-col-gutter no-wrap"
            >
              <template v-for="(x, i) in topPageCount">
                <goods-style1
                  v-if="i + index * topPageCount < detail.TopList.length"
                  :product="detail.TopList[i + index * topPageCount]"
                  :key="detail.TopList[i + index * topPageCount].ConfigId"
                  :class="{
                    'col-3': topPageCount == 4,
                    'col-12': topPageCount == 1,
                  }"
                ></goods-style1>
              </template>
            </div>
          </q-carousel-slide>
        </q-carousel>
      </div>
      <div v-if="detail.NewList && detail.NewList.length>0">
        <div class="top-title">最新推荐</div>
        <div>已售出商品的最新榜單</div>
        <q-carousel
          v-model="newSilder"
          transition-prev="slide-right"
          transition-next="slide-left"
          swipeable
          animated
          control-color="dark"
          control-type="regular"
          padding
          arrows
          height="400px"
          flat
          class="bg-transparent rounded-borders q-mt-md desktop-only"
        >
          <q-carousel-slide
            :name="index"
            v-for="(item, index) in Math.ceil(detail.NewList.length / 4)"
            :key="index"
            class="column no-wrap"
          >
            <div class="row">
              <template v-for="(x, i) in 4">
                <goods-style2
                  v-if="i + index * 4 < detail.NewList.length"
                  :product="detail.NewList[i + index * 4]"
                  :key="detail.NewList[i + index * 4].ConfigId"
                  class="q-pr-md col-6 q-mb-md"
                ></goods-style2>
              </template>
            </div>
          </q-carousel-slide>
        </q-carousel>
        <div class="mobile-only q-mt-md">
          <goods-style2
            :product="x"
            :key="i"
            class="q-pr-md col-6 q-mb-md"
            v-for="(x, i) in detail.NewList"
          ></goods-style2>
        </div>
      </div>
      <city-info :city="detail"></city-info>
      
      <nearCity :name="detail.AreaName" :cityList="detail.AdjacentCityList" />
      <q-dialog v-model="show">
        <div style="width: 900px">
          <div id="dialog-map"></div>
        </div>
      </q-dialog>
    </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";
import goodsStyle1 from "../../components/goods/style1.vue";
import goodsStyle2 from "../../components/goods/style2.vue";
import cityInfo from "./components/city-info.vue";
export default {
  components: {
    topCard,
    likeCard,
    nearCity,
    goodsStyle1,
    goodsStyle2,
    cityInfo,
  },
  data() {
    return {
      show: false,
      detail: null,
      hotSilder: 0,
      newSilder: 0,
      topPageCount: 4,
      newPageCount: 2,
      navList: [
        {
          title: "行程线路",
          img: "nav-map",
        },
        {
          title: "景点门票",
          img: "nav-ticket",
        },
        {
          title: "住宿",
          img: "nav-hotal",
        },
        {
          title: "交通",
          img: "nav-trip",
        },
      ],
    };
  },
  mounted() {
    if (this.$q.platform.is.mobile) {
      this.topPageCount = 1;
      this.newPageCount = 2;
    }
    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) {
      if(item.title=='行程线路'){
        this.CommonJump("/searchProduct", {
          areaId: this.detail.Id,
          qsearchDate: this.searchDate,
          qsearchEndDate: this.searchEndDate,
          CategoryName: item.title,
        });
        return
      }
      this.CommonJump("/search", {
        areaId: this.detail.Id,
        qsearchDate: this.searchDate,
        qsearchEndDate: this.searchEndDate,
        CategoryName: item.title,
      });
    },
    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.createTopMap();
          });
        },
        null
      );
    },
    createMap() {
 
    },
    addMarker() {
      let icon = require(`../../assets/img/marker.png`);
      var myIcon = new BMapGL.Icon(icon, new BMapGL.Size(27, 32), {
        // 指定定位位置。
        // 当标注显示在地图上时，其所指向的地理位置距离图标左上
        // 角各偏移10像素和25像素。您可以看到在本例中该位置即是
        // 图标中央下端的尖角位置。
        anchor: new BMapGL.Size(10, 25),
        // 设置图片偏移。
        // 当您需要从一幅较大的图片中截取某部分作为标注图标时，您
        // 需要指定大图的偏移位置，此做法与css sprites技术类似。
        // imageOffset: new BMapGL.Size(0, 0 - 25)   // 设置图片偏移
      });
      let point = new BMapGL.Point(this.detail.Lng, this.detail.Lat); // 创建点坐标
      // 创建标注对象并添加到地图
      var marker = new BMapGL.Marker(point, { icon: myIcon });
      this.map.addOverlay(marker);
    },
    addLabel() {
      var point = new BMapGL.Point(this.detail.Lng, this.detail.Lat);
      var content = `<div style="font-size: 16px; font-weight: bold;">${this.detail.AreaName}</div><div style="font-size:14px">点击查看附近信息</div>`;
      var label = new BMapGL.Label(content, {
        // 创建文本标注
        position: point, // 设置标注的地理位置
        offset: new BMapGL.Size(10, -80), // 设置标注的偏移量
      });
      this.map.addOverlay(label); // 将标注添加到地图中
      const that = this;
      label.addEventListener("click", function () {
        that.openDialog();
      });
      label.setStyle({
        // 设置label的样式
        color: "#000",
        backgrond: "#fff",
        padding: "4px",
        border: "none",
      });
    },
    createTopMap() {
 
    },
    addTopMarker() {
      let icon = require(`../../assets/img/marker.png`);
      var myIcon = new BMapGL.Icon(icon, new BMapGL.Size(27, 32), {
        // 指定定位位置。
        // 当标注显示在地图上时，其所指向的地理位置距离图标左上
        // 角各偏移10像素和25像素。您可以看到在本例中该位置即是
        // 图标中央下端的尖角位置。
        anchor: new BMapGL.Size(10, 25),
        // 设置图片偏移。
        // 当您需要从一幅较大的图片中截取某部分作为标注图标时，您
        // 需要指定大图的偏移位置，此做法与css sprites技术类似。
        // imageOffset: new BMapGL.Size(0, 0 - 25)   // 设置图片偏移
      });
      let point = new BMapGL.Point(this.detail.Lng, this.detail.Lat); // 创建点坐标
      // 创建标注对象并添加到地图
      var marker = new BMapGL.Marker(point, { icon: myIcon });
      this.topMap.addOverlay(marker);
    },
    addTopLabel() {
      var point = new BMapGL.Point(this.detail.Lng, this.detail.Lat);
      var content = `<div style="font-size: 16px; font-weight: bold;">${this.detail.AreaName}</div><div style="font-size:14px">点击查看附近信息</div>`;
      var label = new BMapGL.Label(content, {
        // 创建文本标注
        position: point, // 设置标注的地理位置
        offset: new BMapGL.Size(10, -80), // 设置标注的偏移量
      });
      this.topMap.addOverlay(label); // 将标注添加到地图中
      const that = this;
      label.addEventListener("click", function () {
        that.openDialog();
      });
      label.setStyle({
        // 设置label的样式
        color: "#000",
        backgrond: "#fff",
        padding: "4px",
        border: "none",
      });
    },
    openDialog() {
      this.show = true;
      this.$nextTick(() => {
        let map = new BMapGL.Map("dialog-map"); // 创建地图实例
        this.map = map;
        let pointA = new BMapGL.Point(this.detail.Lng, this.detail.Lat); // 创建点坐标
        map.centerAndZoom(pointA, 11); // 初始化地图，设置中心点坐标和地图级别
        map.enableScrollWheelZoom();
      });
    },
    showPreview(images, index = 0) {
      this.$viewerApi({
        options: {
          initialViewIndex: index,
        },
        images,
      });
    },
  },
};
</script>
