<template>
  <div class="AppHomeRegistration">
    <AiTopFixed v-if="isGridMember">
      <div class="tab-select">
        <div class="item" :class="tabIndex == index ? 'active' : ''" v-for="(item, index) in tabs" :key="index" @click="tabClick(index)">{{item}}<span></span></div>
      </div>
      <div class="currentLeft-top">
        <div class="left">
          <AiAreaPicker v-model="areaId" :areaId="user.areaId" @select="areaSelect" :name.sync="areaName" selectRoot>
            <span class="label" v-if="areaName">{{ areaName }}</span>
            <span v-else>请选择</span>
            <u-icon name="arrow-down" color="#666" size="24" style="margin-left: 4px" />
          </AiAreaPicker>
        </div>
        <u-search v-model="keyword" :clearabled="true" placeholder="请输入姓名/身份证号" :show-action="false" bg-color="#F5F5F5" search-icon-color="#ccc" color="#666" height="58" @search="getList" @clear="handerClear"></u-search>
      </div>
    </AiTopFixed>
    <div class="user-list" v-if="isGridMember">
      <div class="item" @click="toDetail(item)" v-for="(item,index) in list" :key="index">
        <h2 class="name">{{ item.name }}<span class="status" v-if="item.status == 0">有异常</span></h2>
        <p class="color-999">{{ item.idNumber }}</p>
        <p><img src="./components/img/org-icon.png" alt=""><span class="start-name">{{ item.startAreaName }}</span></p>
        <p><img src="./components/img/blue-icon.png" alt=""><span class="start-name">{{ item.arriveAreaName }}</span></p>
        <p><img src="./components/img/time-icon.png" alt="">{{ item.arriveTime }}</p>
      </div>
    </div>
    <AiEmpty v-if="!list.length && isGridMember"></AiEmpty>
    <div v-if="!isGridMember" class="empty">
      <img src="./components/img/no-admin.png" alt="">
      <p>没有网格员权限<br/>无法查看返乡登记哦~</p>
    </div>
    <u-popup v-model="show" mode="bottom" border-radius="14">
      <div class="line-bg"></div>
      <div class="flex">
        <div class="item" @click="share">
          <img src="./components/img/zf.png" alt="">
          <p>转发</p>
        </div>
        <div class="item" @click="shareWechat">
          <img src="./components/img/wx.png" alt="">
          <p>分享到微信</p>
        </div>
        <div class="item" @click="copy">
          <img src="./components/img/lj.png" alt="">
          <p>获取链接</p>
        </div>
        <div class="item" @click="linkTo(`./Qrcode?girdId=${girdId}&girdName=${girdName}`)">
          <img src="./components/img/ewm.png" alt="">
          <p>保存二维码</p>
        </div>
      </div>
      <div class="btn" @click="show=false">取消</div>
    </u-popup>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import qs from "query-string"

