<template>
  <span>
    <audit-form-top-banner>
      <div class="title_sd-detail-form_common">模型授权详情</div>
      <table
        ><tr
          ><td style="border:none">
            <audit-advanced-group
              :expand="cateGoryShow"
              :expand-str="'cateGoryShow'"
              :group-label="'模型列表'"
              @changedClick="changedClick"
            ></audit-advanced-group> </td></tr
      ></table>

      <SdTable
        v-if="cateGoryShow"
        ref="maintaintable"
        :row-key="(record, index) => index"
        :loading="false"
        class="maintaintable"
        :data-source="modelList"
        :columns="columns"
        :pagination="false"
        :bordered="true"
      />
      <table :class="$style.tableTop"
        ><tr
          ><td style="border:none">
            <audit-advanced-group
              :group-label="'授权单位'"
              :expand="unitShow"
              :expand-str="'unitShow'"
              @changedClick="changedClick"
            ></audit-advanced-group> </td></tr
      ></table>

      <SdTable
        v-if="unitShow"
        ref="maintaintable"
        :row-key="(record, index) => index"
        :loading="false"
        class="maintaintable"
        :data-source="unitList"
        :columns="unitColumns"
        :pagination="false"
        :bordered="true"
      >
        <template slot="empowerType" slot-scope="text, record">
          <span v-if="text === '0'">期间</span>
          <span v-else-if="text === '1'">永久</span>
          <span v-else-if="text === '2'">近一年</span>
        </template>
        <template slot="startDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
        <template slot="endDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
      </SdTable>
      <table :class="$style.tableTop"
        ><tr
          ><td style="border:none">
            <audit-advanced-group
              :group-label="'授权人员'"
              :expand="peoShow"
              :expand-str="'peoShow'"
              @changedClick="changedClick"
            ></audit-advanced-group> </td></tr
      ></table>

      <SdTable
        v-if="peoShow"
        ref="maintaintable"
        :row-key="(record, index) => index"
        :loading="false"
        class="maintaintable"
        :data-source="peoList"
        :columns="peoColumns"
        :pagination="false"
        :bordered="true"
      >
        <template slot="empowerType" slot-scope="text, record">
          <span v-if="text === '0'">期间</span>
          <span v-else-if="text === '1'">永久</span>
          <span v-else-if="text === '2'">近一年</span>
        </template>
        <template slot="startDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
        <template slot="endDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
      </SdTable>
      <table :class="$style.tableTop"
        ><tr
          ><td style="border:none">
            <audit-advanced-group
              :group-label="'授权项目'"
              :expand="projectShow"
              :expand-str="'projectShow'"
              @changedClick="changedClick"
            ></audit-advanced-group> </td></tr
      ></table>

      <SdTable
        v-if="projectShow"
        ref="maintaintable"
        :row-key="(record, index) => index"
        :loading="false"
        class="maintaintable"
        :data-source="projectList"
        :columns="projectColumns"
        :pagination="false"
        :bordered="true"
      >
        <template slot="empowerType" slot-scope="text, record">
          <span v-if="text === '0'">期间</span>
          <span v-else-if="text === '1'">永久</span>
          <span v-else-if="text === '2'">近一年</span>
        </template>
        <template slot="startDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
        <template slot="endDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
      </SdTable>

      <table :class="$style.tableTop"
        ><tr
          ><td style="border:none">
            <audit-advanced-group
              :group-label="'授权人员'"
              :expand="roleShow"
              :expand-str="'roleShow'"
              @changedClick="changedClick"
            ></audit-advanced-group> </td></tr
      ></table>

      <SdTable
        v-if="roleShow"
        ref="maintaintable"
        :row-key="(record, index) => index"
        :loading="false"
        class="maintaintable"
        :data-source="roleList"
        :columns="roleColumns"
        :pagination="false"
        :bordered="true"
      >
        <template slot="empowerType" slot-scope="text, record">
          <span v-if="text === '0'">期间</span>
          <span v-else-if="text === '1'">永久</span>
          <span v-else-if="text === '2'">近一年</span>
        </template>
        <template slot="startDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
        <template slot="endDate" slot-scope="text, record">
          <span>
            {{ text | dateFormater }}
          </span>
        </template>
      </SdTable>
    </audit-form-top-banner>
  </span>
