<template>
  <section class="earlyWarning">
    <ai-top-fixed>
      <u-search v-model="search.name" placeholder="请输入姓名" :show-action="false"
                search-icon-color="#ccc" placeholder-color="#999"
                @change="page.current=1,getList()"/>
      <div flex>
        <ai-date class="fill" placeholder="日期选择" mode="range" @change="handleDateSearch"/>
        <ai-select class="fill" dict="intelligentGuardianshipItem2" @data="handleTypeSearch">
          <div>{{ $dict.getLabel('intelligentGuardianshipItem2', search.item) || '全部预警' }}</div>
          <i class="iconfont iconfont-iconArrow_Down"/>
        </ai-select>
      </div>
    </ai-top-fixed>
    <div class="card" v-for="row in list" :key="row.id" @tap="handleShow(row)">
      <div class="header" flex>
        <img :src="top.cdn(typeIcons[row.item])"/>
        <b v-text="row.desc"/>
      </div>
      <div class="wrapper">
        <div class="start" flex>
          <span v-text="`上报时间:`"/>
          <div v-text="row.createTime"/>
        </div>
        <div class="start" flex>
          <span v-text="`上报地点:`"/>
          <div v-text="row.gpsDesc"/>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import AiTopFixed from "../../components/AiTopFixed";
import {mapState} from "vuex";
import AiDate from "../../components/AiDate";
import AiSelect from "../../components/AiSelect";

export default {
  name: "earlyWarning",
  components: {AiSelect, AiDate, AiTopFixed},
  inject: ['top'],
  computed: {
    ...mapState(['user']),
    typeIcons() {
      return {
        0: "icon4",
        1: "icon2",
        2: "icon5",
        3: "icon6",
        4: "icon3",
        5: "icon1",
      }
    }
  },
  data() {
    return {
      search: {name: "", createTimeRange: ",", item: ""},
      areaId: "",
      page: {current: 1, size: 10, total: 0},
      list: []
    }
  },
  methods: {
    getList() {
      let {areaId} = this
      this.$http.post("/app/appintelligentguardianshipalarm/list", null, {
        params: {areaId, ...this.search, ...this.page}
      }).then(res => {
        if (res?.data) {
          let data = res.data.records.map(e => {
            return {...e, desc: [e.name, this.$dict.getLabel('intelligentGuardianshipItem2', e.item)].join('的')}
          })
          if (this.page.current > 1) {
            this.list = [...this.list, ...data]
          } else this.list = data
          this.page.total = res.data.total
        }
      })
    },
    reachBottom() {
      if (this.page.total > this.list.length) {
        this.page.current++
        this.getList()
      }
    },
    handleDateSearch(v) {
      let {startDate: start, endDate: end} = v
      start = this.$dateFormat(start)
      end = this.$dateFormat(end)
      this.search.createTimeRange = [start, end || start].toString()
      this.page.current = 1
      this.getList()
    },
    handleTypeSearch(v) {
      this.search.item = v?.[0]?.value
      this.page.current = 1
      this.getList()
    },
    handleShow(row) {
      uni.navigateTo({url: `./warningDetail?id=${row.id}`})
    }
  },
  created() {
    this.areaId = JSON.parse(JSON.stringify(this.user.areaId))
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.earlyWarning {
  padding-bottom: 130px;
  background: #f5f5f5;

  ::v-deep .AiDate > div {
    justify-content: center;
  }

  ::v-deep .u-drawer-content {
    padding-bottom: 100px;
  }

  ::v-deep .display {
    justify-content: center;
  }

  ::v-deep .iconfont-iconArrow_Down {
    margin-left: 4px;
    font-size: 32px;
    color: inherit;
  }

  ::v-deep .card {
    margin: 32px 32px 0;
    background: #FFFFFF;
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.02);
    border-radius: 8px;

    .header {
      padding: 0 32px;
      height: 104px;
      border-bottom: 2px solid #EFEFF4;
      font-size: 36px;

      img {
        width: 64px;
        height: 64px;
        margin-right: 16px;
      }
    }

    .wrapper {
      color: #343D65;
      font-size: 30px;
      margin-bottom: 8px;
      padding: 18px 32px;

      span {
        white-space: nowrap;
        flex-shrink: 0;
        color: #999;
        margin-right: 20px;
      }
    }
  }
}
</style>
