<template>
  <a-row>
    <a-col
      v-for="(one, index) in ['sjdwsl', 'ndsjfgl', 'sjwtfxs', 'yzgwts', 'zgzwts', 'wtsjje']"
      :key="one"
      :span="4"
      :class="one + '-col'"
    >
      <div :class="$style.mainDiv" @click="fnOpenModel(one)">
        <div :class="$style.leftDiv">
          <div :class="$style.number">{{ number[index] }}</div>
          <div :class="$style.title">{{ title[index] }}</div>
        </div>
        <div :class="$style.rightDiv">
          <!-- bgcolor[index]  -->
          <a-avatar style=" background: none" :class="$style.avatar" :size="65">
            <template v-slot:icon>
              <img src="./image/sjdwsl1.png" v-if="one === 'sjdwsl'" />
              <img src="./image/ndsjfgl1.png" v-if="one === 'ndsjfgl'" />
              <img src="./image/sjwtfxs1.png" v-if="one === 'sjwtfxs'" />
              <img src="./image/yzgwts1.png" v-if="one === 'yzgwts'" />
              <img src="./image/zgzwts1.png" v-if="one === 'zgzwts'" />
              <img src="./image/wtsjje1.png" v-if="one === 'wtsjje'" />
            </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-map-top-div-import'

export default {
  name: 'IamAuditMapTopDiv',
  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 = ['66', '36%', '40', '35', '3', '128.28']
      // 获取整体数量
      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: 50%;
      font-weight: 600;
      color: #fff;
      text-align: center;
      // line-height: 60px;
      vertical-align: top;
    }
    .number {
      height: 50%;
      margin-top: 15px;
      font-size: 45px;
      font-weight: 700;
      line-height: 45px;
      color: #fff;
      text-align: center;
    }
  }
  .right-div {
    width: 30%;
    .avatar {
      margin-top: 20px;
    }
  }
}
:global(.dg-col) {
  .main-div {
    cursor: not-allowed;
  }
}
:global(.sjdwsl-col) {
  .main-div {
    background: url('./image/sjdwsl.png') no-repeat center;
  }
}
:global(.ndsjfgl-col) {
  .main-div {
    background: url('./image/ndsjfgl.png') no-repeat center;
  }
}
:global(.sjwtfxs-col) {
  .main-div {
    background: url('./image/sjwtfxs.png') no-repeat center;
  }
}
:global(.yzgwts-col) {
  .main-div {
    background: url('./image/yzgwts.png') no-repeat center;
  }
}
:global(.zgzwts-col) {
  .main-div {
    background: url('./image/zgzwts.png') no-repeat center;
  }
}
:global(.wtsjje-col) {
  .main-div {
    background: url('./image/wtsjje.png') no-repeat center;
  }
}
</style>
