<template>
  <div class="AppWarningMonitoring">
    <AiTopFixed>
      <div class="tab-select">
        <div class="item" :class="tabIndex == index ? 'active' : ''" v-for="(item, index) in tabs" :key="index" @click="tabClick(index)">{{item}}<span></span></div>
      </div>
      <div class="search-box">
        <div class="area-select">
          <AiAreaPicker v-model="areaId" :areaId="user.areaId" :name.sync="areaName" @select="areaSelect">
            <u-icon name="map-fill" size="18px" color="#FFF"></u-icon>
            <span v-if="areaName" style="color:#FFF;fontSize: 14px;">{{ areaName }}</span>
            <span v-else :style="{color:areaName? '#FFF': '#E2E8F1'}">请选择</span>
            <u-icon name="arrow-down" color="#FFF" size="24" style="margin-left: 4px"></u-icon>
          </AiAreaPicker>
        </div>
        <div class="search">
          <u-search placeholder="请输入姓名" v-model="name" bg-color="#1F5CAF" search-icon-color="#E2E8F1"
          placeholder-style="color: #E2E8F1;" :show-action="false" @search="searchHandler" @clear="name='',getList()"></u-search>
        </div>
      </div>
    </AiTopFixed>
    <div class="card-list" v-if="list.length">
      <div class="item" v-for="(item, index) in list" :key="index" @click="toDetail(item.id)">
        <div class="top">
          <div class="name-type">
            <span class="name">{{ item.name }}</span>
            <span class="type" :style="{color: item.status==0? '#FFBB00':item.status==1? '#FF8822':item.status==2? '#FF4466':'#2EA222'}">
              {{ $dict.getLabel('fpRiskPersonStatus',item.status) }}
            </span>
          </div>
          <div class="address">{{ item.areaName }}</div>
        </div>
        <div class="bottom">{{ $dict.getLabel('fpRiskType',item.riskType) }}</div>
      </div>
    </div>
    <AiEmpty v-else/>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'AppWarningMonitoring',
  appName: '预警监控',
  data() {
    return {
      tabs: ['待处理','历史信息'],
      tabIndex: 0,
      areaName: '',
      areaId: '',
      name: '',
      current: 1,
      list: [],
    }
  },
  computed: {
    ...mapState(['user'])
  },
  onLoad() {
    this.$dict.load('fpRiskPersonStatus','fpRiskType').then(()=>{
      this.areaId = this.user.areaId
      this.areaName = this.user.areaName
      uni.$on('update',()=>{
        this.current = 1
        this.getList()
      })
      this.getList()
    })
  },
  methods: {
    tabClick(index) {
      this.list = []
      this.current = 1
      this.tabIndex = index,
      this.getList()
    },
    areaSelect(v) {
      this.areaId = v
      this.current = 1
      this.getList()
    },
    searchHandler() {
      this.list = []
      this.current = 1
      this.getList()
    },
    getList() {
      this.$http.post('/app/apppreventionreturntopovertyriskperson/list-wx',null,{params:{
        current: this.current,
        queryType: this.tabIndex,
        name: this.name,
        areaId: this.areaId,
      }}).then(res=>{
        if(res?.data) {
          this.list = this.current==1? res.data.records: [...this.list,...res.data.records]
        }
      })
    },
    toDetail(id) {
      uni.navigateTo({url:`./detail?id=${id}&tabIndex=${this.tabIndex}`})
    }
  },
  onReachBottom() {
    this.current ++ 
    this.getList()
  },
  onShow() {
    document.title = "风险预警"
  },
}
</script>

<style lang="scss" scoped>
.AppWarningMonitoring {
  background: #f3f4f5;
  ::v-deep .AiTopFixed .content {
    padding: 0;
  }
  ::v-deep .AiTopFixed .search {
    margin-bottom: 0;
  }
  .tab-select {
    width: 100%;
    height: 96px;
    line-height: 96px;
    background: #3975C6;
    display: flex;

    .item{
      flex: 1;
      text-align: center;
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #CDDCF0;
    }

    .active{
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      position: relative;
      color: #fff;
      span{
        width: 48px;
        height: 4px;
        background: #FFF;
        position: absolute;
        bottom: 14px;
        left: 50%;
        margin-left: -24px;
      }
    }
  }
  .search-box {
    display: flex;
    width: 100%;
    height: 112px;
    line-height: 112px;
    background: #3975C6;
    padding: 0 32px;
    box-sizing: border-box;
    .area-select {
      display: flex;
      width: 240px;

    }
    .search {
      width: calc(100% - 240px);
      ::v-deep .uni-input-input {
        color: #fff;
      }
    }
  }
  .card-list {
    box-sizing: border-box;
    padding: 32px;
    
    .item {
      background: #FFFFFF;
      border-radius: 16px;
      margin-bottom: 16px;
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      .top {
        padding: 32px 32px;
        .name-type {
          display: flex;
          justify-content: space-between;
          .name {
            color: #333333;
            font-size: 32px;
            font-weight: 500;
          }
        }
        .address {
          margin-top: 16px;
          color: #999999;
          font-size: 26px;
        }
      }
      .bottom {
        padding: 0 32px;
        border-top: 1px solid #DDDDDD;
        height: 94px;
        line-height: 94px;
        color: #3975C6;
        font-size: 26px;
      }
    }
  }

}
</style>