<template>
  <m-card title="勤务">
    <Brief class="brief" :list="summary" />
    <Tabs class="tabs" :list="tabs" horizontal @select="curTab = $event" />
    <div class="details">
      <m-scroll
        v-if="caseList.length > 0"
        :limit="4"
        :length="caseList.length"
        :step="1.1"
        mode="2"
      >
        <div v-for="item in caseList" :key="item.id" class="detail">
          <div class="title">
            <p>{{ item.communityName }}</p>
            <span />
            <p>
              {{
                item.businsessTypeLv1.split('-')[2] || item.troublePhenomenon
              }}
            </p>
          </div>
          <div class="msg">
            <p>{{ item.address }}</p>
            <p>{{ item.acceptTime }}</p>
          </div>
          <m-step :steps="steps" :current="steps.indexOf(item.phase)" />
        </div>
      </m-scroll>
      <m-empty v-else />
    </div>
  </m-card>
</template>

<script lang="ts">
import { computed, defineComponent, ref, watch } from 'vue'
import Brief from '../components/brief.vue'
import Tabs, { TabsProp } from '../components/tabs.vue'
import store from '@/store'
import icon6 from '@/assets/images/icon6.png'
import icon7 from '@/assets/images/icon7.png'
import icon8 from '@/assets/images/icon8.png'

export default defineComponent({
  name: 'Duty',
  components: { Brief, Tabs },
  setup() {
    const summary = computed(() => {
      const {
        comprehensiveNum = 0,
        comprehensiveEndNum = 0,
        streetNum = 0,
        streetEndNum = 0,
        communityNum = 0,
        communityEndNum = 0,
      } = store.state.dutySum
      return [
        {
          name: '综合管理',
          value: [comprehensiveEndNum, comprehensiveNum],
          icon: icon6,
        },
        {
          name: '街面管理',
          value: [streetEndNum, streetNum],
          icon: icon7,
        },
        {
          name: '小区管理',
          value: [communityEndNum, communityNum],
          icon: icon8,
        },
      ]
    })
    const curTab = ref('综合')
    const tabs = ref<TabsProp[]>([
      { name: '综合管理', key: '综合' },
      { name: '街面管理', key: '街面' },
      { name: '小区管理', key: '小区' },
    ])
    const steps = ref(['发现', '立案', '派遣', '处置', '核查', '结案'])
    const caseList = computed(() => store.state.dutyList)
    watch(
      [() => curTab.value, () => store.state.curView.id],
      ([type, id]) => {
        if (!id) return
        store.dispatch('getDutyList', {
          gridId: id,
          managementType: type,
          pageSize: 100,
        })
      },
      { immediate: true }
    )
    return {
      summary,
      curTab,
      tabs,
      caseList,
      steps,
    }
  },
})
</script>

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

.details
  height 3.6rem
  overflow hidden
  .detail
    display flex
    flex-direction column
    justify-content space-between
    padding .1rem
    background url('@/assets/images/border2.png') 100% / 100% 100% no-repeat
    height 1rem
    margin-bottom .1rem
    box-sizing border-box
    .title
      display flex
      align-items center
      p
        font-size .12rem
        &:last-child
          color $edge
          font-size .1rem
      span
        display block
        height .01rem
        background $blue
        flex 1
        margin 0 .1rem
    .msg
      $center()
      justify-content space-between
      color $blue
      font-size .08rem
</style>
