<template>
  <div class="AppNucleicAcidSampling">
    <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="top-search">
        <div class="left">
          <AiAreaPicker v-model="areaId" :areaId="cropAreaId" @select="areaSelect" :name.sync="areaName" style="color: #666" selectRoot>
            <u-icon name="map-fill" color="#3192F4" size="20px" style="vertical-align: text-bottom"></u-icon>
            <span style="margin-left: 4px" v-if="areaName">{{ areaName }}</span>
            <span v-else>请选择</span>
            <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" />
          </AiAreaPicker>
        </div>
        <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>
    </AiTopFixed>
    <div class="data-list" v-if="list && list.length">
      <div class="item" v-for="(item, index) in list" :key="index" @click="toDetail(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>
          <div class="btn" @click.stop="toEdit(item.id)" v-if="item.status != 2">采样</div>
        </div>
      </div>
    </div>
    <AiEmpty description="暂无数据" class="emptyWrap" v-else></AiEmpty>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
 appName: '核酸采样',
  data() {
    return {
      areaId: '',
      areaName: '',
      current: 1,
      keyword: '',
      currentTabs: 0,
      tabList: [
        {
          name: '待采样',
        },
        {
          name: '已采样',
        },
      ],
      barStyle: {
        'width': '24px',
        'height': '2px', 
        'border-radius': '0',
        'bottom': '5px'
      },
      activeStyle: {
        'font-weight' : '400',
      },
      list: [],
      cropAreaId: ''
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad() {
    // this.areaId = this.user.areaId
    // this.areaName = this.user.areaName
    this.$dict.load('EP_CM_status', 'EP_registerInfoType').then(() => {
      this.getListInit()
    })
     uni.$on('updateList', () => {
      this.getListInit()
    })
    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() {
      this.$http.post('/app/appepidemicpreventioncommunitymanagement/list', null, {
        params: { size: 10, current: this.current, queryType: this.currentTabs, areaId: this.areaId, name: this.keyword},
      }).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(id) {
      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()
    },
    typeConfirm(e) {
      this.infoType = e[0].value
      this.getListInit()
    }
  },
  onReachBottom() {
    this.current++
    this.getList()
  },
}
</script>

<style scoped lang="scss">
.AppNucleicAcidSampling {
  height: 100%;
  ::v-deep .AiTopFixed {
    .placeholder {
      .content {
        padding: 0 !important;
      }
    }
    .fixed {
      margin: 0 !important;
      .content {
        padding: 0 !important;
      }
    }
  }
  .top-search {
    padding: 20px 32px;
    display: flex;
    .left{
      width: calc(100% - 402px);
    }
  }
  .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;
            }
          }
          .status1 {
            color: #1CCEB0;
            .cir  {
              background-color: #1CCEB0;
            }
          }
        }
        p {
          line-height: 40px;
          font-family: PingFangSC-Regular;
          font-size: 28px;
          color: #666;
          margin-bottom: 8px;
        }
        .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: 32px;
          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>
