<template>
  <div class="returnHomeRegister" v-if="pageShow">
    <div class="title">
      <h2>上报人员</h2>
      <div class="right">
        <span>共</span>
        <i>{{ total }}</i>
        <span>名</span>
      </div>
    </div>
    <div class="home-list">
      <div class="item" v-for="(item, index) in list" :key="index" >
        <div class="item-top" @click.stop="$linkTo('./Detail?id=' + item.id)">
          <div class="item-top__left">
            <h2>{{ item.name }}<span :class="item.status == 1? 'status0':'status1'">返乡人员</span></h2>
            <!-- <p @click.stop="$linkTo('./UserInfo?id=' + item.id)" hover-class="text-hover">查看个人信息></p> -->
            <div>
              <p>登记于2021-10-15</p>
              <span :class="item.status == 1? 'status0':'status1'">异常</span>
            </div>
          </div>
          <span v-if="item.status === '0'">健康数据异常</span>
        </div>
        <div class="item-bottom">
          <div class="item-bottom__left">
            <span>上报第</span>
            <i>{{ item.diffNum || 0 }}</i>
            <span>天</span>
          </div>
          <div class="item-bottom__right" hover-class="text-hover" v-if="item.today === '0'"
               @click.stop="$linkTo('./AddReport?id=' + item.id)">
            <span style="color: #FF883C">今日未上报</span>
            <u-icon name="arrow-right" color="#ddd"/>
          </div>
          <div class="item-bottom__right" hover-class="text-hover" v-else
               @click.stop="$linkTo('./RecordList?id=' + item.id)">
            <span style="color: #999999">今日已上报</span>
            <u-icon name="arrow-right" color="#ddd"/>
          </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: "AppHealthReport",
  appName: "健康上报",
  data() {
    return {
      list: [],
      pageShow: false,
      current: 1,
      total: 0,
      show: false,
      showCode: false,
    }
  },

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

  onLoad() {
    this.$loading()
    this.$dict.load(['villageActivityStatus']).then(() => {
      this.getList()
    })

    uni.$on('update', () => {
      this.current = 1
      this.$nextTick(() => {
        this.getList()
      })
    })
  },

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

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

    getList() {

      this.$instance.post(`/app/appepidemicreportmember/list?openId=${this.user.openId}`, null, {
        params: {
          current: this.current,
          size: 15
        }
      }).then(res => {
        if (res.code == 0) {
          this.total = res.data.total
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records]
          } else {
            this.list = res.data.records
          }
          uni.hideLoading()
          this.pageShow = true
          if (res.data.records.length < 15) {

            return false
          }

          this.current = this.current + 1
        } else {
          uni.hideLoading()
        }
      }).catch(() => {
        uni.hideLoading()
      })
    }
  },

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

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

  .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;
    border-radius: 16px;
    background: #fff;

    .item-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 152px;
      padding: 0 32px;
      border-bottom: 1px solid #DDDDDD;

      .item-top__left {
        width: 100%;
        h2 {
          line-height: 44px;
          margin-bottom: 8px;
          color: #333;
          font-size: 32px;
          font-weight: 600;
          span {
            padding: 4px 8px;
            font-size: 26px;
            font-weight: normal;
            margin-left: 24px;
          }
        }
        div {
          display: flex;
          justify-content: space-between;
          p {
            color: #999999;
            font-size: 26px;
          }
          span {
            padding: 4px 8px;
            font-size: 26px;
          }
        }
        .status0 {
          color: #FF4466;
          background: #FFF5F7;
        }
        .status1 {
          color: #1AAAFF;
          background: #E8F6FF;
        }
        .status2 {
          color: #42D784;
          background: #ECFBF2;
        }
      }

      & > span {
        font-size: 26px;
        color: #FF4466;
      }
    }

    .item-bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 104px;
      padding: 0 32px;

      .item-bottom__right {
        span {
          color: #999999;
          font-size: 28px;
        }
      }

      .item-bottom__left {
        span {
          color: #999999;
          font-size: 28px;
        }

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

      & > div {
        display: flex;
        align-items: center;
      }
    }
  }

  .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;
        // width: 25%;
        img {
          width: 96px;
          height: 96px;
        }
      }
    }
    // ::v-deep .u-popup .u-drawer .u-drawer-bottom {
    //   bottom: 50px;
    // }
    .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>
