<template>
  <div class="list-box" >

    <div style="position:relative;height:400rpx;">
      <swiper scroll-x="true" autoplay="true" circular="true" class="banner" @change="swiperChange($event,'currentBan')" :current="currentBan">
        <swiper-item v-for="(img,i) in bannerList" :key="i">
          <image :src="img" @click="openBecomeVip()" :style="i===0?'height:409rpx;':''"></image>
        </swiper-item>
      </swiper>
      <div class="swiper-dots">
        <div v-for="(dot,i) in bannerList" :key="i" class="dot" :class="{'active':currentBan===i}"> </div>
      </div>
      <div class="user-card">
        <div class="banner-text">
          <block v-if="user.MEMBERSHIP_MOBILEPHONE">
            <div >
              <div v-if="user.MEMBERSHIP_NAME">{{user.MEMBERSHIP_NAME}}</div>
              <open-data v-else type="userNickName" class="name-text"></open-data>
            </div>
            <div style="display:flex;font-size:26rpx;align-item:center">
              <image class="ico-vip" src="https://eshangtech.com/ShopICO/vip-ico.png" mode="aspectFit"></image>
              <span>{{user.MEMBERSHIP_LEVEL_TEXT}}</span>
            </div>
          </block>
          <block v-else>
            <div style="display:flex;align-items:center;">
              <i></i>
              <image src="https://eshangtech.com/ShopICO/yifuhuiyuan.png" mode="aspectFit" style="width:115rpx;height:29rpx;" />
              <!-- <span>加入驿付会员</span> -->
            </div>
            <span class="vip-btn" @click="goRegister">立即加入</span>
          </block>
        </div>

      </div>

    </div>

    <!-- <div class="movebox" :style="user.MEMBERSHIP_MOBILEPHONE? 'transform: translateY(88rpx)': 'transform: translateY(0px)'" @touchmove="moveBox" @touchstart="startTouch" @touchend="endMove"> -->
    <div class="movebox" >
      <div class="hxing"></div>
      <div class="menu-box ">
        <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/homeFn/payfor/main')">

          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/payMa.png" mode="aspectFit" style="width:52rpx;height:44rpx;"></image></i>
          <span>付款</span>
        </div>

        <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/shopPages/shopList/main')">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/orderfood.png" mode="aspectFit" style="width:41rpx;height:45rpx;"></image></i>

          <span>预约</span>
        </div>
        <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/homeFn/myCoupon/main')">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/backpack.png" mode="aspectFit" style="width:47rpx;height:44rpx;"></image></i>

          <span>券包</span>
        </div>
        <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/webview/main?name=questionnarie&severpart='+serverPart.ServerPart_Id+'&province='+serverPart.ProvinceCode)">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/questionnarie.png" mode="aspectFit" style="width:48rpx;height:46rpx;"></image></i>

          <span>问卷调查</span>
        </div>
        <!-- <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/homeFn/integral/main')">

          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/home-point.png" mode="aspectFit" style="width:37rpx;height:48rpx;"></image></i>
          <span>积分</span>
        </div> -->
      </div>
      <div class="menu-box ">

        <!-- <div class="model-c-menu" hover-class="navigator-hover">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/invoice.png" mode="aspectFit" style="width:51rpx;height:43rpx;"></image></i>

          <span>发票</span>
        </div> -->
        <!-- <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/webview/main?name=questionnarie&severpart='+serverPart.ServerPart_Id+'&province='+serverPart.ProvinceCode)">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/questionnarie.png" mode="aspectFit" style="width:48rpx;height:46rpx;"></image></i>

          <span>问卷调查</span>
        </div> -->
        <div class="model-c-menu" hover-class="navigator-hover" @tap="signIn()">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/gsyw_wechat/questionnarie.png" mode="aspectFit" style="width:60rpx;height:56rpx;"></image></i>

          <span>签到</span>
        </div>

        <!-- <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/webview/main')">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/invoice.png" mode="aspectFit" style="width:65rpx;height:43rpx;"></image></i>

          <span>中秋送礼</span>
        </div> -->
        <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/homeFn/help/main')" >

          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/help.png" mode="aspectFit" style="width:41rpx;height:44rpx;"></image></i>
          <span>帮助</span>
        </div>
        <!-- open-type="switchTab" -->
<!--          老版的-->
<!--        <navigator class="model-c-menu" hover-class="navigator-hover" open-type="navigate" url="/pages/mallHome/main" >-->
<!--          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/gsuyiw.png" mode="aspectFit" style="width:43rpx;height:49rpx;"></image></i>-->
<!--          <span>驿佳超市</span>-->
<!--        </navigator>-->
<!--          跳万佳的-->
          <navigator class="model-c-menu" hover-class="navigator-hover" url="/pages/index/index" target="miniProgram" app-id="wx46686dbdd02eda15">
              <i class="ico-menu"><image src="/static/images/discovery/logo.jpg" mode="aspectFit" style="width:43rpx;height:49rpx;"></image></i>
              <span>驿达万佳</span>
          </navigator>


        <!-- <div class="model-c-menu" hover-class="navigator-hover"  @click="isGo('/pages/shoppingMall/main')" >

          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/gsuyiw.png" mode="aspectFit" style="width:43rpx;height:49rpx;"></image></i>
          <span>驿网优品</span>
        </div> -->
        <div class="model-c-menu" hover-class="navigator-hover" @click="isGo('/pages/homeFn/complaints/main')">
          <i class="ico-menu"><image src="https://eshangtech.com/ShopICO/suggest.png" mode="aspectFit" style="width:52rpx;height:43rpx;"></image></i>

          <span>投诉建议</span>
        </div>
      </div>

       <div style="position:relative;">
