<template>
  <div class="familyMember" v-if="pageShow">
    <div class="item" v-for="(item, index) in list" :key="index">
      <div class="item-title">
        <div class="top">
          <div class="left">
            <h2>{{ item.name }}</h2>
            <span>{{ item.idNumber.replace(/(.{6}).*(.{4})/, '$1********$2') }}</span>
          </div>
          <span v-if="item.isHousehold == 1">户主</span>
          <span v-else>{{ $dict.getLabel('fpRelationship', item.householdRelation) }}</span>
        </div>
        <div class="bottom">
          <span>{{ $dict.getLabel('sex', item.sex) }}</span>
          <span>{{ item.age }}岁</span>
        </div>
      </div>
      <div class="item-bottom">
        <span @click="showMore(item.id)">查看详情</span>
        <!-- <span @click="toEdit(index)">编辑</span> -->
        <span @click="remove(index)">删除</span>
      </div>
    </div>
    <AiFixedBtn>
      <div class="addBtn iconfont iconfont-iconfangda" @tap="toAdd"></div>
    </AiFixedBtn>
    <div class="no-more" v-if="!list.length">
      <image src="https://cdn.cunwuyun.cn/dvcp/h5/no-admin.png"/>
      <div>
        <span>您还未添加过家庭成员点击</span>
        <i  @tap="toAdd">新增按钮</i>
        <span>试试吧~</span>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      list: [],
      id: '',
      info: {},
      pageShow: false,
      houseIdNumber: '',
      objectType: '',
    }
  },

  onShow() {
    document.title = '家庭成员'
  },

  onLoad(query) {
    this.houseIdNumber = query.houseIdNumber
    this.objectType = query.objectType
    this.$dict.load(['fpRelationship','riskEliminationMethod', 'fpRiskType', 'fpYesOrNo', 'fpNation', 'fpEducation', 'fpStudentsInSchool', 'fpHealth',
    'fpLaborSkills', 'fpPoliticalOutlook', 'sex', 'fpHealth']).then(() => {
      if(query.id) {
        this.id = query.id
        this.getInfo()
      }
    })

    uni.$on('reload', () => {
      this.getInfo()
    })
  },

  methods: {
    toAdd() {
      uni.navigateTo({
        url: `./MonitorAddFamilyMember?houseIdNumber=${this.houseIdNumber}&objectType=${this.objectType}`
      })
    },

    toEdit(index) {
      this.$confirm('确定编辑该数据？').then(() => {
        uni.navigateTo({
          url: `./MonitorAddFamilyMember?id=${this.list[index].id}&houseIdNumber=${this.houseIdNumber}&objectType=${this.objectType}`
        })
      })
    },

    remove(index) {
      this.$confirm('', '确定删除该数据？').then(() => {
        this.$http.post(`/app/apppreventionreturntopoverty/delete?ids=${this.list[index].id}`).then(res => {
          if (res.code === 0) {
            this.$u.toast('删除成功')
            uni.$emit('reload')
          }
        })
      })
    },

    showMore(id) {
      uni.navigateTo({url: `./residentDetail?id=${id}`})
    },

    getInfo() {
      this.$http.post(`/app/apppreventionreturntopoverty/queryDetailById?id=${this.id}`).then(res => {
        if (res.code === 0) {
          this.info = res.data
          if(res.data.family && res.data.family.length) {
            console.log(res.data.family);
            this.list = res.data.family.map(item => {
              return {
                ...item,
                isShow: false,
                age: this.$calcAge(item.idNumber)
              }
            })
          }
          this.pageShow = true
        }
      })
    }
  }
}
</script>

<style lang="scss">
.familyMember {
  padding: 32px 0;

  .no-more {
    padding-top: 160px;
    text-align: center;

    image {
      width: 282px;
      height: 304px;
    }

    div {
      width: 280px;
      margin: 0 auto;

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

      i {
        font-style: normal;
        color: #467DFE;
        font-size: 28px;
      }
    }
  }

  .addBtn {
    width: 96px;
    height: 96px;
    flex-shrink: 0;
    background: $uni-color-primary;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
    font-size: 48px;
    color: #fff;
    border-radius: 50%;
    justify-content: center;
    align-items: center;
    display: flex;
  }

  .item {
    width: 686px;
    margin: 0 auto 32px;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;

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

      span {
        height: 100%;
        line-height: 96px;
        color: #3975C6;
        font-size: 26px;
        text-align: center;
      }
    }

    .item-title {
      padding: 32px;
      background: #FFFFFF;
      border-bottom: 1px solid #DDDDDD;

      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 8px;

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

          h2 {
            margin-right: 32px;
            color: #333333;
            font-size: 40px;
            font-weight: 500;
          }

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

        & > span {
          color: #3975C6;
          font-size: 28px;
        }
      }
    }

    .item-info {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      background: #F9F9F9;

      .item-info__item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 50%;
        height: 72px;
        padding: 0 20px;
        border-bottom: 1px solid #DDDDDD;
        border-right: 1px solid #DDDDDD;
        box-sizing: border-box;

        &:nth-of-type(2n) {
          border-right: none;
        }
      }

      label {
        color: #999999;
        font-size: 26px;
      }

      span {
        color: #3975C6;
        font-size: 26px;
      }
    }

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

      span {
        color: #999999;
        font-size: 28px;

        &:first-child {
          margin-right: 20px;
        }
      }
    }
  }
}
</style>
