<template>
  <div class="AppCommunityManagement">
    <AiTopFixed>
      <u-tabs :list="tabList" :is-scroll="false" :current="currentTabs" height="96" bg-color="#3975C6"
        inactive-color="#A1C1E8" :bar-style="barStyle" :active-item-style="activeStyle" active-color="#ffffff " @change="change">
      </u-tabs>
      <div class="header">
        <div class="tab-item" v-if="!currentTabs">
          <h2 style="color:#5AAD6A;">{{totalInfo['待管理']}}</h2>
          <p>待管理</p>
        </div>
        <div class="tab-item" v-if="currentTabs == 1">
          <h2 style="color:#5AAD6A;">{{totalInfo['管理中']}}</h2>
          <p>管理中</p>
        </div>
        <div class="tab-item" v-if="currentTabs == 2">
          <h2 style="color:#5AAD6A;">{{totalInfo['已解除']}}</h2>
          <p>已解除</p>
        </div>
        <div class="tab-item">
          <h2 style="color:#F5A319;">{{totalInfo['今日新增']}}</h2>
          <p>今日新增</p>
        </div>
        <div class="tab-item">
          <h2 style="color:#CD413A;border-right:0;">{{totalInfo['新增风险']}}</h2>
          <p>新增风险</p>
        </div>
      </div>
      <div class="top-search">
        <div class="left">
          <AiAreaPicker v-model="areaId" :areaId="cropAreaId" @select="areaSelect" :name.sync="areaName" style="color: #666" selectRoot>
            <span style="margin-left: 4px" v-if="areaName">{{ areaName }}</span>
            <span v-else style="color:#999;">地区选择</span>
            <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" />
          </AiAreaPicker>
        </div>
        <div class="right">
          <u-search v-model="keyword" :clearabled="true" placeholder="请输入姓名/手机号/身份证号" :show-action="false" bg-color="#F5F5F5"
            search-icon-color="#999" color="#999" height="58" @search="getListInit" @clear="getListInit">
          </u-search>
        </div>
      </div>
      <div class="top-select">
        <div class="item" @click="showDate=true">
          <span v-if="!dateList.length" style="color:#999;">选择日期</span>
          <span v-else>{{ dateList[0] }}-{{dateList[1]}}</span>
          <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" />
          <u-calendar v-model="showDate" mode="range" @change="changeDate"></u-calendar>
        </div>
        <div class="item" @click="showTypeSelect=true">
          <span v-if="handleType === ''" style="color:#999;">处置意见</span>
          <span v-else>{{ $dict.getLabel('EP_handleType', handleType) }}</span>
          <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" />
        </div>
      </div>
    </AiTopFixed>
    <div class="data-list" v-if="list && list.length">
      <div class="item" v-for="(item, index) in list" :key="index" @click="toDetail(item.status, item.id)">
        <div class="top">
          <div class="title">
            <div class="name">
              {{item.name}}
              <span class="type">{{$dict.getLabel('EP_registerInfoType', item.infoType)}}</span>
            </div>
            <div class="status" :class="item.nucleicAcidSamplingCount >0 ? 'status1' : 'status0'">
              <span class="cir"></span>
              <span v-if="item.nucleicAcidSamplingCount >0">核酸采样{{item.nucleicAcidSamplingCount}}次</span>
              <span v-else>核酸未采样</span>
            </div>
          </div>
          <p> {{item.idNumberText}}</p>
          <p>{{item.phone}}</p>
          <p>{{item.registerInfo.startAreaName}}-{{item.registerInfo.arriveAreaName}}</p>
          <p> 处置意见：<span :class="'type-'+item.lastRiskDisposal.handleType">{{$dict.getLabel('EP_handleType', item.lastRiskDisposal.handleType)}}</span></p>
          <div class="btn" v-if="item.status == 0" @click.stop="toEdit(item.id)">管理</div>
          <div class="btn" v-if="item.status == 1" @click.stop="toEdit(item.id)">排查</div>
          <img src="./components/img/status-img.png" alt="" class="status-img" v-if="item.status == 2">
        </div>
        <div class="bottom">
          <div class="text">
            <!-- 管控人：<span> {{item.controllerUserName}}</span>  -->
            抵平时间：{{item.registerInfo.arriveTime}}
          </div>
        </div>
      </div>
    </div>
    <AiEmpty description="暂无数据" class="emptyWrap" v-else></AiEmpty>
    <u-select v-model="showTypeSelect" :list="registerTypeList" label-name="dictName" value-name="dictValue" @confirm="typeConfirm"></u-select>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  appName: '社区管理',
  data() {
    return {
      areaId: '',
      areaName: '',
      current: 1,
      keyword: '',
      currentTabs: 0,
      handleType: '',
      showTypeSelect: false,
      tabList: [
        {
          name: '待管理',
        },
        {
          name: '管理中',
        },
        {
          name: '已解除',
        },
      ],
      barStyle: {
        'width': '24px',
        'height': '2px',
        'border-radius': '0',
        'bottom': '5px'
      },
      activeStyle: {
        'font-weight' : '400',
      },
      list: [],
      registerTypeList: [],
      cropAreaId: '',
      totalInfo: {},
      showDate: false,
      dateList: []
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad() {
    this.areaId = this.user.areaId
    this.areaName = this.user.areaName
    this.$dict.load('EP_CM_status', 'EP_registerInfoType', 'EP_handleType').then(() => {
      this.registerTypeList = this.$dict.getDict('EP_handleType')
      this.registerTypeList.unshift({dictValue: '', dictName: '全部'})
      this.getListInit()
      this.getTotal()
    })
     uni.$on('updateList', () => {
      this.getListInit()
      this.getTotal()
    })
    this.getCropAreaId()
  },
  onShow() {
    document.title = '社区管理'
  },
  methods: {
    getCropAreaId() {
      this.$http.post(`/app/appdvcpconfig/getCorpArea`).then((res) => {
        if (res.code == 0) {
          this.areaId = res.data
          this.cropAreaId = res.data
        }
      })
    },
    getListInit() {
      this.current = 1
      this.list = []
      this.getList()
    },
    getList() {
      var startDate = this.dateList.length ? this.dateList[0] + ' 00:00:00' : ''
      var endDate = this.dateList.length ? this.dateList[1] + ' 00:00:00' : ''
      this.$http.post('/app/appepidemicpreventioncommunitymanagement/list', null, {
        params: {
          size: 10,
          current: this.current,
          status: this.currentTabs,
          areaId: this.areaId, name:
          this.keyword,
          queryBeginTime: startDate,
          queryEndTime: endDate,
          handleType: this.handleType
        },
      }).then((res) => {
        if (res.code == 0) {
          res.data.records.map((item) => {
            item.idNumberText = item.idNumber.replace(/(.{6}).*(.{4})/,"$1********$2")
          })
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
    toDetail(status, id) {
      console.log(status, id)
      if(status == 0) {
        uni.navigateTo({url: `./HandleDetail?id=${id}`})
      }else{
        uni.navigateTo({url: `./Detail?id=${id}`})
      }
    },
    toEdit(id) {
      uni.navigateTo({url: `./Add?id=${id}`})
    },
    change(index) {
      this.keyword = ''
      this.currentTabs = index
      this.getListInit()
    },
    areaSelect(e) {
      this.areaId = e
      this.getListInit()
      this.getTotal()
    },
    typeConfirm(e) {
      this.handleType = e[0].value
      this.getListInit()
    },


    getTotal() {
      this.$http.post(`/app/appepidemicpreventioncommunitymanagement/listStatistics?areaId=${this.areaId}`).then((res) => {
        if (res.code == 0) {
          this.totalInfo = res.data
        }
      })
    },
    changeDate(e) {
      console.log(e)
      this.dateList = [e.startDate, e.endDate]
      this.getListInit()
    },
  },
  onReachBottom() {
    this.current++
    this.getList()
  },
}
</script>

<style scoped lang="scss">
.AppCommunityManagement {
  height: 100%;
  ::v-deep .AiTopFixed {
    .placeholder {
      .content {
        padding: 0 !important;
      }
    }
    .fixed {
      margin: 0 !important;
      .content {
        padding: 0 !important;
      }
    }
  }
  .header{
    padding: 54px 32px 48px 32px;
    display: flex;
    background-color: #fff;
    margin-bottom: 4px;
    .tab-item{
      flex: 1;
      text-align: center;

      h2{
        font-size: 52px;
        font-family: DINAlternate-Bold, DINAlternate;
        font-weight: bold;
        height: 80px;
        margin-bottom: 8px;
        letter-spacing: -4px;
        border-right: 1px solid #ddd;
        line-height: 44px;
      }
      p{
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #999;
        line-height: 40px;
        margin-top: -22px;
      }
    }
    .tab-item:nth-last-of-type(1) {
      border-right: 0;
    }
  }
  .top-search {
    padding: 20px 32px;
    display: flex;
    .left {
      width: 240px;
    }
    .right {
      width: calc(100% - 240px);
    }
  }
  .top-select {
    display: flex;
    padding: 28px 0;
    .item {
      flex: 1;
      padding: 0 8px;
      text-align: center;
      span {
        display: inline-block;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 28px;
        color: #666;
        line-height: 40px;
      }
    }
  }
  .data-list {
    padding: 32px 32px 0;
    .item {
      width: 100%;
      background: #FFF;
      border-radius: 16px;
      margin-bottom: 24px;
      .top {
        padding: 32px 32px 24px 32px;
        position: relative;
        .title {
          display: flex;
          justify-content: space-between;
          margin-bottom: 24px;
          .name {
            font-family: PingFangSC-Regular;
            font-weight: 400;
            font-size: 32px;
            color: #000;
            .type {
              line-height: 34px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              font-size: 24px;
              color: #3975C6;
              padding: 2px 4px;
              background-color: #F6F9F5;
              margin-left: 24px;
            }
          }
          .status {
            line-height: 20px;
            font-family: PingFangSC-Regular;
            font-size: 28px;
            .cir {
              display: inline-block;
              width: 8px;
              height: 8px;
              border-radius: 50%;
              margin-right: 8px;
            }
          }
          .status0 {
            color: #FFA938;
            .cir {
              background-color: #FFA938;
            }
          }
          .status0 {
            color: #1CCEB0;
            .cir {
              background-color: #1CCEB0;
            }
          }
        }
        p {
          line-height: 40px;
          font-family: PingFangSC-Regular;
          font-size: 28px;
          color: #666;
          margin-bottom: 8px;
        }
        .type-1,
        .type-5{
          color: #42D784;
        }
        .type-2,
        .type-3{
          color: #f46;
        }
        .type-4{
          color: #FFA938;
        }
        .btn {
          width: 160px;
          height: 56px;
          text-align: center;
          line-height: 54px;
          background: #FFF;
          border: 1px solid #1365DD;
          border-radius: 4px;
          box-sizing: border-box;
          position: absolute;
          bottom: 16px;
          right: 32px;
          font-family: PingFangSC-Regular;
          font-size: 28px;
          color: #1365DD;
        }
        .status-img {
          position: absolute;
          bottom: 0;
          right: 32px;
          width: 160px;
          height: 160px;
        }
      }
      .bottom {
        border-top: 2px solid #D8DDE6;
        padding: 32px;
        .text {
          line-height: 40px;
          font-family: PingFangSC-Regular;
          font-size: 28px;
          color: #666;
          letter-spacing: 0.58px;
        }
        span {
          display: inline-block;
          color: #3975C6;
          margin-right: 32px;
        }
      }
    }
  }
}
</style>