<!--           currentService-->
           <div class="severpart-box" @click="goSelectServer" v-if="serverPart.SERVERPART_NAME">
               <image mode="aspectFit" src="https://eshangtech.com/ShopICO/icos/dingwei.png" style="margin-right:16rpx;width:34rpx;height:38rpx;"></image>
               <span class="service-name">
            {{serverPart.SERVERPART_NAME}}
          </span>
               <van-icon name="https://eshangtech.com/ShopICO/icos/sanjiao.png" size="16rpx" color="#333" custom-style="margin-left:16rpx;"/>
           </div>
           <div class="severpart-box" @click="goSelectServer" v-else>

               <image mode="aspectFit" src="https://eshangtech.com/ShopICO/icos/dingwei.png" style="margin-right:16rpx;width:34rpx;height:38rpx;"></image>
               <span class="service-name">定位服务区</span>
           </div>


<!--        <div class="severpart-box" @click="toggleSever" v-if="serverPart.ServerPart_Name">-->
<!--          <image mode="aspectFit" src="https://eshangtech.com/ShopICO/icos/dingwei.png" style="margin-right:16rpx;width:34rpx;height:38rpx;"></image>-->
<!--          &lt;!&ndash; <span class="position-name">{{city}}</span> &ndash;&gt;-->
<!--          <span class="service-name">-->
<!--            &lt;!&ndash; 萧山服务区 &ndash;&gt;-->
<!--            {{serverPart.ServerPart_Name}}-->
<!--          </span>-->
<!--          <van-icon name="https://eshangtech.com/ShopICO/icos/sanjiao.png" size="16rpx" color="#333" custom-style="margin-left:16rpx;"/>-->
<!--        </div>-->
<!--&lt;!&ndash;        <div class="severpart-box" @click="getLocalServer" v-else>&ndash;&gt;-->
<!--        <div class="severpart-box" @click="goSelectServer" v-else>-->

