<template>
  <div class="list">
    <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="select-box">
        <div class="left">
          <AiAreaPicker v-model="areaId" :areaId="user.areaId" :name.sync="areaName" @select="areaSelect" selectRoot>
            <div>
              <span v-if="areaId" style="color:#333;fontSize: 14px;" class="areaName">{{ areaName }}</span>
              <span v-else style="color: #999;fontSize: 14px;" class="areaName">所在地区</span>
              <u-icon name="arrow-down" color="#999" size="24" style="margin-left: 4px;width: 14px;display:inline-block;margin-top:18px" @select="areaSelect(e)"></u-icon>
            </div>
          </AiAreaPicker>
        </div>
        <div class="right">
          <AiSelect v-model="declareReason" :list="riskList" @data="typeSelect">
            <span v-if="!declareReason" style="color: #999;">风险类型</span>
            <span v-else>{{ $dict.getLabel('helpDeclarationReason', declareReason) }}</span>
            <u-icon name="arrow-down" color="#999" size="24" style="margin-left: 4px;width: 14px;display:inline-block;"></u-icon>
            <!-- <u-icon name="close-circle" v-if="declareReason" @click="clearReason" color="#999" size="24"></u-icon> -->
          </AiSelect>
        </div>
      </div>
    </AiTopFixed>
    <div v-if="list.length">
      <div class="card_list">
        <div class="card" v-for="(item,index) in list" :key="index" @click="toDetail(item.id)">
          <div class="top">
            <div class="title">{{ item.riskDescription }}</div>
            <div class="time">{{ item.declareTime }}</div>
          </div>
          <div class="bottom">
            <span :style="{background: item.status == 0? '#FF883C':item.status == 1? '#1AAAFF': item.status==2? '#FF4466': '#42D784'}"></span>
            <span :class="item.status == 0? 'status0': item.status==1? 'status1': item.status==2? 'status3': 'status2'">{{ $dict.getLabel('helpDeclarationStatus',item.status) }}</span>
          </div>
        </div>
      </div>
    </div>
    <AiEmpty v-else description="暂无数据"/>

    <!-- <AiFixedBtn>
      <div class="addBtn iconfont iconfont-iconfangda" @tap="toAdd()"/>
    </AiFixedBtn> -->
    <div style="height: 56px"></div>
    <div class="btn" @click="toAdd">申请帮扶</div>

  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      tabs: ['全部待办','办理历史'],
      tabIndex: 0,
      current: 1,
      areaId: '',
      areaName: '',
      declareReason: '',
      list: [],
      riskList: [],
    }
  },
  computed: {
    ...mapState(['user'])
  },
  onShow() {
    this.$dict.load('helpDeclarationStatus').then(() => {
      this.riskList = this.$dict.getDict('helpDeclarationReason').map((item) => ({
        label: item.dictName,
        value: item.dictValue
      }))
      this.riskList.unshift({label: "全部", value: ""})
      uni.$on('update', () => {
        this.getList()
      })
    })
    this.getList()
  },
  methods: {
    tabClick(index) {
      this.current = 1,
      this.list = [],
      this.tabIndex = index,
      this.getList()
    },

    areaSelect(e) {
      this.areaId =e
      this.$nextTick(() => {
        this.getList()
      })
    },

    typeSelect(e) {
      this.declareReason = e[0].value
      this.current = 1,
      this.list = [],
      this.getList()
    },

    clearArea() {
      this.areaId = '',
      this.areaName = '',
      this.current = 1,
      this.list = [],
      this.getList()
    },

    clearReason() {
      this.declareReason = '',
      this.current = 1,
      this.list = [],
      this.getList()
    },

    getList() {
      this.$http.post('/app/apphelpdeclarationinfo/listByEw',null,{
        params: {
          current: this.current,
          searchType: this.tabIndex,
          areaId: this.areaId,
          declareReason: this.declareReason  // 风险类型
        }
      }).then((res) => {
        if(res?.data) {
          this.list = this.current == 1? res.data.records : [...this.list,...res.data.records]
        }
      })
    },

    toAdd() {
       uni.navigateTo({url: './add'})
    },

    toDetail(id) {
      uni.navigateTo({url: `./details?id=${id}`})
    },

    onReachBottom() {
      this.current ++
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
.list {
  ::v-deep .AiTopFixed .content {
    padding: 0;
  }
  ::v-deep .AiSelect .display{
    justify-content: center;
  }

  .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;
      }
    }
  }

  .select-box {
    display: flex;
    height: 96px;
    line-height: 96px;
    width: 100%;
    .left,
    .right {
      flex: 1;
      text-align: center !important;
      font-size: 28px;

      ::v-deep .u-icon .uicon-close-circle{
        top: -96px !important;
        left: 80px;
        margin-left: 30px;
        width: 14px;
        display:inline-block;
      }
    }
  }

  .card_list {
    padding: 24px 32px;
    box-sizing: border-box;
    .card {
      background: #FFFFFF;
      box-shadow: 0px 0px 8px 0px #00000005;
      border-radius: 16px;
      margin-bottom: 24px;
      .top {
        padding: 32px;
        box-sizing: border-box;
        border-bottom: 2px solid #DDDDDD;
        .title {
          color: #333333;
          font-size: 32px;
          font-weight: 600;
          overflow:hidden; 
          text-overflow:ellipsis;
          display:-webkit-box;
          -webkit-box-orient:vertical;
          -webkit-line-clamp:2;
        }
        .time {
          margin-top: 32px;
          color: #999999;
          font-size: 26px;
        }
      }
      .bottom {
        padding: 32px;
        box-sizing: border-box;
        span:first-child {
          display: inline-block;
          width: 8px;
          height: 8px;
          border-radius: 50%;
          margin-right: 8px;
          background: #FF4466;
        }
      }
      .status0 {
        color: #FF883C
      }
      .status1 {
        color: #1AAAFF
      }
      .status2 {
        color: #42D784
      }
      .status3 {
        color: #FF4466
      }
    }
  }

  .btn {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 112px;
    line-height: 112px;
    text-align: center;
    color: #FFF;
    background: #3975C6;
  }
}
</style>