<template>
  <view class="content">
    <view class="bg-box">
      <view class="homo-title">首页</view>
      <image class="bg-logo" style="width: 200rpx; height: 170rpx" src="/static/adminImg/bg-logo.png"></image>
      <image class="bg-hi" style="width: 130rpx; height: 50rpx" src="/static/adminImg/logo-hi.png"></image>
      <view style="height: 150rpx"></view>
      <view class="tip">欢迎使用,张三</view>
      <view class="desc">欢迎使用巡检管理员端</view>
      <view class="card">
        <view class="card-item">
          <view class="item-title">区域数量 </view>
          <view class="item-totel">{{ form.areaCount }} </view>
          <image class="card-img" style="width: 130rpx; height: 130rpx" src="/static/adminImg/card1.png"></image>
        </view>
        <view class="card-item">
          <view class="item-title">子区域数量 </view>
          <view class="item-totel">{{ form.regionCount }} </view>
          <image class="card-img" style="width: 130rpx; height: 130rpx" src="/static/adminImg/card2.png"></image>
        </view>
        <view class="card-item">
          <view class="item-title">已绑定子区域数 </view>
          <view class="item-totel">{{ form.bindnfc }} </view>
          <image class="card-img" style="width: 130rpx; height: 130rpx" src="/static/adminImg/card3.png"></image>
        </view>
        <view class="card-item">
          <view class="item-title">未绑定子区域数 </view>
          <view class="item-totel">{{ form.noBindnfc }} </view>
          <image class="card-img" style="width: 130rpx; height: 130rpx" src="/static/adminImg/card4.png"></image>
        </view>
      </view>
      <view v-if="false" style="display: flex">
        <u-button type="error" @click="testFn">调试录入卡片</u-button>
      </view>
    </view>
    <u-tabbar :list="vuex_tabbar" :border-top="false"></u-tabbar>
  </view>
</template>
<script>
import { GetHomeDataApi } from '@/api/apiAdmin'
export default {
  data() {
    return {
      form: {
        regionCount: 0,
        areaCount: 0,
        bindnfc: 0,
        noBindnfc: 0
      }
    }
  },
  mounted() {
    uni.hideLoading() // 关闭 Loading
  },
  onLoad() {
    uni.$off('reset')
    uni.$on('reset', () => {
      console.log('%c%s', 'color:red', 'reset')
      this.getDataFn()
    })
  },
  onShow() {
    this.getDataFn()
    console.log('%c%s', 'color:red', 'onSHow')
  },
  methods: {
    async getDataFn() {
      const res = await GetHomeDataApi()
      console.log(res, '首页数据')
      this.form = Object.assign(this.form, res.data)
    },
    testFn() {
      let u = navigator.userAgent
      let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 //android
      // let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios
      try {
        if (isAndroid && AndroidJs) {
          console.log('%c%s', 'color:red', '安卓--调用方法')
          const reqRow = {
            name: 'input',
            data: ''
          }
          AndroidJs.func(JSON.stringify(reqRow)) // 给安卓传参
        } else {
          console.log('%c%s', 'color:red', '苹果--调用方法')
          const reqRow = {
            name: 'back-iphone',
            data: ''
          }
          window.webkit.messageHandlers.func.postMessage(JSON.stringify(reqRow)) // 给ios 传参
        }
      } catch (e) {
        console.log(e, 'e-----判断安卓苹果类型出错')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.content {
  height: calc(100vh - 100rpx); // 确保容器有明确高度
  // background-color: skyblue;

  overflow: hidden;

  // padding-bottom: 100rpx;
  .bg-box {
    position: relative;
    // background-color: #528dfe;
    background: linear-gradient(to bottom, #3179fb, white);
    height: 650rpx;

    .homo-title {
      color: white;
      transform: translateY(30rpx);
      font-size: 35rpx;
      text-align: center;
    }

    .bg-logo {
      position: absolute;
      right: 50rpx;
      top: 160rpx;
    }

    .bg-hi {
      position: absolute;
      left: 30rpx;
      top: 200rpx;
    }

    .tip {
      padding-left: 120rpx;
      color: white;
      font-size: 40rpx;
    }

    .desc {
      margin-top: 20rpx;
      padding-left: 30rpx;
      color: #ffffff99;
    }

    .card {
      // border: 1px solid red;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-template-rows: repeat(2, 1fr);
      gap: 30rpx;
      padding: 50rpx;

      .card-item {
        position: relative;
        // border: 1px solid blue;
        border-radius: 20rpx;
        // background-color: red;
        background: linear-gradient(to bottom, white, #e1e9ff);
        height: 280rpx;
        padding: 30rpx;

        .item-title {
          font-size: 30rpx;
        }

        .item-totel {
          font-size: 50rpx;
        }

        .card-img {
          position: absolute;
          right: 20rpx;
          bottom: 20rpx;
        }
      }
    }
  }
}
</style>
