<template>
  <div class="list">
    <div class="top-tab" :style="{'top': `${statusBarHeight+50}px`}">
      <u-tabs :list="tabList" :is-scroll="false" :current="currentTabs" height="96" bg-color="#fff" inactive-color="#222"
        active-color="#1D2229" :bar-style="barStyle"  font-size="34" @change="change"></u-tabs>
      <div class="select-top">
        <div class="tab-item">
          <AiPagePicker type="gird" valueObj nodeKey="id" formType="2" @select="handleSelectGird" action="/app/appgirdmemberinfo/queryMyGirdList">
            <span :class="searchGrid.girdName ? 'grid-name' : 'grid-name color-666'">{{searchGrid.girdName || '所属网格'}}</span>
            <u-icon name="arrow-down" color="#999" size="24" style="margin-left: 4px" />
          </AiPagePicker>
        </div>
        <div class="tab-item" @click="showType = true">
          <span :class="eventStatusText ? 'grid-name' : 'grid-name color-666'">{{eventStatusText || '办件状态'}}</span>
          <u-icon name="arrow-down" color="#999" size="24" style="margin-left: 4px" />
        </div>
        <u-select v-model="showType" :list="listType" value-name="dictValue" label-name="dictName" @confirm="confirm"></u-select>
      </div>
    </div>
    <div class="list-content">
      <div class="item" v-for="(item, i) in datas" :key="i" @click.native="goDetail(item, 1)">
        <div class="card-top">
          <div class="titles">{{ item.content }}</div>
          <div class="source-type">{{ $dict.getLabel('residentEventSource', item.eventSource) }}</div>
          <div class="info">
            <span>事件类型</span>
            <span class="value">{{ item.groupName }}</span>
          </div>
          <div class="info">
            <span>所属网格</span>
            <span class="value">{{ item.girdName }}</span>
          </div>
        </div>
        <div class="card-bottom">
          <div class="status" v-if="item.eventStatus"
            :class="item.eventStatus == 0 ? 'status0' : item.eventStatus == 1 ? 'status1' : item.eventStatus == 2 ? 'status2' : 'status3'">
            <span class="icon"></span>
            <span>{{ $dict.getLabel('clapEventStatus', item.eventStatus) }}</span>
          </div>
          <div class="level-type">中风险纠纷</div>
        </div>
      </div>
      <AiEmpty v-if="!datas.length" />
    </div>
    <div class="ai-add" v-if="isAdd" @click="toAdd"></div>
    <!-- <AiAdd @add="toAdd" /> -->
    
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  customNavigation: true,
  props: {},
  data() {
    return {
      datas: [],
      tabList: [
        {
          name: '全部待办',
        },
        {
          name: '办件历史',
        },
      ],
      currentTabs: 0,
      current: 1,
      pages: 0,
      searchGrid: {girdName: ''},
      showType: false,
      eventStatus: '',
      eventStatusText: '',
      isAdd: true,
      barStyle: {
        'width': '20px',
        'height': '4px',
        'border-radius': '3px',
        'bottom': '-4px',
        'background': '#026AF2'
      },
      statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
    }
  },
  computed: {
    ...mapState(['user']),
    listType() {
      return this.$dict.getDict(this.currentTabs == 0 ? 'clapEventStatusAll' : 'clapEventStatusHistory')
    }
  },
  mounted() {
    console.log(1)
    this.searchGrid.girdId = this.user.girdId
    this.searchGrid.girdName = this.user.girdName
    this.current = 1
    this.$dict.load('clapEventStatus', 'clapEventStatusAll', 'clapEventStatusHistory', 'residentEventSource').then(() => {
      this.getList()
      this.getIsAdd()
    })
  },
  methods: {
    getListInit() {
      this.current = 1
      this.getList()
    },
    nextPage() {
      this.current++
      this.getList()
    },
    getList() {
      let {current, eventStatus, searchGrid: {id: girdId}} = this
      this.$instance.post(`/app/apppatrolreportinfov2/listByGirdMember`, null, {
        params: {
          size: 10,
          current, 
          eventStatus, 
          girdId,
          searchType: this.currentTabs,
        },
      }).then((res) => {
        if (res.code == 0) {
          this.datas = this.current > 1 ? [...this.datas, ...res.data.records] : res.data.records
          this.pages = res.data.pages
          this.$forceUpdate()
        }
      })
    },

    confirm(e) {
      if (this.showType) {
        this.eventStatus = e[0].value
        this.eventStatusText = e[0].label
      }
      this.current = 1
      this.getList()
    },

    handleSelectGird(v) {
      this.searchGrid = v
      this.current = 1
      this.getList()
    },
    clearGrid() {
      this.searchGrid = {girdName: ''}
      this.current = 1
      this.getList()
    },

    goDetail(item) {
      uni.navigateTo({url: `./Detail?id=${item.id}&isShowBtn=1`})
    },

    change(index) {
      this.current = 1
      this.datas = []
      this.eventStatus = ''
      this.currentTabs = index
      this.getList()
    },

    linkTo(url) {
      uni.navigateTo({url})
    },
    toAdd() {
      console.log(123)
      uni.navigateTo({url: './Add'})
    },

    getIsAdd() {
      this.$instance.post(`/app/apppatrolreportinfov2/checkGirdMemberUser`).then((res) => {
        if (res.code == 0) {
          this.isAdd = res.data
        }
      })
    },
  },
}
</script>