<!--          <image mode="aspectFit" src="https://eshangtech.com/ShopICO/icos/dingwei.png" style="margin-right:16rpx;width:34rpx;height:38rpx;"></image>-->
<!--          &lt;!&ndash; <span class="position-name">{{city}}</span> &ndash;&gt;-->
<!--          <span class="service-name">定位服务区</span>-->
<!--        </div>-->
      </div>

        <!-- 精选商家 -->
        <div class="hot-block mt20" v-if="storeList.length>0">
            <div class="block-title">
                <image  src="https://eshangtech.com/ShopICO/icos/home-sj.png" style="width:246rpx;height:51rpx;"/>
            </div>
            <div class="mt20">
                <div class="conpon-img-box" v-if="storeList.length>4">
                    <div class="store-img" v-for="(item,o) in storeList" :key="o">
                        <image mode="aspectFit" :src="item.IMAGE_URL" @click="goShop(item)"></image>
                        <div class="photo-name" style="text-align:left;padding-left:20rpx;bottom:56rpx;" v-if="o<2">{{ item.TITLE }}</div>
                        <div class="photo-name" style="bottom:108rpx;" v-else>{{item.TITLE}}</div>

                    </div>
                </div>

                <div class="photo-box" v-else>

                    <div class="store-photo-box">
                        <div class="store-photo" v-for="(item,i) in storeList" @click="goShop(item)" :key="i">
                            <image  mode="aspectFit" :src="item.IMAGE_URL"></image>
                            <div class="photo-name" >{{item.TITLE}}</div>
                        </div>

                    </div>
                </div>

            </div>
        </div>

      <div class="hot-block mt20" v-if="cardList.length>0">
        <div class="block-title">
          <image  src="https://eshangtech.com/ShopICO/icos/home-kq.png" style="width:217rpx;height:51rpx;"/>
          <!-- 卡券优惠 -->
          </div>

          <div class="conpon-list-box mt20">
            <div class="store-photo" v-for="(item,i) in cardList" @click="goDetail(item)" :key="i">
              <image mode="aspectFit" :src="item.IMAGE_URL"></image>
              <div class="photo-name">
                <text v-for="(t,o) in item.title" :key="o" :class='{"text-red":t>0}'>{{t}}</text>
              </div>
            </div>

          </div>

      </div>

        <!-- 驿网优品  精选商城-->
        <div class="hot-block mt20" v-if="mallList.length>0">
            <div class="block-title">
                <image  src="https://eshangtech.com/ShopICO/icos/home-sc.png" style="width:249rpx;height:51rpx;"/>

            </div>

            <div class="product-photo-box" >

                <swiper scroll-x="true"  @change="swiperChange($event,'currentPro')" :current="currentPro" style="height:300rpx;">
                    <swiper-item v-for="(imgList,i) in mallList" :key="i" class="swiper-image">
                        <div class="product-photo" v-for="(item,o) in imgList" @click="goMall(item)" :key="o">
                            <image mode="aspectFit" :src="item.IMAGE_URL"></image>
                            <div class="photo-name">
                                <div class="value-text">{{item.COMMODITY_POINT}}<text style="font-size:18rpx;line-height:30rpx;">积分</text></div>
                                <text style="white-space:nowrap;overflow:hidden;width:168rpx;">{{item.TITLE}}</text>
                            </div>
                        </div>
                    </swiper-item>
                </swiper>
                <div class="pro-swiper-dots">
                    <div v-for="(dot,i) in mallList" :key="i" class="dot" :class="{'active':currentPro===i}"> </div>
                </div>

            </div>

        </div>
    </div>

    <uniPopup :show="isShow && !user.MEMBERSHIP_MOBILEPHONE" @close="isShow=false" custom-style="border-radius: 24rpx;">
      <div class="pop-box">
        <div class="pop-title">温馨提示</div>
        <div class="pop-body">您还没有登录，快去登录吧!</div>
        <div class="popbtn-box">
          <div class="popbtn cancel-btn" @click="isShow=false">取消</div>
          <div class="popbtn confirm-btn" @click="goRegister">去登录</div>
        </div>
      </div>
    </uniPopup>
    <uniPopup :show="isShowBuilding" @close="isShowBuilding=false" custom-style="border-radius: 24rpx;">
      <div class="pop-box">
        <div class="pop-title">温馨提示</div>
        <div class="pop-body">该模块正在建设中，尽请期待。</div>
        <div class="popbtn-box">
          <!-- <div class="popbtn cancel-btn" @click="isShowBuilding=false">关闭</div> -->
          <div class="popbtn confirm-btn" @click="isShowBuilding=false">确定</div>
        </div>
      </div>
    </uniPopup>
   <uniPopup :show="isShowSever"
    position="bottom"
    overlay="false"
    @close="isShowSever=false">
    <van-picker show-toolbar :columns="severList" @cancel="isShowSever=false" @confirm="chosePart" value-key="showName"/>
  </uniPopup>
   <!-- <payForVip/> -->
  <van-overlay :show="isShowSign===1 || isShowSign===2" @click="isShowSign=0" duration="0.1">
    <div class="qd-pop" v-show="isShowSign==1 || isShowSign==2" >
      <block v-if="isShowSign==1">
        <div class="qd-pop-days">
          <text v-for="(d,i) in checkDays" :key="i">{{d.WeekName}}</text>
        </div>
        <div class="qd-pop-img">
          <hr class="qd-pop-line"/>
          <block v-for="(d,i) in checkDays" :key="i" >
            <image v-if="d.IsSign==0" src="https://eshangtech.com/ShopICO/home-qd/dqd-ico.png" mode="aspectFit"/>
            <image v-else-if="d.IsSign==1" src="https://eshangtech.com/ShopICO/home-qd/yqd-ico.png" mode="aspectFit" />
            <image v-else src="https://eshangtech.com/ShopICO/home-qd/wqd-ico.png" mode="aspectFit" />
          </block>

        </div>
        <div class="qd-pop-text">恭喜你获得</div>
        <div class="qd-pop-jf">
          <image src="https://eshangtech.com/ShopICO/home-qd/jfb-ico.png" class="pd-pop-ico"/>
          <van-icon name="cross" size="12" color="#363636"/>
          <text style="margin-left:12rpx;">{{BonusPoint || 1}}</text>
        </div>
      </block>
      <block v-else-if="isShowSign==2">
        <div class="qd-pop-text" style="font-size:34rpx;margin-top:46rpx;">今日已签到</div>
        <div class="qd-pop-tip">连续签到有惊喜</div>
      </block>
      <div class="qd-btn">知道了</div>
    </div>
    <!-- <image :src="'https://eshangtech.com/ShopICO/gsyw_wechat/'+(isShowSign==1? 'qdcg.png':'yqd.png')" mode="aspectFit" style="width:690rpx;" :style="'height:'+(isShowSign==1? '688rpx;':'580rpx;')"/> -->
    <!-- <navigator style="position:absolute; width:606rpx;height:93rpx;bottom: 110rpx;left: 42rpx;" hover-class="navigator-hover" open-type="switchTab" url="/pages/shoppingMall/main" @click="isShowSign=0"></navigator> -->

  </van-overlay>


      <view class="privacyMeng" v-if="showPrivacy"></view>
      <view class="privacy" v-if="showPrivacy">
          <view class="privacyContent">
              <p class="contentTitle">用户隐私保护提示</p>
              <view class="contentWord">
                  感谢您使用本产品，您使用本产品前应当仔细阅读并同意<text class="tips" @click="handleOpenPrivacyContract">《小程序隐私保护指引》</text>
                  当您点击同意并开始使用产品服务时，即表示您已理解并同意该条款内容，该条款将对您产生法律约束。如您拒绝，将无法更好的体验产品。
              </view>
          </view>
          <view class="btnList">
              <button class="btns noAgree" @click="handleRefuse">拒绝</button>
              <button class="btns agree" id="agree-btn3" open-type="agreePrivacyAuthorization"  @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
          </view>
      </view>

  </div>

