<template>
  <a-row>
    <a-col
      v-for="(one, index) in ['sjry', 'xmzs', 'yqdxm', 'dg', 'sjfx', 'sjzg']"
      :key="one"
      :span="4"
      :class="one + '-col'"
    >
      <div :class="$style.mainDiv" @click="fnOpenModel(one)">
        <div :class="$style.leftDiv">
          <div :class="$style.title">{{ title[index] }}</div>
          <div :class="$style.number">{{ number[index] }}</div>
        </div>
        <div :class="$style.rightDiv">
          <a-avatar :style="{ backgroundColor: bgcolor[index] }" :class="$style.avatar" :size="65">
            <template v-slot:icon>
              <sd-icon
                :style="{
                  marginLeft: index === 0 ? '5px' : '0px',
                  marginTop: index === 3 ? '20px' : '0px',
                }"
                :type="icon[index]"
                theme="fill"
              >
              </sd-icon>
            </template>
          </a-avatar>
        </div>
      </div>
    </a-col>
  </a-row>
</template>

<script>
import axios from '@/common/services/axios-instance'
import iamAuditDscService from './iam-audit-dsc-service'
import components from './_import-components/iam-audit-dsc-top-div-import'

export default {
  name: 'IamAuditDscTopDiv',
  metaInfo: {
    title: 'IamAuditTopDiv',
  },
  components,
  props: {
    /**
     * 统计的组织ID
     */
    unidId: {
      type: Array,
      default: () => {
        return []
      },
    },
    /**
     * 统计的年份
     */
    planYear: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      icon: [
        'sd-audit-dsc-user-icon',
        'sd-audit-dsc-project-all-icon',
        'sd-audit-dsc-project-start-icon',
        'sd-audit-dsc-gzdg-icon',
        'sd-audit-dsc-find-icon',
        'sd-audit-dsc-rectify-icon',
      ],
      title: [
        '审计人员数',
        '项目总数',
        '已启动项目数',
        '底稿数量',
        '审计发现数量',
        '已整改问题数量',
      ],
      bgcolor: ['#bb7ec4', '#ffb648', '#ff4a55', '#00a389', '#54c5eb', '#bb7ec4'],
      number: [],
    }
  },
  computed: {
    // 因为props传值不会自动更新，使用计算值
    selectYear() {
      return this.planYear
    },
    // 因为props传值不会自动更新，使用计算值
    selectUnidId() {
      if (this.unidId.length > 0) {
        return this.unidId[0].id
      } else {
        return null
      }
    },
    // 因为props传值不会自动更新，使用计算值
    selectUnidText() {
      if (this.unidId.length > 0) {
        return this.unidId[0].name
      } else {
        return null
      }
    },
  },
  watch: {
    // 年份和组织变化时，重新加载数据
    selectYear() {
      this.getData()
    },
    selectUnidId() {
      this.getData()
    },
  },
  created() {
    // 创建时获取内容
    this.getData()
  },
  methods: {
    /**
     * 打开对应的模块
     */
    fnOpenModel(type) {
      // 审计人员
      if (type === 'sjry') {
        if (this.selectUnidId) {
          iamAuditDscService.getOrgId(this.selectUnidId).then((res) => {
            window.open(
              `#/iam-audit-dsc-userbase-list?depid=${res.data}&deptext=${this.selectUnidText}`
            )
          })
        } else {
          window.open(`#/iam-audit-dsc-userbase-list`)
        }
      }
      // 所有项目列表
      if (type === 'xmzs') {
        window.open(
          '#/iam-audit-dsc-project-list?params={"unitNames":"\'' +
            this.selectUnidText +
            '\'","planYear":"' +
            this.selectYear +
            '","unitIds":"' +
            this.selectUnidId +
            '"}&type=projectlist'
        )
      }
      // 已启动项目列表
      if (type === 'yqdxm') {
        window.open(
          '#/iam-audit-dsc-project-list?params={"unitNames":"\'' +
            this.selectUnidText +
            '\'","planYear":"' +
            this.selectYear +
            '","status":"start","unitIds":"' +
            this.selectUnidId +
            '"}&type=projectlist'
        )
      }
      // 底稿
      if (type === 'dg') {
      }
      // 审计发现
      if (type === 'sjfx') {
        window.open(
          '#/iam-audit-dsc-find-list?params={"unitNames":"\'' +
            this.selectUnidText +
            '\'","dateStart":"' +
            this.selectYear +
            '","dimension":"decision","unitIds":"' +
            this.selectUnidId +
            '"}&type=projectlist'
        )
      }
      // 已整改问题数量
      if (type === 'sjzg') {
        window.open(
          '#/iam-audit-dsc-rectify-list?params={"unitNames":"\'' +
            this.selectUnidText +
            '\'","dateStart":"' +
            this.selectYear +
            '","dimension":"decision","unitIds":"' +
            this.selectUnidId +
            '"}&type=projectlist'
        )
      }
    },
    /**
     * 初始化数据
     */
    getData() {
      this.number = []
      // 获取整体数量
      const params = {
        unitId: this.selectUnidId,
        planYear: this.selectYear,
      }
      if (this.selectUnidId) {
        iamAuditDscService.getAllNumResult(params).then((res) => {
          // 按顺序将内容写入
          const data = res.data
          // 审计人员数量
          this.number.push(data.PERSON_NUM)
          // 项目总数
          this.number.push(data.PROJECT_TOTAL_NUM)
          // 已启动项目数
          this.number.push(data.STARTED_PROJECT_NUM)
          // 底稿数量
          this.number.push(data.PAPER_NUM)
          // 审计发现数量
          this.number.push(data.FIND_NUM)
          // 已整改问题数量
          this.number.push(data.RECT_NUM)
        })
      }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.main-div {
  display: flex;
  height: 105px;
  margin: 0 10px;
  cursor: pointer;
  background: #fff;
  border-radius: 10px;
  .left-div {
    display: flex;
    flex-direction: column;
    width: 70%;
    padding-left: 22px;
    .title {
      height: 40%;
      font-weight: 600;
      line-height: 60px;
    }
    .number {
      height: 60%;
      font-size: 45px;
      font-weight: 700;
      line-height: 45px;
    }
  }
  .right-div {
    width: 30%;
    .avatar {
      margin-top: 20px;
    }
  }
}
:global(.dg-col) {
  .main-div {
    cursor: not-allowed;
  }
}
</style>
