<template>
  <view class="width-100 height-100 view-page">
    <view class="p-10 dis-flex flex-y-center flex-x-between">
      <view class="search-left-btn">
        <u-image width="35px" height="35px" mode="aspectFit" src="@/static/images/home/logo.png"></u-image>
      </view>
      <view class="width-100">
        <u-search :clearabled="true" height="35px" placeholder="请输入搜索关键字" v-model="keyword" shape="round"
          search="doSearch" @custom="doSearch" :showAction="false" bg-color="#e9f0f8"
          placeholder-color="#65371b"></u-search>
      </view>
    </view>
    <view style="width: 100%;height: 250px;">
      <qiun-data-charts type="map" :opts="mapOpts" :chartData="mapDataColumn" @getIndex="clickMap" />
    </view>
    <u-tabs ref="tabs" :list="tabList" :scrollable="false" :current="currentTab" @change="tabChange" lineColor="#65371b"
      :activeStyle="{color:'#65371b'}" inactiveStyle="{color:'#65371b'}"></u-tabs>
    <u-list @scrolltolower="scrolltolower" height="calc(100% - 341px)" lowerThreshold="10">

      <view class="info-list">
        <view class="info-item" v-for="(item, index) in list" :key="index" @click="toDetail(item.id)">
          <view class="info-pic">
            <u-image width="96px" height="96px" mode="aspectFill" :src="item.cover"></u-image>
          </view>
          <view class="info-title">
            {{item.name || item.title}}
          </view>
        </view>
      </view>
      <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
        :nomore-text="page.nomoreText" />
    </u-list>
  </view>
</template>

