<template>
  <div class="AppHelpEffect">
    <AiTopFixed>
      <u-tabs :list="tabs" :is-scroll="false" :current="currentTab" height="96" bar-width="150" @change="v=>{currentTab=v,current=1}"/>
      <div class="search">
        <u-search placeholder="请输入姓名、身份证号" @clear="con='',getList()" clearable v-model="con" :show-action="false" @search="search"></u-search>
      </div>
      <div class="select">
        <AiAreaPicker class="fill" v-model="areaId" :area-id="user.areaId" :name.sync="areaName" @select="areaSelect" selectRoot>
          <div flex class="center">
            <u-icon name="map-fill" size="32" color="#999" class="mar-r8"/>
            <AiMore icon="arrow-down" v-model="areaName" placeholder="所在地区"/>
          </div>
        </AiAreaPicker>
        <AiSelect v-if="currentTab=='0'" class="fill center" flex v-model="houseType" :list="typeList" @data="typeSelect">
          <AiMore class="fill" icon="arrow-down" v-model="$dict.getLabel('fpHouseType', houseType)" placeholder="户类型"/>
        </AiSelect>
      </div>
    </AiTopFixed>
    <div class="cardList">
      <component ref="List" :is="currentPage.list" v-bind="{current,search:{areaId,houseType,con}}"/>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import HelpedResidentList from "./helpedResidentList";
import NormalFarmerList from "./normalFarmerList";

export default {
  name: "AppHelpEffect",
  components: {NormalFarmerList, HelpedResidentList},
  appName: '帮扶成效',
  data() {
    return {
      con: "",
      current: 1,
      typeList: [],
      areaId: '',
      areaName: '',
      houseType: '',
      currentTab: '0'
    }
  },
  computed: {
    ...mapState(['user']),
    tabs: () => [
      {name: "监测对象", list: HelpedResidentList},
      {name: "一般农户", list: NormalFarmerList}
    ],
    currentPage: v => v.tabs[v.currentTab] || {}
  },
  methods: {
    areaSelect(e) {
      this.areaId = e
      this.refreshList()
    },
    typeSelect(v) {
      this.houseType = v?.[0].value
      this.refreshList()
    },
    search(value) {
      this.name = value
      this.refreshList()
    },
    refreshList() {
      this.current = 1
      this.$nextTick(() => this.$refs.List.getList(true))
    }
  },
  onLoad() {
    this.areaId = this.user.areaId
    this.$dict.load('fpHouseType').then(() => {
      this.typeList = this.$dict.getDict('fpHouseType').map((item) => {
        return {
          label: item.dictName,
          value: item.dictValue
        }
      })
      this.typeList.unshift({label: '全部类型', value: ''})
    })
  },
  onShow() {
    document.title = '帮扶成效'
    this.refreshList()
  },
  onReachBottom() {
    this.current++
  }
}
</script>

<style lang="scss" scoped>
.AppHelpEffect {
  .search {
    height: 100px;
    line-height: 100px;
  }

  .center {
    justify-content: center;
    text-align: center;
  }

  .select {
    width: 100%;
    display: flex;
    height: 86px;
    line-height: 86px;
    text-align: center;
  }

  ::v-deep .cardList {
    padding: 32px;
    box-sizing: border-box;

    .card {
      padding: 32px;
      box-sizing: border-box;
      margin-bottom: 32px;
      background: #FFF;
      box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.0200);
      border-radius: 16px;

      .user {
        display: flex;
        justify-content: space-between;

        .name {
          font-size: 36px;
          font-weight: 600;
        }
      }

      .idCard,
      .tel,
      .address {
        margin-top: 8px;
        color: #999999;

        img {
          margin-right: 16px;
          width: 28px;
          height: 28px;
        }
      }

      .tel,
      .address {
        color: #333;
      }
    }
  }
}
</style>
