<template>
  <div class="Search">
    <AiTopFixed>
      <u-search placeholder="请输入手机号或身份证号码搜索" :show-action="false" search-icon-color="#ccc" v-model="phone"  @search="getList()"/>
    </AiTopFixed>
    <div class="family-list" v-if="familyInfo.familyId">
      <div class="item" @click="goBack">
        <div class="name">{{familyInfo.familyName}}家</div>
        <div class="num">剩余积分:{{familyInfo.familyIntegral}}分</div>
      </div>
    </div>
    <p class="text" v-else>请通过搜索“<span>手机号或身份证号</span>”后选择结算对象</p>
  </div>
</template>

<script>
export default {
  name: 'Search',
  data() {
    return {
      phone: '',
      familyInfo: {},
      areaId: ''
    };
  },
  onLoad(options) {
    this.areaId = options.areaId
  },
  onShow() {
    document.title = '搜索'
  },
  methods: {
    getList() {
      this.$http.post(`/app/appresident/queryFamilyByPhone?phone=${this.phone}&areaId=${this.areaId}`).then(res => {
        if (res.code === 0 && res.data) {
          this.familyInfo = res.data
        }
      }).catch((err) => {
        this.$confirm(err, '温馨提示').then()
      })
    },
    goBack() {
      uni.$emit('selectFamily', this.familyInfo)
      uni.navigateBack()
    }
  },
};
</script>

<style scoped lang="scss">
uni-page-body{
  height: 100%;
  background-color: #fff;
}
.Search {
  ::v-deep .u-search{
    margin-bottom: 0!important;
  }
  .text{
    font-size: 28px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #999;
    line-height: 40px;
    margin-top: 120px;
    text-align: center;
    span{
      color: #135AB8;
    }
  }
  .item{
    line-height: 44px;
    padding: 34px 56px;
    background: #FFF;
    border-bottom: 1px solid #D8DDE6;
    display: flex;
    justify-content: space-between;
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #333;
  }
}
</style>