<template>
  <div :class="$style.wrapHeight">
    <div :class="$style.rowHeight">
      <div :class="$style.rightcard">
        <a-card>
          <!-- 高级搜索组件 -->
          <audit-advanced-query
            :expand="expand"
            :search-data="formData"
            :ref-name="searchform"
            :search-style="{ height: '150px', left: '20px', top: '57px' }"
            :search-fun="handleSearch"
            @searchedClick="searchedClick"
          >
            <template>
              <a-col :span="12">
                <a-form-model-item :label="'模型名称'" prop="tagCode">
                  <a-input v-model="formData.modelName" allow-clear />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item :label="'模型编号'" prop="modelName">
                  <a-input v-model="formData.modelCode" allow-clear />
                </a-form-model-item>
              </a-col>
            </template>
          </audit-advanced-query>

          <sd-data-table
            ref="SJMXDataTable"
            :filter-expressions="expressions"
            :columns="columns"
            :actions="actions"
            form-id="iamModelMaintainRankList"
            data-url="api/xcoa-mobile/v1/iammodelmaintain/iamModelMaintainRankList"
            :search-fields="['modelCode', 'modelName']"
            show-selection
            :show-advance-query="true"
            @searchbtnClick="searchbtnClick"
          >
            <div slot="islink" slot-scope="text, record">
              <!-- 本身是创建人，或者有共享查看权限 -->
              <a v-if="rowNameStatus(record)" :title="text" @click="rowClick(record)">{{ text }}</a>
              <span v-else :title="text">{{ text }}</span>
            </div>
          </sd-data-table>
        </a-card>
      </div>
    </div>
  </div>
</template>

<script>
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditAdvancedQuery from '../../components/audit-advanced-query.vue'
import auditAdvancedQueryMixins from '../../components/audit-advanced-query-mixins'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import components from './_import-components/audit-view-list-import'
import { getUserInfo } from '@/common/store-mixin'

export default {
  name: 'AuditMaintainQuoteList',
  metaInfo: {
    title: '模型引用排行',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins, auditAdvancedGroupMixins],
  data() {
    return {
      key: 0,
      treeData: [],
      searchform: 'searchform',
      formData: {
        modelName: '',
        modelCode: '',
      },
      formId: 'iamModelMaintain',
      columns: [
        {
          title: '排行',
          dataIndex: 'sortNumber',
          width: '70px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '模型名称',
          dataIndex: 'modelName',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '模型编号',
          dataIndex: 'modelCode',
        },
        // 标签描述
        {
          title: '引用次数',
          dataIndex: 'reservelong5',
        },
        // 创建人
        {
          title: '创建人',
          dataIndex: 'reservestring3',
        },
      ],
      expressions: [
        {
          dataType: 'str',
          name: 'catalogId',
          op: 'eq',
          stringValue: 0,
        },
      ],
      catalogId: null,
      catalogName: '',
      isroot: true,
    }
  },
  computed: {
    userInfoData() {
      return getUserInfo()
    },
  },
  methods: {
    rowNameStatus(record) {
      return record.reservelong1 === 1 || record.creatorId === this.userInfoData.id
    },
    refresh() {
      return this.$refs.SJMBKDataTable.refresh(true)
    },
    rowClick(record) {
      const url = '/audit-maintain-from?record=' + record.id + '&type=readonly' // 新页面要打开的路由地址
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
    },
    // 查询
    handleSearch() {
      this.expressions = []
      // 模型编号
      if (this.formData.modelCode) {
        this.expressions.push({
          dataType: 'str',
          name: 'modelCode',
          op: 'like',
          stringValue: `%${this.formData.modelCode}%`,
        })
      }
      // 模型名称
      if (this.formData.modelName) {
        this.expressions.push({
          dataType: 'str',
          name: 'modelName',
          op: 'like',
          stringValue: `%${this.formData.modelName}%`,
        })
      }
    },
  },
}
</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%;
    }
  }
}
.no-action {
  color: $text-color-secondary;
}
</style>
