<template>
  <div :class="$style.wrapHeight">
    <a-card>
      <!-- 高级搜索组件 -->
      <audit-advanced-query
        :expand="expand"
        :search-data="formData"
        :ref-name="searchform"
        :search-style="{ height: '170px', left: '20px', top: '57px' }"
        :search-fun="handleSearch"
        @searchedClick="searchedClick"
        @resetForm="resetForm"
      >
        <template>
          <a-col :span="12">
            <a-form-model-item label="版本年度" prop="year">
              <sd-select v-model="formData.year" :options="yearArry" allow-clear />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="版本编号" prop="versionCode">
              <a-input v-model="formData.versionCode" allow-clear />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属单位" prop="belongUnitName">
              <a-input v-model="formData.belongUnitName" allow-clear />
            </a-form-model-item>
          </a-col>
        </template>
      </audit-advanced-query>
      <sd-data-table-ex
        v-show="flag"
        :key="key"
        ref="riskVersionTable"
        :editnode="editnode"
        form-id="riskLibraryVersion"
        page-id="risk/version/riskLibraryVersion"
        :columns="columns"
        :actions="actions"
        show-selection
        :show-advance-query="true"
        :filter-expressions="expressions"
        :search-fields="['year']"
        @searchbtnClick="searchbtnClick"
      >
        <template slot="islink" slot-scope="text, record">
          <a @click="openversion(record)">{{ text }}</a>
        </template>
        <template slot="action" slot-scope="text, record">
          <a-button type="link" @click="open(record)"
            ><sd-icon type="sd-eye" :style="{ fontSize: '25px' }"
          /></a-button>
        </template>
      </sd-data-table-ex>
    </a-card>
    <sd-detail-modal
      ref="versionform"
      :readOnly="true"
      :record-id="recordId"
      page-id="risk/version/riskLibraryVersion"
      :modal-props="{ width: 1200 }"
    >
      <template v-slot="{ model, fields }">
        <table style="width:80%">
          <colgroup>
            <col style="width: 20%;" />
            <col style="width: 30%;" />
            <col style="width: 20%;" />
            <col style="width: 30%;" />
          </colgroup>
          <tr
            ><sd-form-item-td name="belongUnitName"></sd-form-item-td
            ><sd-form-item-td name="year"></sd-form-item-td
          ></tr>
          <tr v-show="false"
            ><sd-form-item-td name="belongUnitCode"></sd-form-item-td>
            <sd-form-item-td name="belongUnitId"></sd-form-item-td>
          </tr>

          <tr
            ><sd-form-item-td name="auditOrgId" :hidden="true"></sd-form-item-td>
            <sd-form-item-td name="modifyDeptId" :hidden="true"></sd-form-item-td>
          </tr>
          <tr
            ><sd-form-item-td name="modifyDeptCode" :hidden="true"></sd-form-item-td>
            <sd-form-item-td name="modifyDeptName" :hidden="true"></sd-form-item-td>
          </tr>

          <tr
            ><sd-form-item-td name="versionCode"></sd-form-item-td
            ><sd-form-item-td name="versuibType"></sd-form-item-td
          ></tr>
          <tr><sd-form-item-td colspan="3" name="riskLibraryType"></sd-form-item-td></tr>
          <tr><sd-form-item-td colspan="3" name="riskLibraryDesc"></sd-form-item-td></tr>
          <tr
            ><sd-form-item-td name="creatorName"></sd-form-item-td
            ><sd-form-item-td name="creationTime"></sd-form-item-td></tr
        ></table>
      </template>
    </sd-detail-modal>
  </div>
</template>