</template>

<script>

import { mapGetters, mapMutations } from 'vuex'
import UniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue';
export default {
  data () {
    return {
      isFirst: 1,
      height: 0,
      cardList: [],
      mallList: [],
      isShow: false,

      bannerList: ['https://eshangtech.com/ShopICO/yifu/banner/banner1.png', 'https://eshangtech.com/ShopICO/yifu/banner/banner2.png', 'https://eshangtech.com/ShopICO/yifu/banner/banner3.png'],
      storeList: [],
      currentY: 0,
      y: 0,
      couponNum: 0,
      currentBan: 0,
      currentPro: 0,
      serverPart: {},
      isShowSever: false,
      isShowSign: 0,
      isShowBuilding: false, //  是否显示正在建设中
      consecutiveCheckDays: 2, // 连续签到天数
      BonusPoint: 1, // 签到积分
      checkDays: [],
      showPrivacy: false, // 隐私弹框的东西
      showBtn: false, // 隐私权限有了之后 就会出来这俩按钮
      currentService: {}
    }
  },
  components:{UniPopup},
  computed: {
    ...mapGetters({
      user: 'user',
      canIuse: 'canIuse',
      provinceCode: 'provinceCode',
      severList: 'severList'
    })
  },

  methods: {
    ...mapMutations({
      setArea: 'setHomeServer',
      setServerPart: 'discoveryServerPart',
      setSeverList: 'severList',
      setprovinceCode: 'setprovinceCode',
      setInvitedCode: 'setInvitedCode',
      setOwnerUnitId: 'setOwnerUnitId'
    }),
    // 跳转到地图选择服务区
    goSelectServer () {
      uni.navigateTo({url: '/pages/newMap/index/main'})
    },
    // 打开隐私协议页面
    handleOpenPrivacyContract () {
      uni.openPrivacyContract({
        success: (success) => {
          console.log('success', success)
        }, // 打开成功
        fail: () => {}, // 打开失败
        complete: () => {}
      })
    },
    // 点击了同意
    handleAgreePrivacyAuthorization (e) {
      console.log('e1', e)
      this.showPrivacy = false
      this.showBtn = true
      this.getLocalServer()
    },
    goDetail (item) {
      if (this.user.MEMBERSHIP_MOBILEPHONE) {
        uni.navigateTo({url: '/pages/couponDetail/main?id=' + item.ITEM_ID})
      } else {
        this.isShow = true
      }
    },
    // 点击了拒绝
    handleRefuse () {
      this.showPrivacy = false
    },
    goShop (item) {
      // if (this.user.MEMBERSHIP_MOBILEPHONE) {
      uni.navigateTo({url: '/pages/storeDetail/main?id=' + item.ITEM_ID})
      // } else {
      // this.isShow = true
      // }
    },
    goMall (item) {
      // if (this.user.MEMBERSHIP_MOBILEPHONE) {
      uni.navigateTo({url: '/pages/product/productDetail/main?id=' + item.ITEM_ID})
      // } else {
      // this.isShow = true
      // }
    },
    goRegister () {
      this.isShow = false
      uni.navigateTo({url: '/pages/register/main'})
    },

    swiperChange (e, name) {
      this[name] = e.mp.detail.current
    },
    openBecomeVip () {
      // if (this.currentBan === 0) {
      //   this.$store.commit('payForVip', true)
      // }
      if (this.currentBan === 2) {
        uni.switchTab({url: '/pages/discovery/main'})
      }
    },
    getCouponList () {
      let _this = this

      _this.$api.getCoop({
        action_type: 'GetRcmContent',
        rcmtagKey: 'HOME_COUPON',
        serverpartId: _this.serverPart.ServerPart_Id,
        provinceCode: _this.provinceCode
      }).then(function (data) {
        if (data.ResultCode === '100') {
          _this.cardList = data.Data.List
          data.Data.List.map(n => { // 把中文和数字拆分  方便把数字标红
            let s = n.TITLE
            // eslint-disable-next-line no-useless-escape
            s = s.split(/([\d\.]+)/g)
            n.title = s
          })
        }
      })
    },

    getStore () {
      let _this = this

      _this.$api.getCoop({
        action_type: 'GetRcmContent',
        rcmtagKey: 'HOME_SELLER',
        serverpartId: _this.serverPart.ServerPart_Id,
        provinceCode: _this.provinceCode

      }).then(function (data) {
        if (data.ResultCode === '100') {
          _this.storeList = data.Data.List
        }
      })
    },
    getMall () {
      let _this = this
      console.log('_this.serverPart', _this.serverPart)

      _this.$api.getCoop({
        action_type: 'GetRcmContent',
        rcmtagKey: 'HOME_MALL',
        serverpartId: _this.serverPart.ServerPart_Id,
        provinceCode: _this.provinceCode

      }).then(function (data) {
        if (data.ResultCode === '100') {
          _this.mallList = _this.$utils.ArrayGroup(data.Data.List, 3)
        }
      })
    },
    getMember () {
      let _this = this
      if (this.user.WechatUserId) {
        _this.$api.getCoop({
          action_type: 'GetMembershipInfo',
          WechatUserId: this.user.WechatUserId,
          RegisterType: 0
        }).then(function (data) {
          if (data.ResultCode === '100') {
            let _data = data
            _this.user.MEMBERSHIP_NAME = _data.Data.MEMBERSHIP_NAME || ''
            _this.user.MEMBERSHIP_ID = _data.Data.MEMBERSHIP_ID || ''
            _this.user.MEMBERSHIP_LEVEL_TEXT = _data.Data.MEMBERSHIP_LEVEL_TEXT || ''
            _this.user.COUPON_COUNT = _data.Data.COUPON_COUNT || ''
            _this.user.PENDORDER_COUNT = _data.Data.PENDORDER_COUNT || ''
            _this.user.RESERVATION_COUNT = _data.Data.RESERVATION_COUNT || ''
            _this.user.ACCOUNT_BALANCE = _data.Data.ACCOUNT_BALANCE || ''
            _this.user.ISPLUS = _data.Data.ISPLUS || ''
            _this.user.INDUSTRY_MEMBERSHIP_ID = _data.Data.INDUSTRY_MEMBERSHIP_ID || ''
            _this.user.MEMBERSHIP_TYPE = _data.Data.MEMBERSHIP_TYPE || ''
            _this.user.MEMBERSHIP_LEVEL = _data.Data.MEMBERSHIP_LEVEL || ''
            _this.user.InviteCode = _data.Data.InviteCode || ''
            _this.user.MEMBERSHIP_POINT = _data.Data.MEMBERSHIP_POINT || ''
            _this.user.MEMBERSHIP_MOBILEPHONE = _data.Data.MEMBERSHIP_MOBILEPHONE || ''
            _this.$store.commit('setUser', _this.user)
          }
        })
      }
    },
    shouldShowBuilding (url) {
      if (url.indexOf('shopList') > -1) {
        this.isGo(url)
      } else {
        this.isShowBuilding = true
      }
    },
    isGo (url) {
      if (this.user.MEMBERSHIP_MOBILEPHONE) {
        if (url === '/pages/homeFn/consumption/main') {
          if (this.user.INDUSTRY_MEMBERSHIP_ID) {
            uni.navigateTo({url: url})
          }
        } else {
          uni.navigateTo({url: url})
        }
      } else {
        this.isShow = true
      }
    },
    moveBox (e) {
      let moveY = e.mp.touches[0].pageY
      let _move = moveY - this.currentY
      if (_move > 5 && _move < 42) {
        this.y = 'transform: translateY(' + _move + 'px)'
      } else if (_move > 42) {
        _move =
        this.y = 'transform: translateY(42px)'
      } else {
        this.y = ''
      }
    },
    startTouch (e) {
      this.currentY = e.mp.touches[0].pageY
    },
    endMove (e) {
      this.y = 'transform: translateY(0px)'
    },
    toggleSever () {
      if (this.severList.length > 0) {
        this.isShowSever = !this.isShowSever
      } else {
        uni.showToast({title: '没有可选择服务区数据。', icon: 'none'})
      }
    },
    getLocalServer () { // 根据定位获取周边服务区
      let _this = this
      wx.getFuzzyLocation({
        type: 'gcj02',
        altitude: true,
        success: async (res) => {
          console.log('rewrwqerwq', res)
          let seatInfo = {
            latitude: res.latitude,
            longitude: res.longitude
          }
          uni.setStorageSync('seatInfo', seatInfo)
          uni.setStorageSync('actualLocation', seatInfo)
          _this.seat = seatInfo

          let latitude = res.latitude
          let longitude = res.longitude
          await this.handleGetNearService(latitude, longitude)
        }
      })
    },
    chosePart (event) {
      let index = event.target.index
      this.serverPart = this.severList[index]
      this.setArea(this.severList[index])
      this.setServerPart(this.severList[index])
      if (this.severList[index].ProvinceCode !== this.provinceCode) {
        this.setprovinceCode(this.severList[index].ProvinceCode)
        // this.getMember()
      }

      this.getCouponList()
      this.getStore()
      this.getMall()
      this.isShowSever = false
    },
    signIn () { // 签到
      let _this = this
      if (this.user.MEMBERSHIP_MOBILEPHONE) {
        _this.$api.getCoop({
          action_type: 'signIn'
        }).then(res => {
          if (res.ResultCode === '100') {
            _this.BonusPoint = res.Data.Bonus_Point
            _this.$api.getCoop({
              action_type: 'getConsecutiveSignIn'
            }).then(rs => {
              _this.checkDays = rs.Data.List
              _this.consecutiveCheckDays = rs.Data.consecutiveCheckDays
              _this.isShowSign = 1
            })
          } else if (res.ResultCode === '101') {
            _this.isShowSign = 2
          } else {
            uni.showModal({
              content: res.ResultDesc,
              showCancel: false,
              success: (res) => {
                if (res.confirm) {

                }
              }
            })
          }
        })
      } else {
        this.isShow = true
      }
    },
    // 拿到最近的服务区数据
    async handleGetNearService (latitude, longitude) {
      let req = {
        Province_Code: '340000',
        longitude: longitude,
        latitude: latitude
      }
      uni.showLoading({
        title: '服务区加载中...'
      })
      const data = await this.$api.$get(
        '/CommercialApi/BaseInfo/GetServerpartList',
        req
      )
      console.log('data321312', data)
      let _data = data.Result_Data.List
      let serverSelectList = []
      if (_data && _data.length > 0) {
        _data.forEach(item => {
          serverSelectList.push({
            ...item,
            showName: item.SERVERPART_NAME,
            ProvinceCode: '340000',
            ServerPart_Id: item.SERVERPART_ID,
            ServerPart_Name: item.SERVERPART_NAME
          })
        })
      }

      this.severPartList = _data
      this.setSeverList(serverSelectList)
      let obj = this.handleChangeServiceInfo(_data[0])
      uni.setStorageSync('currentService', obj) // 当前选中服务区信息
      this.serverPart = obj
      console.log('_this.serverPart2', this.serverPart)
      this.setprovinceCode(obj.ProvinceCode)
      this.setArea(obj)
      this.setOwnerUnitId(obj.OwnerUnitId)

      this.getCouponList()
      this.getStore()
      this.getMall()
      this.getMember()
      uni.hideLoading()
    },
    // 兼容一下老接口要的服务区对象的内容
    handleChangeServiceInfo (obj) {
      let newObj = {
        ...obj,
        Distance: obj.SERVERPART_DISTANCE,
        OwnerUnitId: obj.OWNERUNIT_ID,
        OwnerUnitName: obj.OWNERUNIT_NAME,
        ProvinceCode: '340000',
        ServerPart_Id: obj.SERVERPART_ID,
        ServerPart_Name: obj.SERVERPART_NAME,
        ServerPart_Tel: '',
        ServerPart_X: obj.SERVERPART_X,
        ServerPart_Y: obj.SERVERPART_Y,
        showName: `${obj.SERVERPART_NAME}(${obj.SERVERPART_DISTANCE}km)`
      }
      return newObj
    }
  },
  onShow () {
    let res = uni.getStorageSync('currentService')
    // 如果切换了服务区 那就重新请求数据
    if (res.ServerPart_Id !== this.serverPart.ServerPart_Id) {
      // 切换了服务区的话 就要把精选的地方的数据清空 拿新的数据
      this.storeList = []
      this.cardList = []
      this.mallList = []

      this.currentService = res
      this.serverPart = this.handleChangeServiceInfo(res)
      this.getMember()
      this.handleGetNearService(res.ServerPart_Y, res.ServerPart_X)
    }
  },
  onReady () {
    if (this.canIuse) {
      uni.navigateTo({url: '/pages/register/main'})
    }
  },
  onLoad (option) {
    console.log('onLoad')
    console.log('user', this.user)
    let _this = this
    // uni.getPrivacySetting({
    //   success: res => {
    //     if (res.needAuthorization) {
    //       _this.showPrivacy = true
    //     } else {
    //       _this.showBtn = true
    //       if (option.scene) {
    //         let scene = decodeURIComponent(option.scene)
    //         scene = scene.split('&')

    //         _this.setInvitedCode(scene[0])
    //       }
    //       let systemInfo = uni.getStorageSync('systemInfo')
    //       _this.height = systemInfo.windowHeight + 'px' // (94 / 750 * systemInfo.windowWidth)
    //       let currentService = uni.getStorageSync('currentService')
    //       // 如果缓存中已经有服务区了 就不会用最近的服务区了 就用缓存的服务区去调用
    //       if (!currentService.ServerPart_Id) {
    //         _this.getLocalServer()
    //       } else {
    //         _this.handleGetNearService(currentService.ServerPart_Y, currentService.ServerPart_X)
    //         //   判断之前是不是已经有定位了
    //         let seatInfo = uni.getStorageSync('seatInfo')
    //         if (seatInfo) {
    //           uni.setStorageSync('actualLocation', seatInfo)
    //         }
    //       }
    //     }
    //   },
    //   fail: fail => {
    //     console.log('fail', fail)
    //   }
    // })
  },
  onUnload () {
    this.isShow = false
  },
  onPullDownRefresh () {
    // this.getLocalServer()
    setTimeout(function () {
      uni.stopPullDownRefresh()
    }, 1000)
  }
}
</script>

