<template>
  <m-card title="美丽家园">
    <div class="container">
      <m-sub2>项目实施情况</m-sub2>
      <div class="summary">
        <div v-for="item in summary" :key="item.name">
          <m-count class="count orange-count" :value="item.value" />
          <p>{{ item.name }}</p>
        </div>
      </div>
      <Brief :list="situation" color="#fff" />
      <m-sub2 :addition="{ value: 33, unit: '幢' }">电梯加装（排摸）</m-sub2>
      <div class="sum-card">
        <div
          v-for="item in elevList"
          :key="item.cmtName"
          :class="{ on: curCmtName === item.cmtName }"
          @click="handleSelect(item.cmtName)"
        >
          <p>{{ item.cmtName }}</p>
          <m-count class="count" :value="item.num" />
        </div>
      </div>
      <m-sub2>马桶改造</m-sub2>
      <Brief :list="toiletSituation" color="#fff" />
      <m-progress
        :value="
          Math.round(
            (toiletSituation[0].value / toiletSituation[1].value) * 100
          )
        "
        :color="['rgba(253,211,116,.15)', '#F7933E']"
        :msg="{
          value: Math.round(
            (toiletSituation[0].value / toiletSituation[1].value) * 100
          ),
          unit: '%',
          name: '改造进度',
          color: '#fff',
        }"
      />
    </div>
  </m-card>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted, ref } from 'vue'
import Brief, { BriefProp } from '../components/brief.vue'
import store from '@/store'
import icon31 from '@/assets/images/icon31.png'
import icon32 from '@/assets/images/icon32.png'
import icon33 from '@/assets/images/icon33.png'
import icon34 from '@/assets/images/icon34.png'
import icon35 from '@/assets/images/icon35.png'
import icon36 from '@/assets/images/icon36.png'
import { ajax, api } from '@/ajax'

export default defineComponent({
  name: 'BeautyHome',
  components: { Brief },
  setup() {
    const summary = ref([
      { name: '2020年', value: 26 },
      { name: '2019年', value: 24 },
      { name: '2018年', value: 18 },
    ])
    const situation = ref<BriefProp[]>([
      { name: '小区微更新', value: 26, icon: icon31 },
      { name: '门岗规范化', value: 12, icon: icon32 },
      { name: '充电桩', value: 64, icon: icon33 },
      { name: '雨污混接', value: 18, icon: icon34 },
    ])
    const elevList = computed(() => store.state.elevCount)
    const curCmtName = ref<string | null>(null)
    const handleSelect = async (name: string) => {
      curCmtName.value === name
        ? (curCmtName.value = null)
        : (curCmtName.value = name)
      if (!curCmtName.value) return

      const { content } = (
        await ajax.get({ url: api.GET_ELEV_LIST, params: { cmtName: name } })
      ).data
      // TODO 可能要出列表或者地图撒点之类的
      console.log(`美丽街区-加装电梯-${name}区域电梯列表`, content)
    }
    const toiletSituation = ref<BriefProp[]>([
      { name: '已完成改造', value: 0, icon: icon35 },
      { name: '应改造', value: 0, icon: icon36 },
    ])
    onMounted(async () => {
      const { content } = (await ajax.get({ url: api.GET_TOILET })).data
      toiletSituation.value[0].value = content.completeNum
      toiletSituation.value[1].value = content.totalNum
    })
    const workStationProjects = ref([
      { name: '架空线梳理', value: 16 },
      { name: '店招店牌美化', value: 26 },
      { name: '绿化整治', value: 15 },
      { name: '外立面整治', value: 8 },
      { name: '公共设置', value: 8 },
    ])
    return {
      summary,
      situation,
      elevList,
      curCmtName,
      handleSelect,
      toiletSituation,
      workStationProjects,
    }
  },
})
</script>

<style lang="stylus" scoped>
@import '../../components/MyComponent/main.styl'
.container
  height 100%
  display flex
  flex-direction column
  justify-content space-around
.summary
  width 100%
  display flex
  justify-content space-between
  >div
    display flex
    align-items center
    justify-content space-around
    width 24%
    padding .05rem
    .count
      font-size .14rem
      font-family $font-barlow
      margin-right .03rem
    p
      font-size .09rem
.sum-card
  display flex
  flex-wrap wrap
  justify-content space-between
  >div
    display flex
    justify-content space-between
    align-items center
    width 49%
    $card-bg2()
    padding 0 .1rem
    margin-bottom .05rem
    cursor pointer
    transition all .3s ease
    &:hover
    &.on
      $card-bg2(0.8, 0.4)
    .count
      font-size .12rem
      font-weight bold
</style>