</template>

<script>
import axios from '@/common/services/axios-instance'
import auditFormTopBanner from '../../components/audit-form-top-banner'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import SdTable from '@/common/components/sd-table.vue'

export default {
  name: 'AuditWarrantReadonly',
  metaInfo: {
    title: '模型授权',
  },
  components: {
    auditFormTopBanner,
    auditAdvancedGroup,
    SdTable,
  },
  filters: {
    dateFormater(val) {
      if (val === null) return ''
      const date = new Date(val)
      const Y = date.getFullYear() + '-'
      const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
      const D = date.getDate()
      return Y + M + D
    },
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      mainSendUnit: [],
      selectid: '',
      cateGoryShow: true,
      modelList: [],
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          key: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '模型名称',
          dataIndex: 'modelName',
          key: 'modelName',
          width: '30%',
        },
        {
          title: '模型编号',
          dataIndex: 'modelCode',
          key: 'modelCode',
          width: '30%',
        },
        {
          title: '模型描述',
          dataIndex: 'modelDesc',
          key: 'modelDesc',
          width: '30%',
        },
      ],
      companyShow: true,
      companyList: [],
      companyColumns: [
        {
          title: '公司名称',
          dataIndex: 'unitName',
        },
        {
          title: '公司编号',
          dataIndex: 'unitCode',
        },
      ],
      unitShow: true,
      unitList: [],
      unitColumns: [
        {
          title: '单位名称',
          dataIndex: 'unitName',
        },
        {
          title: '单位编号',
          dataIndex: 'unitCode',
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          scopedSlots: { customRender: 'empowerType' },
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          scopedSlots: { customRender: 'startDate' },
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          scopedSlots: { customRender: 'endDate' },
        },
      ],
      peoShow: true,
      peoList: [],
      peoColumns: [
        {
          title: '用户名',
          dataIndex: 'userName',
        },
        {
          title: '所属单位',
          dataIndex: 'userUnit',
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          scopedSlots: { customRender: 'empowerType' },
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          scopedSlots: { customRender: 'startDate' },
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          scopedSlots: { customRender: 'endDate' },
        },
      ],
      projectShow: true,
      projectList: [],
      projectColumns: [
        {
          title: '项目名称',
          dataIndex: 'projectName',
        },
        {
          title: '所属单位',
          dataIndex: 'projectUnit',
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          scopedSlots: { customRender: 'empowerType' },
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          scopedSlots: { customRender: 'startDate' },
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          scopedSlots: { customRender: 'endDate' },
        },
      ],
      roleShow: true,
      roleList: [],
      roleColumns: [
        {
          title: '角色名称',
          dataIndex: 'roleName',
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          scopedSlots: { customRender: 'empowerType' },
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          scopedSlots: { customRender: 'startDate' },
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          scopedSlots: { customRender: 'endDate' },
        },
      ],
    }
  },
  created() {
    if (this.$route.query.selectid) {
      this.selectid = this.$route.query.selectid
      this.getEmpowerInfo()
    }
  },
  methods: {
    // 获取授权详情
    getEmpowerInfo() {
      axios
        .post('api/xcoa-mobile/v1/iammodelmaintain/iamDataSqDetail?id=' + this.selectid)
        .then((res) => {
          this.modelList = res.data.iamModelMaintainEntitys
          this.companyList = res.data.iamAppointUnitEntities
          this.unitList = res.data.iamLicenseUnitEntitys
          this.peoList = res.data.iamLicensePeopleEntitys
          this.projectList = res.data.iamLicenseProjectEntitys
          this.roleList = res.data.iamLicenseRoleEntitys
        })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.btnselect {
  position: relative;
  top: 4px;
  right: 80px;
  float: right;
  padding: 4px 0;
  .batchselect {
    z-index: 100;
    margin-left: 10px;
  }
}

.tableTop {
  margin-top: 20px;
}
:global(.maintaintable) {
  :global(.ant-table-tbody > tr > td) {
    border-right: none;
    border-left: none;
  }
  :global(.ant-table-thead > tr > th) {
    border-right: none;
    border-left: none;
  }
  :global(table) {
    border: none !important;
  }
  :global(.ant-table-placeholder) {
    border: none !important;
  }
}
</style>
