<template>
  <div class="AppReturnHomeRegister">
    <div class="tips">
      <div>外地抵汉、来汉人员疫情防控政策通…</div>
      <div @click="$linkTo('./policyDetail')">查看详情></div>
    </div>
    <div class="title">
      <h2>报备记录</h2>
      <div class="right">
        <span>共</span>
        <i>{{ total }}</i>
        <span>条</span>
      </div>
    </div>
    <div class="home-list">
      <div class="item" hover-class="bg-hover" @click="$linkTo(`./Detail?id=${item.id}`)"
           v-for="(item, index) in list" :key="index">
        <div class="item-top">
          <h2>{{ item.name }}</h2>
          <span v-if="item.status === '0'">有异常情况</span>
        </div>
        <p>{{ item.idNumber.replace(/^(\d{6})\d{8}(.{4}$)/g, `$1${Array(9).join('*')}$2`) }}</p>
        <div class="item-info">
          <div class="item-info__item">
            <image src="/static/img/from-icon.png"/>
            <span>{{ item.startAreaName }}</span>
          </div>
          <div class="item-info__item">
            <image src="/static/img/to-icon.png"/>
            <span>{{ item.arriveAreaName }}</span>
          </div>
          <div class="item-info__item">
            <image src="/static/img/to-date.png"/>
            <span>{{ item.arriveTime && item.arriveTime.substr(0, item.arriveTime.length - 3) }} 到达</span>
          </div>
        </div>
      </div>
      <AiEmpty v-if="list.length==0"/>
    </div>
    <div class="btn-wrapper">
      <div class="share" @click="show = true">分享</div>
      <div class="addbtn" @click="toReport" hover-class="text-hover">添加返乡报备</div>
    </div>

    <u-popup  v-model="show" mode="bottom" border-radius="30">
			<div class="shareBox">
        <h2>分享到：</h2>
        <div class="card">
          <div class="itemCard" @click="registerCode()">
            <img src="components/code.png" alt="" class="imgs" />
            <div class="names">扫码登记</div>
          </div>
          <div class="itemCard" @click="invitation()">
            <img src="components/wechat.png" alt="" class="imgs" />
            <div class="names">微信邀请</div>
          </div>
        </div>
        <div class="close" @click="show = false">取消</div>
      </div>
		</u-popup>

    <u-popup v-model="showCode" mode="center" border-radius="14" width="90%" height="450px">
			<div class="showCode">
        <div class="qrCode">
          <img src="components/code.png" alt="">
        </div>
        <h2>返乡登记</h2>
        <p>请外来及返乡人员使用微信扫码主动报备行程</p>
        <div class="btn">
          <div class="cancel" @click="showCode = false">取消</div>
          <div class="save" @click="savePoster">保存海报</div>
        </div>
      </div>
		</u-popup>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "AppReturnHomeRegister",
  appName: "返乡登记",
  data() {
    return {
      list: [],
      current: 1,
      total: 0,
      show: false,
      showCode: false,
    }
  },

  computed: {
    ...mapState(['user'])
  },

  onLoad() {
    this.$loading()
    this.getList()
    this.$dict.load('villageActivityStatus')
    uni.$on('update', () => {
      this.current = 1
      this.$nextTick(() => {
        this.getList()
      })
    })
  },

  methods: {
    toReport() {
      this.$linkTo('./Add')
    },

    // 扫码登记
    registerCode() {
      this.show = false;
      this.showCode = true;
    },
    // 微信邀请
    invitation() {
      console.log('222');
    },
    // 保存海报
    savePoster() {},

    getList() {
      this.$instance.post(`/app/appepidemicbackhomerecord/list`, null, {
        params: {
          openId: this.user.openId,
          current: this.current,
          size: 15
        }
      }).then(res => {
        uni.hideLoading()
        if (res?.data) {
          this.total = res.data.total
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records]
          } else {
            this.list = res.data.records
          }
        }
      }).catch(() => {
        uni.hideLoading()
      })
    },

  },

  onReachBottom() {
    this.current++
    this.getList()
  }
}
</script>

<style lang="scss" socped>
.AppReturnHomeRegister {
  padding: 0 0 150px 0;

  .tips {
    height: 106px;
    line-height: 106px;
    display: flex;
    justify-content: space-between;
    background: #FFF8F3;
    padding: 0 32px;
    div:first-child {
      width: 520px;
      color: #FF883C;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    div:last-child {
      color: #4181FF;
    }
  }

  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    padding: 48px 32px 0 32px;

    & > h2 {
      font-size: 38px;
      color: #333;
      font-weight: 600;
    }

    .right {
      display: flex;
      align-items: center;

      span {
        color: #666666;
        font-size: 28px;
      }

      i {
        color: #4181FF;
        font-style: normal;
        font-size: 28px;
      }
    }
  }

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

    .item-info {
      .item-info__item {
        display: flex;
        margin-bottom: 8px;
        line-height: 1.3;

        &:last-child {
          margin-bottom: 0;
        }

        image {
          position: relative;
          top: 2px;
          width: 32px;
          height: 32px;
          margin-right: 16px;
        }

        span {
          flex: 1;
          color: #333;
          font-size: 28px;
        }
      }
    }

    .item-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 50px;

      h2 {
        color: #333333;
        font-size: 36px;
        font-weight: 600;
      }

      span {
        font-size: 28px;
        color: #FF4466;
      }
    }

    p {
      margin: 14px 0 20px;
      color: #999999;
      font-size: 28px;
    }
  }

  .btn-wrapper {
    display: flex;
    justify-content: space-between;
    padding: 20px 32px !important;
    box-sizing: border-box;
    .addbtn,
    .share {
      height: 88px;
      line-height: 88px;
      text-align: center;
    }
    .share {
      width: 35%;
      border-radius: 16px;
      border: 1px solid #A0C0FF;
    }
    .addbtn {
      width: 60%;
      background: #4181FF;
      border-radius: 16px;
      color: #fff;
    }
  }

  .shareBox {
    padding-top: 32px;
    box-sizing: border-box;
    h2 {
      padding: 0 32px;
      font-weight: 600;
    }
    .card {
      display: flex;
      padding: 60px 32px 32px 32px;
      .itemCard {
        flex: 1;
        text-align: center;
        img {
          width: 96px;
          height: 96px;
        }
      }
    }

    .close {
      height: 112px;
      line-height: 112px;
      text-align: center;
      border-top: 2px solid #EEEEEE;
    }
  }

  .showCode {
    padding: 64px;
    box-sizing: border-box;
    text-align: center;
    .qrCode {
      img {
        width: 320px;
        height: 320px;
      }
    }
    h2 {
      font-size: 36px;
      font-weight: 600;
      padding: 32px 0;
    }
    p {
      font-size: 32px;
      margin-bottom: 80px;
    }

    .btn {
      display: flex;
      justify-content: space-between;
      .cancel,
      .save {
        width: 45%;
        text-align: center;
        height: 80px;
        line-height: 80px;
        border-radius: 40px;
      }
      .cancel {
        background: #EFF2F7;
      }
      .save {
        background: #383A49;
        color: #FFF;
      }
    }
  }

}
</style>
