<template>
  <view>
    <zj-page-layout
      :hasFooter="false"
      :isScroll="true"
      :isLoading="isLoading"
      :refresherTriggered="refresherTriggered"
      @refresherrefresh="refresherrefresh"
    >
      <Loading v-if="isError || !isLogin" :type="3" :loadStatus="2" :showText="'加载失败，请下拉重新加载'" />

      <view class="all-container" v-else>
        <!-- 去除商城和服务业务 -->
        <!-- <view class="swiper-container" v-if="bannerList.length > 0">
          <u-swiper
            :list="bannerList"
            keyName="imgSrc"
            autoplay
            circular
            indicator
            indicatorMode="line"
            height="175"
            @click="clickBanner"
          ></u-swiper>
        </view>

        <view class="noticebar-container" v-if="noticeContent">
          <u-notice-bar :text="noticeContent"></u-notice-bar>
        </view>

        <block v-if="categoryList.length > 0">
          <view
            class="service-container card"
            v-for="(item, index) in categoryList.filter(o => o.sub.length > 0)"
            :key="index"
          >
            <view class="home-title">
              <view class="left">{{ item.name }}</view>
              <view class="right" @tap="toClassifyList(item.categoryId)">
                <text class="text">查看更多</text>
                <text class="iconfont icon-jinru"></text>
              </view>
            </view>
            <view class="list">
              <view
                class="item"
                v-for="(it, idx) in item.sub.slice(0, 4)"
                :key="idx"
                @tap="toGoodsList(item.categoryId, it.categoryId, it.name)"
              >
                <image :src="it.imgUrl" mode="aspectFill"></image>
                <text>{{ it.name }}</text>
              </view>
            </view>
          </view>
        </block> -->

        <!-- 自助服务 -->
        <!-- <view class="service-container card">
          <view class="home-title">
            <view class="left">自助服务</view>
            <view class="right" @tap="toWorkorder">
              <text class="text">我的服务单</text>
              <text class="iconfont icon-jinru"></text>
            </view>
          </view>
          <view class="list">
            <view class="item" v-for="(item, index) in serviceList" :key="index" @tap="toPage(item.url)">
              <image :src="item.icon" mode="aspectFill" v-if="item.icon"></image>
              <image
                :src="require(`@/static/images/home/service-icon${item.code}.png`)"
                mode="aspectFill"
                v-else-if="item.code"
              ></image>
              <text>{{ item.title }}</text>
            </view>
            <view class="item" v-if="userInfo.isShowLease" @tap="toPage('/packageHome/pages/service/tenancy')">
              <image :src="require(`@/static/images/home/service-icon5.png`)" mode="aspectFill"></image>
              <text>设备租赁</text>
            </view>
          </view>
        </view> -->

        <!-- 扫码活动 -->
        <view class="swiper2-container" v-if="codeActivityList.length > 0">
          <u-swiper
            :list="codeActivityList"
            keyName="banner"
            autoplay
            circular
            indicator
            indicatorMode="line"
            height="100"
            @click="toCodeActivityList"
          ></u-swiper>
        </view>

        <!-- 增值服务 -->
        <!-- <view class="other-container card" v-if="userInfo.moduleYb">
          <view class="home-title">
            <view class="left">增值服务</view>
          </view>
          <view class="list">
            <view
              class="item"
              v-for="(item, index) in addvalueList.filter(o => !o.root || (o.root && o.root.includes(userInfo.type)))"
              :key="index"
              @tap="item.fn ? toFn(item.fn) : toPage(item.url)"
            >
              <image :src="require(`@/static/images/home/other-icon${item.code}.png`)" mode=""></image>
              <text>{{ item.title }}</text>
            </view>
          </view>
        </view> -->

        <!-- 工程维保服务 -->
        <!-- <view
          class="other-container card"
          v-if="(isWorkerUser || isShowMaintenance) && userInfo.moduleWb && userInfo.mobile"
        >
          <view class="home-title">
            <view class="left">工程维保服务</view>
          </view>
          <view class="list">
            <view
              class="item"
              v-for="(item, index) in maintenanceList"
              :key="index"
              @tap="item.fn ? toFn(item.fn) : toPage(item.url)"
            >
              <image :src="require(`@/static/images/home/other-icon${item.code}.png`)" mode=""></image>
              <text>{{ item.title }}</text>
            </view>
          </view>
        </view> -->

        <!-- 二手商城 -->
        <!-- <view class="other-container card" v-if="(isServiceUser || isWorkerUser) && userInfo.moduleEs">
          <view class="home-title">
            <view class="left">二手商城</view>
          </view>
          <view class="list">
            <view
              class="item"
              v-for="(item, index) in recycleList.filter(
                o => !o.root || (o.root == 1 && userInfo.isEs) || (o.root == 2 && !userInfo.isEs)
              )"
              :key="index"
              @tap="item.fn ? toFn(item.fn) : toPage(item.url)"
            >
              <image :src="require(`@/static/images/home/other-icon${item.code}.png`)" mode=""></image>
              <text>{{ item.title }}</text>
            </view>
          </view>
        </view> -->

        <!-- 分享收益 -->
        <!-- <view class="share-container card" v-if="isServiceUser || isWorkerUser">
          <view class="home-title">
            <view class="left">分享收益</view>
            <view class="right" @tap="toPage(`/packageMine/pages/order/list?tab=`)">
              <text class="text">我的订单</text>
              <text class="iconfont icon-jinru"></text>
            </view>
          </view>
          <view class="list">
            <view class="item" @tap="toMall()">
              <image src="@/static/images/home/share-icon1.png"></image>
              <view class="text">分销商城</view>
            </view>
            <view class="item" @tap="toActivityList(5)">
              <image src="@/static/images/home/share-icon2.png"></image>
              <view class="text">活动专区</view>
            </view>
          </view>
        </view> -->

        <!-- 工单管理 -->
        <view class="order-container card">
          <view class="home-title">
            <view class="left">工单管理</view>
          </view>
          <view class="list">
            <view
              class="item"
              v-for="(item, index) in orderList"
              :key="index"
              @tap="
                toPage(
                  !userInfo.mobile
                    ? '/packageMine/pages/phone'
                    : !userInfo.workerNumber
                    ? '/packageMine/pages/myWebsit'
                    : item.url
                )
              "
            >
              <image :src="require(`@/static/images/home/order-icon${item.code}.png`)" mode=""></image>
              <text>{{ item.title }}</text>
            </view>
          </view>
        </view>

        <!-- 其他 -->
        <view class="other-container card">
          <view class="home-title">
            <view class="left">辅材</view>
            <view
              class="right"
              @tap="
                toPage(
                  !userInfo.mobile
                    ? '/packageMine/pages/phone'
                    : !userInfo.workerNumber
                    ? '/packageMine/pages/myWebsit'
                    : `/packageMaterial/pages/index?type=M`
                )
              "
            >
              <text class="text">查看详细</text>
              <text class="iconfont icon-jinru"></text>
            </view>
          </view>
          <view class="list">
            <view
              class="item"
              v-for="(item, index) in otherList"
              :key="index"
              @tap="
                toPage(
                  !userInfo.mobile
                    ? '/packageMine/pages/phone'
                    : !userInfo.workerNumber
                    ? '/packageMine/pages/myWebsit'
                    : item.url
                )
              "
            >
              <image :src="require(`@/static/images/home/other-icon${item.code}.png`)" mode=""></image>
              <text>{{ item.title }}</text>
            </view>
          </view>
        </view>

        <view class="other-container card">
          <view class="home-title">
            <view class="left">配件</view>
            <view
              class="right"
              @tap="
                toPage(
                  !userInfo.mobile
                    ? '/packageMine/pages/phone'
                    : !userInfo.workerNumber
                    ? '/packageMine/pages/myWebsit'
                    : `/packageMaterial/pages/index?type=P`
                )
              "
            >
              <text class="text">查看详细</text>
              <text class="iconfont icon-jinru"></text>
            </view>
          </view>
          <view class="list">
            <view
              class="item"
              v-for="(item, index) in otherList2"
              :key="index"
              @tap="
                toPage(
                  !userInfo.mobile
                    ? '/packageMine/pages/phone'
                    : !userInfo.workerNumber
                    ? '/packageMine/pages/myWebsit'
                    : item.url
                )
              "
            >
              <image :src="require(`@/static/images/home/other-icon${item.code}.png`)" mode=""></image>
              <text>{{ item.title }}</text>
            </view>
          </view>
        </view>

        <!-- 联系我们 -->
        <view class="contact-container card">
          <view class="home-title">
            <view class="left">联系我们</view>
          </view>
          <view class="list">
            <!-- <button open-type="contact" class="item bb">
							<image src="@/static/images/home/home-icon1.png"></image>
							<view class="title">在线客服</view>
              <text class="iconfont icon-jinru"></text>
						</button> -->
            <view class="item" :class="isShowContact1 ? '' : 'bb'" @tap="isShowContact1 = !isShowContact1">
              <image src="@/static/images/home/home-icon2.png"></image>
              <view class="title">服务网点</view>
              <text class="iconfont icon-jinru"></text>
            </view>
            <view class="wrap1" v-if="isShowContact1">
              <view class="it" v-for="(item, index) in websitList" :key="index">
                <view class="top">
                  <view class="left">{{ item.name }} {{ item.websitPhone || '' }}</view>
                  <view class="right" @tap="$callPhone(item.websitPhone)" v-if="item.websitPhone"
                    ><text class="iconfont icon-call"></text
                  ></view>
                </view>
                <view class="address">{{ item.address }}</view>
              </view>
            </view>
            <view class="item" @tap="isShowContact2 = !isShowContact2">
              <image src="@/static/images/home/home-icon3.png"></image>
              <view class="title">投诉热线</view>
              <text class="iconfont icon-jinru"></text>
            </view>
            <view class="wrap2" v-if="isShowContact2">
              <view class="left">投诉电话：{{ userInfo.companyWechatMobile || '暂无' }}</view>
              <view class="right" @tap="$callPhone(userInfo.companyWechatMobile)" v-if="userInfo.companyWechatMobile"
                ><text class="iconfont icon-call"></text
              ></view>
            </view>
          </view>
        </view>
      </view>
    </zj-page-layout>

    <!-- <view class="dialog-container" v-if="couponDialogImgUrl && isShowCouponDialog">
			<uni-transition ref="dialog" mode-class="zoom-in" :duration="500" :show="couponDialogImgUrl && isShowCouponDialog">
				<image class="image" :src="couponDialogImgUrl" mode="widthFix" @tap="handleCoupon()"></image>
			</uni-transition>
			<uni-transition ref="dialogBtn" mode-class="fade" :duration="500" :show="couponDialogImgUrl && isShowCouponDialog">
				<text class="iconfont icon-close2" @tap="closeDialog()"></text>
			</uni-transition>
		</view> -->

    <view class="top-tooltip" v-if="isShowTopTooltip">
      <view class="content">
        <view class="left">
          <view>点击<text class="iconfont icon-gengduo"></text>添加到我的小程序</view>
          <view>微信下拉使用更方便哟！</view>
        </view>
        <text class="iconfont icon-close2 close" @tap="isShowTopTooltip = false"></text>
      </view>
      <view class="arrow"></view>
    </view>

    <view class="bottom-tooltip" v-if="isShowBottomTooltip">
      <view class="left">
        <text class="iconfont icon-close2 close" @tap="isShowBottomTooltip = false"></text>
        <view class="text">关注公众号及时获取服务进度</view>
      </view>
      <view class="btn" @tap="toWxLink()">前往关注</view>
    </view>
  </view>