export default {
  appName: '返乡登记',
  data() {
    return {
      tabs: ['新增报备', '历史数据'],
      tabIndex: 0,
      areaId: '',
      areaName: '',
      keyword: '',
      current: 1,
      list: [],
      name: '',
      totalInfo: {},
      show: false,
      girdName: '',
      girdId: '',
    }
  },
  computed: {
    ...mapState(['user']),
    params() {
      return qs.parse(decodeURIComponent(location.search))
    },
    shareLink() {
      let {girdId, girdName, user: {corpId}} = this
      return location.origin + `/apps/AppAppHomeRegistration/add?corpId=${corpId}&arriveGirdId=${girdId}&arriveGirdName=${encodeURIComponent(girdName)}`
    },
    isGridMember() {
      return this.user.girdCheckType > 0
    }
  },
  onLoad() {
    this.girdId = this.user.girdId
    uni.$on('updateBackList', () => {
      this.getListInit()
    })
    this.areaId = this.user.areaId
    this.areaName = this.user.areaName
    this.getListInit()
  },
  onShow() {
    document.title = '返乡登记'
  },
  methods: {
    tabClick(index) {
      this.tabIndex = index
      this.getListInit()
    },
    areaSelect(e) {
      this.areaId = e
      this.getList()
    },
    getListInit() {
      this.current = 1
      this.list = []
      this.getList()
    },
    getList() {
      var status = ''
      if (this.tabIndex == 1) {
        status = 0
      }
      this.$http.post(`/app/appepidemicbackhomerecord/list?current=${this.current}&size=10&status=${status}&name=${this.name}&arriveGirdId=${this.girdId}`).then((res) => {
        if (res?.data) {
          res.data.records.map((item) => {
            item.idNumber = this.$idCardNoUtil.hideId(item.idNumber)
          })
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
    toDetail(row) {
      uni.navigateTo({url: `./Detail?id=${row.id}`})
    },
  },
  onReachBottom() {
    this.current++
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.AppHomeRegistration {

  .tab-select {
    width: 100%;
    height: 96px;
    line-height: 96px;
    background: #3975C6;
    display: flex;

    .item{
      flex: 1;
      text-align: center;
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #CDDCF0;
    }

    .active{
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      position: relative;
      color: #fff;
      span{
        width: 48px;
        height: 4px;
        background: #FFF;
        position: absolute;
        bottom: 14px;
        left: 50%;
        margin-left: -24px;
      }
    }
  }

  .currentLeft-top {
    display: flex;
    align-items: center;
    padding: 32px;
    background-color: #fff;

    .left {
      width: 40%;
      display: flex;
      align-items: center;

      img {
        width: 48px;
        height: 48px;
      }
    }
  }

  .user-list {
    padding: 32px 32px 0;
    background-color: #F3F6F9;

    .item {
      padding: 32px 32px 24px;
      background-color: #fff;
      margin-bottom: 32px;
      border-radius: 16px;

      .name {
        font-size: 36px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333;
        line-height: 50px;
        margin-bottom: 8px;

        .status {
          float: right;
          font-size: 28px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #FF4466;
          line-height: 40px;
        }
      }

      p {
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #333;
        line-height: 40px;
        margin-bottom: 8px;

        img {
          width: 32px;
          height: 32px;
          margin-right: 18px;
          vertical-align: top;
        }
      }

      .start-name {
        display: inline-block;
        width: calc(100% - 50px);
      }

      .color-999 {
        margin-bottom: 24px;
        color: #999;
      }
    }
  }

  ::v-deep .AiTopFixed {
    .placeholder {
      .content {
        padding: 0 !important;

      }
    }

    .fixed {
      margin: 0 !important;
      background-color: #f5f5f5 !important;

      .content {
        padding: 0 !important;
      }
    }
  }

  .pad-t32 {
    padding-top: 32px;
  }

  .select-gird {
    width: calc(100% - 60px);
    padding: 24px 32px;
    background: #FFFFFF;
    border-radius: 16px;
    margin: 0 30px 32px;
    box-sizing: border-box;
    text-align: center;

    img {
      width: 32px;
      height: 32px;
      vertical-align: middle;
      margin-right: 8px;
    }

    .center {
      justify-content: center;
    }

  }

  .empty {
    text-align: center;

    img {
      width: 282px;
      height: 306px;
      margin: 136px auto 0;
    }

    p {
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #999;
      line-height: 40px;
    }
  }

  .pad-b120 {
    padding-bottom: 120px;
  }

  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 112px;
    line-height: 110px;
    text-align: center;
    display: flex;
    font-size: 36px;
    font-family: PingFangSC-Regular, PingFang SC;
    z-index: 99;

    .bg-fff {
      flex: 1;
      color: #333;
      background-color: #fff;
    }

    .bg-blue {
      flex: 2;
      color: #fff;
      background-color: #3975C6;
    }
  }

  .line-bg {
    width: 110px;
    height: 8px;
    background: #DCDDDE;
    border-radius: 4px;
    margin: 32px auto 82px;
  }

  .flex {
    width: 100%;
    display: flex;
    padding-bottom: 70px;

    .item {
      flex: 1;
      text-align: center;

      img {
        width: 100px;
        height: 100px;
        border-radius: 16px;
        background-color: #fff;
        margin-bottom: 16px;
      }

      p {
        font-size: 26px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #666;
        line-height: 36px;
      }
    }
  }

  .btn {
    width: 100%;
    height: 96px;
    line-height: 96px;
    text-align: center;
    background: #FFF;
    font-size: 30px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333;
  }

  ::v-deep .uni-scroll-view {
    background-color: #f7f7f7;
  }
}
</style>