<script>
import { Modal, message } from 'ant-design-vue'
import systemManage from '@/system-manage/system-manage'
import errorUtil from '@/common/services/error-util'
import download from '@/common/services/download'
import TableActionTypes from '@/common/services/table-action-types'
import TableColumnTypes from '@/common/services/table-column-types'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import openAsTrustId from '@/common/services/open-as-trust-id'
import pickValues from '@/common/services/pick-values'
import sdIconPicker from '@/common/components/sd-icon-picker.vue'
import auditAdvancedQuery from '../../../components/audit-advanced-query.vue'
import auditAdvancedQueryMixins from '../../../components/audit-advanced-query-mixins'
import RiskVersionService from './risk-version-service'
import components from './_import-components/risk-version-list-import'
export default {
  name: 'RiskVersionList',
  metaInfo: {
    title: '风险矩阵',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins],
  data() {
    return {
      yearArry: [],
      waterMark: systemManage.getFormWaterMark(),
      flag: true,
      recordId: '',
      editnode: true, // 列表是否可以新建
      key: 0,
      treeData: [],
      searchform: 'searchform',
      formData: {
        year: '',
        versionCode: '',
        belongUnitName: '',
      },
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '所属单位',
          dataIndex: 'belongUnitName',
        },
        {
          title: '版本年度',
          dataIndex: 'year',
          width: '120px',
        },

        {
          title: '版本编号',
          dataIndex: 'versionCode',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '版本类型',
          dataIndex: 'versionType',
          width: '120px',
        },
        {
          title: '维护人员',
          dataIndex: 'creatorName',
          width: '100px',
        },
        {
          title: '维护日期',
          dataIndex: 'creationTime',
          sdRender: TableColumnTypes.date,
          sorter: true,
          defaultSortOrder: 'desc',
          width: '120px',
        },
        { dataIndex: 'auditOrgId', sdHidden: true },
        { dataIndex: 'belongUnitId', sdHidden: true },
        {
          title: '操作',
          dataIndex: '',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          width: '100px',
        },
      ],
      actions: [],
      expressions: [],
      catalogId: null,
      catalogName: '',
      auditMattersPath: '',
      visible: false,
    }
  },
  mounted() {
    // 初始化年份下拉框
    this.initYearSelect()
  },
  methods: {
    // 初始化年份下拉框
    initYearSelect() {
      const nowYear = new Date().getFullYear()
      const yearArry = []
      yearArry.push(nowYear)
      for (let i = 1; i < 6; i++) {
        yearArry.push(nowYear - i)
      }
      for (let i = 1; i < 11; i++) {
        yearArry.push(nowYear + i)
      }
      yearArry.sort()
      yearArry.forEach((year) => {
        this.yearArry.push({
          name: year,
          id: year,
        })
      })
    },
    Saved() {
      message.success('保存成功')
      this.$refs.versionform.hide()
    },
    Closed() {
      this.$refs.versionform.hide()
      // this.$refs.versionform.resetFields()
    },
    open(record) {
      this.recordId = record.id
      // this.visible = true
      this.$refs.versionform.show()
    },
    openversion(record) {
      let url = ''
      url =
        '/risk-event-list?version=' +
        record.id +
        '&orgId=' +
        record.belongUnitId +
        '&orgName=' +
        record.belongUnitName +
        '&history=1' // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
      const res = crossWindowWatcher.waitForChanged(url)
    },
    handleSearch() {
      this.expressions = []
      // 审计事项名称
      if (this.formData.year) {
        this.expressions.push({
          dataType: 'str',
          name: 'year',
          op: 'eq',
          stringValue: this.formData.year[0].name,
        })
      }
      // 审计事项编号
      if (this.formData.versionCode) {
        this.expressions.push({
          dataType: 'str',
          name: 'versionCode',
          op: 'like',
          stringValue: '%' + this.formData.versionCode + '%',
        })
      }

      if (this.formData.belongUnitName) {
        this.expressions.push({
          dataType: 'str',
          name: 'belongUnitName',
          op: 'like',
          stringValue: '%' + this.formData.belongUnitName + '%',
        })
      }

      this.expressions = [...this.expressions]
    },

    // 重置
    resetForm() {
      this.formData.year = null
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.wrap-height {
  height: 100%;
  .row-height {
    display: flex;
    flex: auto;
    height: 100%;
    .rightcard {
      flex: 1;
      width: calc(100% - 20%);
      height: 100%;
    }
  }
}
</style>