<style scoped lang="stylus">


.privacyMeng{
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.3);
    z-index: 999998;
}
.privacy{
    position: fixed;
    bottom: 0;
    width: 100vw;
    box-sizing: border-box;
    padding: 40rpx 30rpx;
    z-index: 999999;
    border-top-right-radius: 24px;
    border-top-left-radius: 24px;
    background: #fff;
    .privacyContent{
        .contentTitle{
            font-size: 48rpx;
            font-family: Source Han Sans CN-Bold, Source Han Sans CN;
            font-weight: bold;
            color: #000000;
            line-height: 56rpx;
        }
        .contentWord{
            margin-top: 32rpx;
            text-indent: 2em;
            .tips {
                font-size: 28rpx;
                font-family: Source Han Sans CN-Normal, Source Han Sans CN;
                font-weight: 400;
                color: #8BC21F;
                line-height: 33rpx;
            }
        }
    }
    .btnList{
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        margin-top: 48rpx;
        .btns{
            display: inline-block;
            padding: 0 90rpx;
            border-radius: 15rpx;
        }
        .noAgree{
            background: rgb(242,242,242);
            color: rgb(26,187,107);
            font-weight: 600;
        }
        .agree{
            background: rgb(26,187,107);
            color: #fff;
            font-weight: 600;
        }
    }
}
/*头部搜索*/
  *
    box-sizing: border-box
  .text-red
    color #DB5E50
  .list-box
    height 100%
    background #fff
  .bankspace
    height 88rpx
    position relative
  .severpart-box
    position absolute
    background #fff
    padding-left 24rpx
    font-size 30rpx
    display flex
    align-items flex-end
    right 38rpx
    top 36rpx
    .service-name
      min-width 120rpx
      color #333
      line-height 30rpx
  .movebox
    z-index 1
    transform translateY(-10rpx)
    // transition all .2s
    background #fff
    position relative
  .hxing
    background url(/static/images/hxing2.png) no-repeat center bottom
    height 35rpx
    background-size contain
    position relative
    top -33rpx
    width 100%
    z-index 1
  .swiper-dots
    width 90rpx
    height 20rpx
    display flex
    flex-direction row
    position absolute
    left 50%
    transform translateX(-50%)
    bottom 100rpx

  .dot
    width 30rpx
    height 8rpx
    border-radius 14rpx
    margin-right 12rpx
    background-color #ffffff
    opacity .3
  .active.dot

    background-color #fff
    opacity 1
  .menu-box

    padding 0 32rpx
    display flex
    justify-content space-around
  .user-card
    position absolute
    bottom 6rpx
    width 100%
    z-index 1
  .banner
    background #fff
    height 412rpx
    z-index -1
  .banner image
    width 100%
    height 412rpx
  .banner-text
    width 698rpx
    border-radius 12rpx 12rpx 0   0
    height 94rpx
    // background #383838
    background url(https://eshangtech.com/ShopICO/home-card.png) no-repeat center
    background-size contain
    margin 0 auto
    color #f9e7af
    padding 12rpx 32rpx
    font-size 26rpx
    box-sizing border-box
    display flex
    align-items center
    justify-content space-between
    i
      background url(https://eshangtech.com/ShopICO/vip-ico.png) no-repeat center
      background-size contain
      width 36rpx
      height 36rpx
      margin-right 16rpx
    .ico-vip
      width 36rpx
      height 36rpx
      margin-right 16rpx
    .vip-btn
      width 136rpx
      height 46rpx
      line-height 46rpx
      color #464245
      background linear-gradient(to right,#f9e7af,#f1d798)
      // border 1rpx solid #D5C8A6
      border-radius 23rpx
      margin-left 74rpx
      font-family 'PingFang SC Regular'
      text-align center
  .user-tab
    width 100%
    position absolute
    bottom -100rpx
    z-index 0
    font-family 'PingFang SC Medium'
  .user-tab-content
    width 698rpx
    margin 0 auto
    background-color #383838
    display flex
    align-items center
    justify-content center
    height 114rpx
  .u-t-unit
    font-size 24rpx
    color #D5C59D
    width 40%
    display flex
    align-items center
    // justify-content center
    flex-direction column
    height 100%
  .user-tab-num
    margin-top 8rpx
    color #D5C59D
    font-size 28rpx

  .model-c-menu
    display flex
    flex-direction column
    align-items center
    margin-bottom 32rpx
    padding-top 16rpx
    width 25%

  .model-c-menu span
    font-family "PingFang SC Medium","SimHei"
    font-size 26rpx
    color #484b51
    // font-weight bolder
  .ico,
  .ico-menu
    width 65rpx
    height 60rpx

    position relative
    text-align center
    overflow hidden


  span.ico-t-count
    font-style normal
    color #fff
    border-radius 18px
    min-width 8px
    width auto
    height auto
    padding 2rpx 8rpx
    font-size 20rpx
    line-height 1.2
    text-align center
    white-space nowrap
    background #ed4d3e
    position absolute
    right -4rpx
    top -12rpx

  .canIuse-box
    padding 40rpx
    border-radius 8rpx
    text-align center

  .canIuse-box-title
    font-size 28rpx
    margin-bottom 24rpx
  .hot-block
    background-color #ffffff
    padding 0 30rpx
  .block-title
    font-size 32rpx
    font-weight bolder
    font-family 'PingFang SC Bold'
    color #303030
    display flex
    justify-content space-between
    align-items center
  .mt20
    margin-top 30rpx

  .conpon-img-box
    display flex
    justify-content space-between
    margin-top 16rpx
    padding-bottom 32rpx
    flex-wrap wrap

  .conpon-img image
    width 456rpx
    height 278rpx
    border-radius 4rpx
  .store-img
    box-shadow 1rpx 1rpx 12rpx #eee
    border-radius 10rpx
    margin-bottom 12rpx
    .photo-name
      position relative
      bottom 64rpx
      padding-top 0

  .store-img, .store-img image
    width 339rpx
    height 215rpx


  .store-img:nth-child(n+3),.store-img:nth-child(n+3) image
    width 222rpx
    height 260rpx

  .conpon-img:nth-child(2) image
    width 221rpx
    height 278rpx

  .conpon-img:nth-child(n+3) image,.conpon-img-box li image
    width 221rpx
    height 140rpx
    border-radius 4rp
  .photo-box
    width 718rpx
    overflow hidden
    .store-photo-box
        display flex
        padding-right 32rpx
        padding-bottom 20rpx
        // width 100%
        flex-wrap wrap
        justify-content space-between
        padding-right 24rpx

        .store-photo
            border 2rpx solid #eee
            position relative
            border-radius 12rpx
            margin-top 12rpx

        .photo-name
            position absolute
            bottom 10rpx
            padding-left 10rpx
            padding-top 0

  .store-photo

    box-shadow 0rpx 6rpx 12rpx #e9e9e9
    font-size 0

  .store-photo image

    width 339rpx
    height 215rpx

  .photo-name
    padding-top 20rpx
    font-size 24rpx
    text-align center
    color #5C5C5C
    line-height 1.6
  //  精选商城模块
  .product-photo-box
    border-radius 20rpx
    box-shadow 0rpx 6rpx 18rpx #ddd
    padding 16rpx 0
    height 330rpx
    margin-bottom 60rpx
    margin-top 45rpx
    .swiper-image
      display flex
      align-items center

      height 278rpx
    .product-photo
      width 204rpx
      margin-left 20rpx
      text-align center
      border-radius 0 0 20rpx 20rpx
      background #f7f7f7
      image
        width 100%
        height 162rpx
      .photo-name
        height 116rpx
        background url(https://eshangtech.com/ShopICO/icos/home-pro-bg.png) no-repeat center
        background-size contain
        color #845825
        display flex
        align-items center
        flex-direction column
        padding 0
        .value-text
          width 160rpx
          height 34rpx
          border-radius 4rpx
          background-color #EAC789
          margin-bottom 16rpx
          margin-top 6rpx
          color #fff
          justify-content center
          display flex
          align-items center
    .pro-swiper-dots
      width 90rpx
      height 20rpx
      display flex
      flex-direction row
      margin 12rpx auto 0 auto
    .dot
      width 30rpx
      height 8rpx
      border-radius 14rpx
      margin-right 12rpx
      background-color #ddd
    .active.dot
      background-color #EACC96
  .conpon-list-box

    display flex
    align-items center
    justify-content space-between
    flex-wrap wrap
    padding 0 6rpx
    .store-photo
      width 322rpx
      height 262rpx
      border-radius 16rpx
      margin-bottom 28rpx
      margin-left 0
      image
        width 322rpx
        height 190rpx

  .pop-box
    width 588rpx
    height 256rpx
    text-align center
    padding 40rpx 0
    border-radius 30rpx
    overflow hidden
  .pop-title
    font-size 32rpx
  .pop-body
    font-size 28rpx
    margin-top 36rpx
  .popbtn-box
    display flex
    justify-content center
    align-items center
    margin-top 72rpx
  .popbtn
    height 60rpx
    width 208rpx
    border-radius 32rpx
    text-align center
    font-size 24rpx
    line-height 60rpx
  .popbtn+.popbtn
    margin-left 60rpx
  .cancel-btn
    border 1rpx solid #616161
    color #616161
  .confirm-btn
    background #515151
    color #fff

  //  签到弹出窗口
  .qd-pop
    background url(https://eshangtech.com/ShopICO/home-qd/qdcg.png) no-repeat center
    background-size contain
    height 672rpx
    width 750rpx
    transform translateY(-40%)
    margin 50% auto
    box-sizing border-box
    padding 336rpx 120rpx 0 120rpx
    .qd-pop-days,.qd-pop-img
      display flex
      align-items center
      justify-content space-between
      font-size 22rpx
      color #A3A3A3
      position relative
      margin-top 12rpx
    .qd-pop-img image
      width 36rpx
      height 36rpx
      z-index 1
    .qd-pop-line
      width 450rpx
      height 2rpx
      background #E5E5E7
      display block
      position absolute
      top 17rpx
      left 32rpx
      z-index 0
      box-shadow 0 2rpx 6rpx rgba(155,155,155,0.35)
    .qd-pop-text
      color #4896EB
      font-size 28rpx
      margin 36rpx auto 12rpx auto
      text-align center
    .qd-pop-jf
      display flex
      align-items center
      justify-content center
      font-size 40rpx
      color #363636
      font-weight bold
    .pd-pop-ico
      width 52rpx
      height 52rpx
      margin-right 12rpx
    .qd-pop-tip
      color #AAAFB5
      font-size 26rpx
      text-align center
      margin-top 24rpx
      margin-bottom 60rpx
    .qd-btn
      background url(https://eshangtech.com/ShopICO/home-qd/qd-btn.png) no-repeat center
      background-size contain
      width 348rpx
      height 93rpx
      margin 40rpx auto
      text-align center
      font-size 32rpx
      color #fff
      line-height 92rpx

</style>