</template>

<script>
import { getNoticeNum, getOrderNum, selectionChange } from '@/common/utils/util.js'

export default {
  data() {
    return {
      isLoading: true,
      refresherTriggered: false, // 下拉刷新状态
      userInfo: {},
      configInfo: {},
      scene: {
        // 页面参数（扫码进入小程序时产生）
        type: '',
        goodsId: '',
        orderId: '',
        serviceId: '',
        couponId: ''
      },
      isCouponDialog: false, // 是否显示过期优惠券弹窗
      isReceiveDialog: false,
      isSmsReceive: false,

      isShowTopTooltip: false,
      isShowBottomTooltip: false,

      noticeContent: '', // 公告内容

      categoryList: [],
      serviceList: [],
      baseServiceList: [
        // 自助服务列表
        { code: 3, title: '收费标准', url: `/packageHome/pages/service/chargeStandard` },
        { code: 4, title: '故障自查', url: `/packageHome/pages/service/troubleshoot` }
      ],
      addvalueList: [
        // 增值服务列表
        { code: 1, title: '延保服务', fn: 'toServiceIndex' },
        { code: 2, title: '我的延保', url: `/packageHome/pages/addvalue/orderList` },
        { code: 3, title: '服务记录', fn: `toServiceRecods` },
        { code: 3, title: '延保查询', url: `/packageHome/pages/addvalue/check`, root: ['WORKER'] }
      ],
      maintenanceList: [
        // 工程维保服务列表
        { code: 1, title: '创建维保单', fn: `toMaintenanceCreate` },
        { code: 2, title: '维保单记录', fn: `toMaintenanceRecods` },
        { code: 3, title: '费用申请单', url: `/packageHome/pages/maintenance/applyList` }
      ],
      recycleList: [
        { code: 1, title: '二手商城', url: `/packageHome/pages/recycle/index`, root: 0 },
        { code: 2, title: '已发布的', url: `/packageHome/pages/recycle/issue/list`, root: 1 },
        { code: 3, title: '我买到的', url: `/packageHome/pages/recycle/order/list`, root: 2 }
      ],
      orderList: [
        // 工单管理列表
        { code: 1, title: '待接单', url: `/packageWorkorder/pages/orderList?tab=DJD` },
        { code: 2, title: '服务中', url: `/packageWorkorder/pages/orderList?tab=FWZ` },
        { code: 3, title: '已完成', url: `/packageWorkorder/pages/orderList?tab=YWG` },
        { code: 4, title: '异常单', url: `/packageWorkorder/pages/orderList?tab=YCD` }
      ],
      otherList: [
        // 其他列表
        { code: 1, title: '辅材管理', url: `/packageMaterial/pages/stock/index` },
        { code: 2, title: '辅材收款', url: `/packageMaterial/pages/sale/index?type=M` }
      ],
      otherList2: [
        // 其他列表
        { code: 1, title: '配件管理', url: `/packageAttachment/pages/fittingsManagement/index` },
        { code: 2, title: '配件收款', url: `/packageMaterial/pages/newSale/index?type=P` }
      ],
      bannerList: [], // 轮播图列表
      couponList: [], // 可领取优惠券列表

      codeActivityList: [],

      couponDialogImgUrl: '',
      isShowCouponDialog: true,

      isError: false,

      websitList: [],
      isShowContact1: false,
      isShowContact2: false,

      isShowMaintenance: false
    }
  },

  computed: {
    isLogin() {
      return this.$store.state.user.token ? true : false
    },
    isServiceUser() {
      // 是否业务员
      return this.userInfo && this.userInfo.type === 'SERVICE'
    },
    isWorkerUser() {
      // 是否师傅
      return this.userInfo && this.userInfo.type === 'WORKER'
    }
  },

  async onShow() {
    selectionChange()

    try {
      await this.$onLaunched

      this.configInfo = await this.$getConfigInfo()
      await this.getBannerList()
      this.getNoticebar()

      if (this.isLogin) {
        this.userInfo = await this.$getUserInfo()
        this.isShowMaintenance = await this.checkMaintenance()
        this.getCategoryList()
        this.getServiceList()
        this.getCouponList()
        this.getWebsitList()
        this.getCodeActivityList()

        getNoticeNum()
        getOrderNum()
      }

      this.$nextTick(() => {
        this.isError = false
        this.isLoading = false
        this.refresherTriggered = false
      })
    } catch {
      this.isError = true
      this.isLoading = false
    }
  },

  async onLoad({
    scene, // 扫码进入的参数
    goodsId, // 商品id
    serviceId, // 业务员id
    smsServiceId, // 短信业务员id
    otherType, // 类型：groupbuyList=团购活动，activityList=专区活动，orderList=订单列表，workOrderList=工单列表，couponList=优惠券列表，workOrderDetail
    activityType, // 专区活动类型
    appOrderId, // 师傅端app订单id（下单支付）
    orderId, // 订单id（进入订单详情）
    workOrderId, // 工单id（进入工单详情）
    workOrderTypeId,
    workOrderType,
    workOrderImgUrl,
    mpOpenId,
    type,
    objId,
    isYB,
    isWB,
    sharerOpenId
  }) {
    await this.$onLaunched

    setTimeout(() => {
      this.isShowTopTooltip = false
      this.isShowBottomTooltip = false
    }, 10000)

    if (this.isLogin) {
      this.checkCoupon()
    }

    if (mpOpenId) {
      uni.login({
        provider: 'weixin',
        success: loginRes => {
          this.$api.post('/user/auth', {
            code: loginRes.code,
            mpOpenId: mpOpenId
          })
        }
      })
    }

    if (sharerOpenId) {
      this.$api
        .post('/user/bind', {
          serviceOpenId: sharerOpenId,
          userId: this.$store.state.user.userId
        })
        .then(res => {
          console.log('绑定成功：' + res.message)
        })
    }

    // 点击短信链接进入小程序
    if (smsServiceId) {
      this.bindUser(smsServiceId)
      if (this.userInfo.type !== 'SERVICE') {
        this.isSmsReceive = true
        this.isReceiveDialog = true
      }
    }

    // 从链接进入小程序
    if (serviceId) {
      this.bindUser(serviceId)
    }

    if (goodsId) {
      setTimeout(() => {
        this.toGoodsDetail(goodsId)
      }, 1000)
    }

    if (isYB) {
      setTimeout(() => {
        this.toServiceIndex()
      }, 1000)
    }

    if (isWB) {
      setTimeout(() => {
        this.toMaintenanceCreate()
      }, 1000)
    }

    if (otherType) {
      // 团购列表
      if (otherType === 'groupbuyList') {
        this.navToPage('/packageMine/pages/groupbuy/list')
      }
      // 活动专区列表
      if (otherType === 'activityList') {
        this.navToPage('/packageGoods/pages/activity?type=' + activityType)
      }
      // 订单列表
      if (otherType === 'orderList') {
        this.navToPage('/packageMine/pages/order/list')
      }
      // 工单列表
      if (otherType === 'workOrderList') {
        this.navToPage('/packageMine/pages/workOrder/list')
      }
      // 优惠券列表
      if (otherType === 'couponList') {
        this.navToPage('/packageMine/pages/coupon/list')
      }
    }

    if (orderId) {
      this.navToPage(`/packageMine/pages/order/detail?orderId=${orderId}`)
    } else if (workOrderId && workOrderTypeId && workOrderType) {
      workOrderType = workOrderType.replace(/\\\\/g, '\\')
      this.navToPage(
        `/packageMine/pages/workOrder/detail?id=${workOrderTypeId}&type=${workOrderType}&orderNo=${workOrderId}`
      )
    } else if (workOrderId) {
      this.navToPage(`/packageMine/pages/workOrder/list`)
    } else if (workOrderImgUrl) {
      this.navToPage(`/packageMine/pages/workOrder/receipt?imgurl=${workOrderImgUrl}`)
    }

    // 扫码进入小程序
    if (scene) {
      console.log(scene)
      // 拿scene的id去获取
      this.$api
        .get('/common/scene', {
          scene: scene
        })
        .then(res => {
          let newScene = res.data.split('&')
          this.scene.type = newScene[0]
          this.scene.serviceId = newScene[2] || ''
          // 如果是商品
          if (newScene[0] == 'goods') {
            this.scene.goodsId = newScene[1]
            this.toGoodsDetail(this.scene.goodsId)
          }
          // 如果是优惠券
          else if (newScene[0] == 'coupon') {
            this.scene.couponId = newScene[1]
            this.isReceiveDialog = true
            // this.receiveCoupon(this.scene.couponId);
          }
          // 如果是团购分享码
          else if (newScene[0] == 'promotion_group') {
            this.navToPage('/packageMine/pages/groupbuy/list')
          }
          // 如果是活动专区分享码
          else if (newScene[0] == 'HDZQ') {
            this.navToPage('/packageGoods/pages/activity?type=' + newScene[1])
          }
          // 如果是工程维保
          else if (newScene[0] == 'ENGIN_PROJECT_REPAIR') {
            this.$navToPage({
              url: `/packageHome/pages/maintenance/create?projectId=${newScene[1]}`
            })
          }

          console.log(this.scene)
          if (this.scene.serviceId) {
            this.bindUser(this.scene.serviceId)
          }
        })
    }
  },

  methods: {
    // 获取公告栏
    getNoticebar() {
      this.$api.get('/shpping/cart/notice').then(res => {
        this.noticeContent = res.data
      })
    },

    // 触发下拉刷新
    async refresherrefresh(e) {
      this.refresherTriggered = true

      this.configInfo = await this.$getConfigInfo()
      await this.getBannerList()

      if (this.isLogin) {
        this.userInfo = await this.$getUserInfo()
        this.getCategoryList()
        this.getServiceList()
        this.getCouponList()
        this.getWebsitList()
        this.getCodeActivityList()
      } else {
        await this.wxLogin()
        this.userInfo = await this.$getUserInfo()
        this.getCategoryList()
        this.getServiceList()
        this.getCouponList()
        this.getWebsitList()
        this.getCodeActivityList()
      }

      this.$nextTick(() => {
        this.$isResolve()
        this.isError = false
        this.refresherTriggered = false
      })
    },

    async wxLogin() {
      return new Promise((resolve, reject) => {
        uni.login({
          provider: 'weixin',
          success: loginRes => {
            this.$api
              .post('/user/auth', {
                code: loginRes.code
              })
              .then(async res => {
                this.$store.commit('user/set_token', res.data.token)
                this.$store.commit('user/set_openId', res.data.openId)
                this.$store.commit('user/set_name', res.data.nickName)
                this.$store.commit('user/set_avatar', res.data.avatar)
                this.$store.commit('user/set_userId', res.data.userId)
                if (res.data.mobile) {
                  this.$store.commit('user/set_mobile', res.data.mobile)
                }
                if (!res.data.avatar || !res.data.nickName) {
                  await this.saveUserInfo(res.data)
                }
                resolve(1)
              })
              .catch(() => {
                this.refresherTriggered = false
                reject(0)
              })
          }
        })
      })
    },

    // 保存用户信息
    async saveUserInfo(userInfo) {
      let randomNum = new Date().getTime().toString().substr(-6)
      let configInfo = await this.$getConfigInfo()
      return new Promise((resolve, reject) => {
        this.$api
          .post('/user/userinfo/save', {
            userId: userInfo.userId,
            avatarUrl: configInfo.minLogo3,
            nickName: `微信用户_${randomNum}`
          })
          .then(res => {
            resolve(res.data)
          })
      })
    },

    getCategoryList() {
      this.$api
        .get('/goods/category/list/all', {
          isServiceShow: true
        })
        .then(res => {
          this.categoryList = res.data
        })
    },

    getServiceList() {
      this.$api.post('/pg/order/base/type/list').then(res => {
        let list = res.data.map(item => {
          return {
            title: item.orderSmallTypeText,
            icon: item.imgUrl,
            url: `/packageWorkorder/pages/create/index?typeId=${item.id}&typeName=${item.orderSmallTypeText}`
          }
        })
        this.serviceList = [...list, ...this.baseServiceList]
      })
    },

    getWebsitList() {
      this.$api
        .get('/user/apply/websit', {
          isAll: false
        })
        .then(res => {
          this.websitList = res.data || []
        })
    },

    toPage(url) {
      if (!url) return this.$toast('敬请期待～')

      this.navToPage(url)
    },

    toFn(fn) {
      if (!fn) return this.$toast('敬请期待～')

      this[fn]()
    },

    toServiceIndex() {
      if (this.isWorkerUser) {
        this.navToPage(`/packageHome/pages/addvalue/serviceBuy`)
      } else {
        this.navToPage(`/packageHome/pages/addvalue/explainList`)
      }
    },

    toServiceRecods() {
      if (this.isWorkerUser) {
        this.navToPage(`/packageWorkorder/pages/orderList?isYb=true`)
      } else {
        this.navToPage(`/packageWorkorder/pages/userWorkorderList`)
      }
    },

    async checkMaintenance() {
      const hasApply = await this.$api
        .post('/engin/material/list/page', {
          pageNum: 1,
          pageSize: -1,
          examineStatus: ''
        })
        .then(res => {
          return res.data.records && res.data.records.length > 0
        })
      const hasOrder = await this.$api
        .post('/pg/order/base/list', {
          pageNum: 1,
          pageSize: -1,
          isWb: true
        })
        .then(res => {
          return res.data.records && res.data.records.length > 0
        })

      return hasApply || hasOrder
    },

    toMaintenanceCreate() {
      if ((this.isWorkerUser || this.isShowMaintenance) && this.userInfo.mobile) {
        this.navToPage(`/packageHome/pages/maintenance/create`)
      } else {
        this.$tips('您暂无维保工程')
      }
    },

    toMaintenanceRecods() {
      if (this.isWorkerUser) {
        this.navToPage(`/packageWorkorder/pages/orderList?isWb=true`)
      } else {
        this.navToPage(`/packageWorkorder/pages/userWorkorderList?isWb=1`)
      }
    },

    toMall() {
      this.$navToPage(
        {
          url: '/pages/goods/index'
        },
        'switchTab'
      )
    },

    // 获取轮播图列表
    async getBannerList() {
      return new Promise((resolve, reject) => {
        this.$api
          .get('/common/list/page', {
            pageNum: 1,
            pageSize: 10,
            state: true,
            port: 'SHOP'
          })
          .then(res => {
            this.bannerList = res.data.records
            resolve(1)
          })
          .catch(res => {
            reject(0)
          })
      })
    },

    // 点击轮播图
    clickBanner(index) {
      let item = this.bannerList[index]
      if (item.type == 3) {
        this.toActivityList(item.goodsId)
      } else {
        this.toGoodsDetail(item.goodsId)
      }
    },

    // 获取扫码活动列表
    async getCodeActivityList() {
      return new Promise((resolve, reject) => {
        this.$api
          .post('/promotion/questionnaire/list', {
            state: 1
          })
          .then(res => {
            this.codeActivityList = res.data
            resolve(1)
          })
          .catch(res => {
            reject(0)
          })
      })
    },

    // 获取可领优惠券列表
    getCouponList() {
      this.$api
        .get('/coupon/list/all', {
          userId: this.$store.state.user.userId
        })
        .then(res => {
          this.couponList = res.data.filter(item => {
            return item.obtainType === 1
          })
          if (this.couponList && this.couponList.length > 0) {
            this.couponDialogImgUrl = this.couponList[0].imgSrc
          }
        })
    },

    // 关闭弹窗
    closeDialog() {
      this.$refs.dialog.step(
        {
          scale: 0
        },
        {
          duration: 400
        }
      )
      this.$refs.dialog.run(() => {
        this.isShowCouponDialog = false
      })
      this.$refs.dialogBtn.step(
        {
          scale: 0
        },
        {
          duration: 400
        }
      )
      this.$refs.dialogBtn.run(() => {
        this.isShowCouponDialog = false
      })
    },

    // 领取优惠券
    handleCoupon() {
      let ids = this.couponList.map(item => {
        return item.couponId
      })
      this.$api
        .post('/coupon/obtain', {
          userId: this.$store.state.user.userId,
          couponIds: ids.join(',')
        })
        .then(res => {
          this.closeDialog()
          setTimeout(() => {
            this.$tips('优惠券领取成功，请及时使用!')
          }, 500)
        })
    },

    // 进入商品详情
    toGoodsDetail(id) {
      if (!id) {
        return false
      }
      this.$navToPage({
        url: '/packageGoods/pages/detail?id=' + id
      })
    },

    // 进入活动列表
    toActivityList(type) {
      this.$navToPage({
        url: '/packageGoods/pages/activity?type=' + type
      })
    },

    // 进入扫码活动列表
    toCodeActivityList() {
      this.$navToPage({
        url: '/packageHome/pages/codeActivity/activityList'
      })
    },

    // 绑定用户关系
    bindUser(serviceId) {
      this.$api
        .post('/user/bind', {
          serviceId: serviceId,
          userId: this.$store.state.user.userId
        })
        .then(res => {
          console.log('绑定成功：' + res.message)
        })
    },

    // 去分类列表
    toClassifyList(categoryId) {
      this.navToPage(`/packageGoods/pages/classify?categoryId=${categoryId}`)
    },

    // 点击二级分类
    toGoodsList(pid, cid, cname) {
      this.$navToPage({
        url: `/packageGoods/pages/list?pid=${pid}&cid=${cid}&cname=${cname}`
      })
    },

    // 进入商品详情
    toGoodsDetail(id) {
      if (!id) {
        return false
      }
      this.$navToPage({
        url: '/packageGoods/pages/detail?id=' + id
      })
    },

    // 检查是否有优惠券过期
    checkCoupon() {
      this.$api.get('/coupon/timeout').then(res => {
        if (res.data) {
          this.isCouponDialog = true
        }
      })
    },

    // 进入我的优惠券
    toMyCoupon() {
      this.isCouponDialog = false
      this.navToPage('/packageMine/pages/coupon/list')
    },

    // 领取优惠券
    receiveCoupon(id) {
      if (!this.isLogin) {
        return this.navToPage('/pages/login/indexs')
      }

      if (this.isSmsReceive) {
        this.$api
          .get('/coupon/obtain')
          .then(res => {
            this.isReceiveDialog = false
            this.$modal({
              content: '领取成功',
              confirmText: '去看看'
            })
              .then(() => {
                this.toMyCoupon()
              })
              .catch(() => {})
          })
          .catch(res => {
            this.isReceiveDialog = false
            this.$tips(`领取失败：${res.message}`)
          })
      } else {
        this.$api
          .get('/coupon/transfer/coupon2', {
            userCouponId: this.scene.couponId,
            shareUserId: this.scene.serviceId
          })
          .then(res => {
            this.isReceiveDialog = false
            this.$modal({
              content: '领取成功',
              confirmText: '去看看'
            })
              .then(() => {
                this.toMyCoupon()
              })
              .catch(() => {})
          })
          .catch(res => {
            this.isReceiveDialog = false
            this.$tips(`领取失败：${res.message}`)
          })
      }
    },

    // 跳转微信公众号链接
    toWxLink() {
      let link = this.configInfo.pubOfficeAddr
      if (!link) return false
      this.navToPage('/pages/index/webview?link=' + link)
    },

    navToPage(url) {
      this.$navToPage({
        url
      })
    },

    toWorkorder() {
      this.$navToPage({
        url: `/packageWorkorder/pages/userWorkorderList`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.all-container {
  box-sizing: border-box;
  padding: 1rpx 20rpx 20rpx;
}

.top-tooltip {
  width: 390rpx;
  transform-origin: center bottom;
  z-index: 1025;
  position: fixed;
  top: 20rpx;
  right: 20rpx;
  background: rgba(0, 0, 0, 0.8);
  min-width: 150px;
  border-radius: 8rpx;
  padding: 15rpx 20rpx;
  color: #ffffff;
  text-align: justify;
  box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.1);
  word-break: break-all;
  box-sizing: border-box;
  .content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .left {
      view {
        color: #ffffff;
        font-size: 24rpx;
        display: flex;
        align-items: center;
        &:last-child {
          margin-top: 8rpx;
        }
      }
      .iconfont {
        color: #ffffff;
        font-size: 36rpx;
        margin: 0 4rpx;
      }
    }
    .close {
      flex-shrink: 0;
      font-size: 34rpx;
      color: #ffffff;
      margin-left: 20rpx;
    }
  }
  .arrow {
    top: -6px;
    right: 110rpx;
    margin-right: 3px;
    border-top-width: 0;
    border-bottom-color: #ebeef5;
    border-width: 6px;
    filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
    position: absolute;
    display: block;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    &::after {
      position: absolute;
      display: block;
      width: 0;
      height: 0;
      border-color: transparent;
      border-style: solid;
      top: -12px;
      margin-left: -6px;
      border-top-width: 0;
      border-bottom-color: rgba(0, 0, 0, 0.8);
      content: ' ';
      border-width: 6px;
    }
  }
}

.bottom-tooltip {
  z-index: 1025;
  position: fixed;
  bottom: 20rpx;
  left: 20rpx;
  width: 710rpx;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72rpx;
  padding: 0 20rpx 0 30rpx;
  box-sizing: border-box;
  .left {
    display: flex;
    align-items: center;
    .close {
      font-size: 34rpx;
      color: #ffffff;
    }
    .text {
      font-size: 24rpx;
      color: #ffffff;
      margin-left: 16rpx;
    }
  }
  .btn {
    font-size: 24rpx;
    color: #ffffff;
    background: #ff3f42;
    padding: 0 16rpx;
    height: 48rpx;
    line-height: 48rpx;
    border-radius: 48rpx;
  }
}

.home-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .left {
    font-size: 34rpx;
    color: $main-font;
    font-weight: bold;
  }
  .right {
    display: flex;
    align-items: center;
    .text {
      color: $sec-font;
      font-size: 28rpx;
    }
    .iconfont {
      font-size: 24rpx;
      color: $sec-font;
      margin-left: 8rpx;
    }
  }
}
.home-container {
  background: #f5f5f5;
}

.all-container {
  padding: 1rpx 20rpx 20rpx;
}

.card {
  @include zj-card;
  padding: 30rpx;
  margin-top: 20rpx;
  background: linear-gradient(180deg, #f3f9fe 0%, #ffffff 100%);
}

.swiper-container {
  @include zj-card;
  margin-top: 20rpx;
  padding: 0 20rpx;
  ::v-deep .u-swiper {
    height: 350rpx !important;
    .u-swiper__wrapper {
      height: 350rpx !important;
    }
    .u-swiper__wrapper__item__wrapper__image {
      height: 350rpx !important;
    }
  }
}

.swiper2-container {
  @include zj-card;
  position: relative;
  margin-top: 20rpx;
  ::v-deep .u-swiper {
    height: 188rpx !important;
    .u-swiper__wrapper {
      height: 188rpx !important;
    }
    .u-swiper__wrapper__item__wrapper__image {
      height: 188rpx !important;
    }
  }
}

.noticebar-container {
  margin-top: 30rpx;
}

.service-container {
  padding: 0;
  .home-title {
    padding: 30rpx 30rpx 0;
  }
  .list {
    display: flex;
    margin-top: 40rpx;
    flex-wrap: wrap;
    padding-bottom: 30rpx;
    .item {
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      box-sizing: border-box;
      margin-bottom: 20rpx;
      &:nth-child(5),
      &:nth-child(6),
      &:nth-child(7),
      &:nth-child(8) {
        margin-bottom: 0;
      }
      image {
        width: 76rpx;
        height: 76rpx;
      }
      text {
        font-size: 26rpx;
        font-weight: 500;
        margin-top: 16rpx;
      }
    }
  }
}

.share-container {
  .list {
    display: flex;
    margin-top: 40rpx;
    .item {
      flex: 1;
      padding: 20rpx;
      border-radius: 12rpx;
      display: flex;
      align-items: center;
      image {
        flex-shrink: 0;
        width: 88rpx;
        height: 88rpx;
      }
      .text {
        margin-left: 20rpx;
        font-size: 32rpx;
      }
      &:first-child {
        margin-right: 30rpx;
        background: #e8f5fe;
        .text {
          color: #6ca2f8;
        }
      }
      &:last-child {
        background: #fff9f4;
        .text {
          color: #d87e3b;
        }
      }
    }
  }
}

.order-container {
  .list {
    display: flex;
    justify-content: space-between;
    margin-top: 40rpx;
    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      box-sizing: border-box;
      padding: 0 10rpx;
      image {
        width: 76rpx;
        height: 76rpx;
      }
      text {
        font-size: 26rpx;
        font-weight: 500;
        margin-top: 16rpx;
      }
    }
  }
}

.other-container {
  padding: 30rpx 0;
  .home-title {
    padding: 0 30rpx;
  }
  .list {
    display: flex;
    margin-top: 40rpx;
    .item {
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      box-sizing: border-box;
      padding: 0 10rpx;
      image {
        width: 76rpx;
        height: 76rpx;
      }
      text {
        font-size: 26rpx;
        font-weight: 500;
        margin-top: 16rpx;
      }
    }
  }
}

.contact-container {
  .list {
    margin-top: 20rpx;
    .item {
      display: flex;
      align-items: center;
      height: 100rpx;
      background: none;
      padding: 0;
      &.bb {
        border-bottom: 1px solid #eaeaea;
      }
      &::after {
        border: none;
      }
      image {
        width: 44rpx;
        height: 44rpx;
        margin-right: 20rpx;
      }
      .title {
        flex: 1;
        font-size: 30rpx;
        font-weight: 500;
        text-align: left;
        line-height: 1;
      }
      .iconfont {
        font-size: 26rpx;
        color: $sec-font;
      }
    }
    .wrap1 {
      border-bottom: 1px solid #eaeaea;
      padding-bottom: 20rpx;
      padding-left: 60rpx;
      .it {
        padding: 20rpx 0;
        border-bottom: 1px solid #f5f5f5;
        &:last-child {
          border-bottom: none;
        }
        .top {
          display: flex;
          align-items: center;
          justify-content: space-between;
          .left {
            font-size: 28rpx;
          }
          .right {
            .iconfont {
              font-size: 36rpx;
              color: $theme-color;
            }
          }
        }
        .address {
          margin-top: 12rpx;
          font-size: 28rpx;
          color: $sec-font;
        }
      }
    }
    .wrap2 {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-left: 60rpx;
      .left {
        font-size: 28rpx;
      }
      .right {
        .iconfont {
          font-size: 36rpx;
          color: $theme-color;
        }
      }
    }
  }
}

.dialog-container {
  position: fixed;
  z-index: 1000000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba($color: #000000, $alpha: 0.6);
  .image {
    width: 600rpx;
    display: block;
    border-radius: 20rpx;
    margin-top: 40rpx;
  }
  .iconfont {
    font-size: 68rpx;
    color: #ffffff;
    margin-top: 40rpx;
  }
}
</style>

<style>
::-webkit-scrollbar {
  display: none;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none;
  background: transparent;
  color: transparent;
}
</style>
