<template>
  <m-card mode="border">
    <m-card class="card" title="管理基数">
      <div class="basic">
        <div v-for="item in basicList" :key="item.name">
          <p>
            <img :src="item.icon" />
            {{ item.name }}
          </p>
          <p>
            <m-count
              class="count"
              :value="item.value"
              :decimal="item.decimal || 0"
            />
            <span>{{ item.unit }}</span>
          </p>
        </div>
      </div>
    </m-card>
    <m-card class="card" title="指挥体系">
      <div class="command">
        <div class="flag">
          <img src="@/assets/images/wangge.png" />
          <img src="@/assets/images/jingzhang.png" />
        </div>
        <div class="leader">
          <div v-for="(item, i) in leaders" :key="i">
            <img :src="item.img" />
            <div>
              <p>{{ item.name }}</p>
              <span>{{ item.type }}</span>
            </div>
          </div>
        </div>
      </div>
    </m-card>
    <m-card class="card" title="网格力量">
      <div class="table">
        <div>
          <p>部门</p>
          <p>人员</p>
        </div>
        <div v-for="(item, i) in gridList" :key="i">
          <p>{{ item.department }}</p>
          <p>{{ item.persons }}</p>
        </div>
      </div>
    </m-card>
  </m-card>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import pic1 from '@/assets/images/pic1.png'
import pic2 from '@/assets/images/pic2.png'
import pic3 from '@/assets/images/pic3.png'
import pic4 from '@/assets/images/pic4.png'
import avatar1 from '@/assets/images/avatar1.png'
import avatar2 from '@/assets/images/avatar2.png'
import store from '@/store'

export default defineComponent({
  name: 'ManageBasic',
  setup() {
    const stationInfo = computed(() => store.state.stationInfo)
    const basicList = computed(() => {
      const {
        totalArea = 0,
        totalHousehold = 0,
        totalPopulation = 0,
        totalUnit = 0,
      } = stationInfo.value
      return [
        {
          name: '总面积',
          value: totalArea,
          unit: 'k㎡',
          icon: pic1,
          decimal: 2,
        },
        {
          name: '总户数',
          value: totalHousehold,
          unit: '户',
          icon: pic2,
        },
        {
          name: '总人口',
          value: totalPopulation,
          unit: '人',
          icon: pic3,
        },
        {
          name: '总单位',
          value: totalUnit,
          unit: '家',
          icon: pic4,
        },
      ]
    })
    const leaders = computed(() => {
      const {
        gridId = '无',
        viceGridId = '无',
        sheriffId = '无',
      } = stationInfo.value
      return [
        {
          img: avatar1,
          name: gridId,
          type: '网格长',
        },
        {
          img: avatar2,
          name: viceGridId,
          type: '副网格长',
        },
        {
          img: avatar1,
          name: sheriffId,
          type: '警长',
        },
      ]
    })
    const getName = (type: string) => {
      switch (type) {
        case 'pcs':
          return '派出所'
        case 'scs':
          return '市场所'
        case 'cgzd':
          return '城管中队'
        case 'wgzx':
          return '网格中心'
        case 'lhsrs':
          return '绿化市容所'
        case 'djlly':
          return '党建联络员'
        case 'fwqyry':
          return '服务企业人员'
        default:
          return '无'
      }
    }
    const gridList = computed(() => {
      const gridPower =
        stationInfo.value.gridPower &&
        JSON.parse(stationInfo.value.gridPower as string)
      if (!gridPower) return []
      return Object.keys(gridPower).map((key: string) => {
        return {
          department: getName(key),
          persons: gridPower[key],
        }
      })
    })
    return {
      basicList,
      leaders,
      gridList,
    }
  },
})
</script>

<style lang="stylus" scoped>
@import '../../components/MyComponent/main.styl'

.card
  flex 1.8
  &:nth-of-type(2)
    flex 1
.basic
  $full()
  display flex
  flex-direction column
  justify-content space-around
  padding .05rem 0
  >div
    display flex
    align-items center
    justify-content space-between
    height 22%
    background linear-gradient(to right, rgba(30,251,255,.2), transparent)
    border-left .02rem solid $secondary-color
    padding 0 .2rem
    img
      width .26rem
      height @width
      margin-right .1rem
    .count
      color $yellow
      font-size .14rem
      font-family $font-pang
      margin-right .05rem
    span
      color #aaa
      font-size .09rem
.command
  display flex
  .flag
    display flex
    flex-direction column
    justify-content space-around
    margin 0 .3rem 0 .05rem
    >img
      display block
      width .36rem
      height @width
      margin .04rem 0
  .leader
    flex 1
    display flex
    flex-wrap wrap
    >div
      width 50%
      display flex
      align-items center
      p
        font-size .11rem
        font-weight bold
      img
        width .28rem
        height @width
        margin-right .1rem
      span
        color #ccc
.table
  border .01rem solid $blue
  >div
    display flex
    background $table-bg(.15)
    &:first-child
      background $table-bg()
    &+div
      border-top inherit
    p
      flex 1
      line-height 2
      padding 0 .05rem
      overflow hidden
      text-overflow ellipsis
      white-space nowrap
      &+p
        border-left .01rem solid $blue
      &:first-child
        flex 0.4
</style>