<style scoped lang="scss">
.list {
  height: 100%;
  padding: 0;
  width: 100vw;

  .top-tab {
    width: calc(100% - 64px);
    box-sizing: border-box;
    position: fixed;
    left: 32px;
    z-index: 9;
  }

  ::v-deep .u-tabs {
    border-bottom: 1px solid #eee;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
  }

  .select-top {
    background: #fff;
    display: flex;
    padding: 24px 0;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;

    .tab-item {
      flex: 1;
      text-align: center;
      line-height: 48px;
      font-size: 26px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #666;

      img {
        width: 32px;
        height: 32px;
        margin-left: 8px;
        vertical-align: middle;
      }
    }

    .grid-name {
      display: inline-block;
      line-height: 40px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 28px;
      color: #333;
    }
    .color-666 {
      color: #666;
    }
  }

  .list-content {
    margin: 244px 0 200px 32px;
  }

  .item {
    width: calc(100% - 32px);
    background: #FFF;
    box-shadow: 0 0 4px 0 #00000005;
    border-radius: 16px;
    margin-bottom: 32px;
    .card-top {
      width: 100%;
      padding: 32px 32px 24px 32px;
      box-sizing: border-box;
      position: relative;
      .titles {
        width: calc(100% - 132px);
        word-break: break-all;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-height: 44px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 32px;
        color: #333;
        margin-bottom: 24px;  
      }
      .source-type {
        padding: 0 10px;
        line-height: 44px;
        background-color: #EBF3FE;
        border-radius: 6px;
        font-family: PingFangSC-Regular;
        font-size: 24px;
        color: #3D88F5;
        position: absolute;
        top: 32px;
        right: 32px;
      }

      .info {
        line-height: 40px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        font-size: 28px;
        color: #999;
        margin-bottom: 8px;

        .value {
          display: inline-block;
          margin-left: 24px;
          color: #333;
        }
      }
    }

    .card-bottom {
      display: flex;
      justify-content: space-between;
      padding: 32px;
      border-top: 1px solid #ddd;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 28px;
    }

    .status {
      .icon {
        display: inline-block;
        width: 16px;
        height: 16px;
        vertical-align: middle;
        margin-right: 16px;
        border-radius: 50%;
      }
    }

    .status0 {
      color: #ff883c;

      .icon {
        background: #ff883c;
      }
    }

    .status1 {
      color: #1aaaff;

      .icon {
        background: #1aaaff;
      }
    }

    .status2 {
      color: #42d784;

      .icon {
        background: #42d784;
      }
    }

    .status3 {
      color: #ff4466;

      .icon {
        background: #ff4466;
      }
    }

    .level-type0 {
      color: #52C75B;
    }
    .level-type1 {
      color: #FF883C;
    }
    .level-type2 {
      color: #FF3C3C;
    }
    
  }

  .ai-add {
    width: 96px;
    height: 96px;
    background: #1365DD;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    position: fixed;
    bottom: 240px;
    right: 32px;

    &:before, &:after {
      content: "";
      background: #FFFFFF;
      display: block;
      position: absolute;
      border-radius: 4px;
    }

    &:before {
      height: 48px;
      width: 4px;
    }

    &:after {
      height: 4px;
      width: 48px;
    }
  }
}
</style>