<script>
  import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';

  import mapdata from '@/mockdata/mapdata.json';
  export default {
    mixins: [themeMixins],
    data() {
      return {
        mapOpts: {
          timing: "easeOut",
          duration: 1000,
          rotate: false,
          rotateLock: false,
          color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
          padding: [0, 0, 0, 0],
          fontSize: 13,
          fontColor: "#666666",
          dataLabel: false,
          dataPointShape: true,
          dataPointShapeType: "solid",
          touchMoveLimit: 60,
          enableScroll: false,
          enableMarkLine: false,
          extra: {
            map: {
              border: true,
              borderWidth: 1,
              borderColor: "#666666",
              fillOpacity: 0.6,
              activeBorderColor: "#F04864",
              activeFillColor: "#FACC14",
              activeFillOpacity: 1,
              mercator: false,
              active: true,
              activeTextColor: "#FFFFFF"
            },
            tooltip: {
              showBox: true,
              showArrow: true,
              showCategory: false,
              borderWidth: 0,
              borderRadius: 0,
              borderColor: "#000000",
              borderOpacity: 0.7,
              bgColor: "#000000",
              bgOpacity: 0.7,
              gridType: "solid",
              dashLength: 4,
              gridColor: "#CCCCCC",
              boxPadding: 3,
              fontSize: 13,
              lineHeight: 20,
              fontColor: "#FFFFFF",
              legendShow: true,
              legendShape: "auto",
              splitLine: true,
              horizentalLine: false,
              xAxisLabel: false,
              yAxisLabel: false,
              labelBgColor: "#FFFFFF",
              labelBgOpacity: 0.7,
              labelFontColor: "#666666"
            }
          }
        },
        mapDataColumn: {},
        //
        chartOption: {

        },
        page: {
          current: 1,
          size: 15,
          total: 0,
          // loadmore loading nomore
          status: 'loadmore',
          loadingText: '正在加载中',
          loadmoreText: '上拉加载更多',
          nomoreText: '没有更多了'
        },
        keyword: '',
        areaCode: '',
        list: [],
        tabList: [{
          name: '专业风采'
        }, {
          name: '名店',
        }, {
          name: '名菜'
        }, {
          name: '名点',
        }],
        currentTab: 0
      }
    },
    onReady() {

      setTimeout(() => {
        let md = {
          visualMap: {
            min: 800,
            max: 50000,
            text: ['High', 'Low'],
            realtime: false,
            calculable: true,
            inRange: {
              color: ['lightskyblue', 'yellow', 'orangered']
            }
          },
          series: mapdata.features
        };
        this.mapDataColumn = JSON.parse(JSON.stringify(md));
      }, 5000);
    },
    onLoad(options) {},
    onShow() {
      this.doRefresh()
    },
    methods: {
      clickMap(e) {
        if (e.currentIndex < 0) {
          this.areaCode = '';
        } else {
          this.areaCode = e.opts.series[e.currentIndex].properties.adcode || '';
        }

        this.areaSearch();
      },
      tabChange(e) {
        this.currentTab = e.index;
        this.doRefresh();
      },
      scrolltolower() {
        this.loadmore()
      },
      loadmore() {
        this.page.current++;
        this.getList();
      },
      areaSearch() {
        this.page.current = 1;
        this.page.status = 'loadmore';
        this.list = [];
        this.getList();
      },
      doRefresh() {
        this.page.current = 1;
        this.page.status = 'loadmore';
        this.areaCode = '';
        this.list = [];
        this.getList();
      },
      getList() {
        if (this.page.status == 'loading' || this.page.status == 'nomore') {
          // 防止重复下拉
          return;
        }
        this.page.status = 'loading';
        //
        let listFunc, params = {};
        switch (this.currentTab) {
          case 0:
            listFunc = this.$u.api.getProfessionalStyleList;
            params.title = this.keyword || '';
            break;
          case 1:
            listFunc = this.$u.api.getRestaurantList;
            params.name = this.keyword || '';
            params.regionId = this.areaCode || '';
            break;
          case 2:
            listFunc = this.$u.api.getDishList;
            params.name = this.keyword || '';
            params.regionId = this.areaCode || '';
            break;
          case 3:
            listFunc = this.$u.api.getSnacksList;
            params.name = this.keyword || '';
            params.regionId = this.areaCode || '';
            break;
          default:
            return;
            break;
        }
        //
        listFunc(this.page.current, this.page.size, params).then(res => {
          if (res.data.records && res.data.records.length > 0) {
            this.list.push(...res.data.records)
          }
          this.page.total = res.data.total || 0;
          if (this.page.size * this.page.current >= res.data.total) {
            this.page.status = 'nomore'
          } else {
            this.page.status = 'loadmore'
          }
        })
      },
      toDetail(id) {
        switch (this.currentTab) {
          case 0:
            uni.navigateTo({
              url: "/pages/yuecai/professional_style/detail/index?id=" + id,
            })
            break;
          case 1:
            uni.navigateTo({
              url: "/pages/yuecai/restaurant/detail/index?id=" + id,
            })
            break;
          case 2:
            uni.navigateTo({
              url: "/pages/yuecai/dish/detail/index?id=" + id,
            })
            break;
          case 3:
            uni.navigateTo({
              url: "/pages/yuecai/snacks/detail/index?id=" + id,
            })
            break;
          default:
            return;
            break;
        }

      }
    },
  }
</script>

<style scoped lang="scss">
  .search-left-btn {
    width: 35px;
    min-width: 35px;
    height: 35px;
    margin-right: 5px;
    box-sizing: border-box;
  }

  .icon-circle {
    border-radius: 50%;
    border: 4rpx solid #65371b;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .nav-btns {
    border-bottom: 1rpx solid #65371b;
    margin-bottom: 20rpx;
    padding-bottom: 50rpx;

    .nav-btn {
      width: 150rpx;

      .nav-btn-icon {
        margin: auto;
        width: 110rpx;
        height: 110rpx;
      }

      .nav-btn-text {
        width: 100%;
        color: #65371b;
        margin-top: 5rpx;
        font-weight: bolder;
        text-align: center;
      }
    }
  }

  .info-list {
    display: flex;
    flex-wrap: wrap;

    .info-item {
      padding: 20rpx;
      width: 33%;
      box-sizing: border-box;

      .info-pic {
        margin: auto;
        width: 175rpx;
        height: 175rpx;
        background: bisque;
      }

      .info-title {
        word-break: break-all;
        text-align: center;
        color: #65371b;
        font-size: 24rpx;
        font-weight: 300;
        line-height: 47rpx;
        word-spacing: 2rpx;
        overflow: hidden;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        line-clamp: 3;
        -webkit-box-orient: vertical;
      }
    }
  }
</style>