<template>
  <div class="app-container">
    <el-row :gutter="16">
      <el-col :span="5">
        <el-card shadow="never">
          <el-input
            v-model="filterText"
            style="width: 100%"
            placeholder="搜索系统名称"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
          <el-tree
            style="margin-top: 10px"
            ref="treeRef"
            node-key="id"
            :default-expand-all="true"
            :highlight-current="true"
            :expand-on-click-node="false"
            :data="treeData"
            :props="defaultProps"
            :filter-node-method="filterNode"
            :current-node-key="currentNode.id"
            @node-click="handleNodeClick"
          >
            <template #default="{ node, data }">
              <el-space :size="2">
                <el-icon v-if="!data.isLeaf"><Folder /></el-icon>
                <el-icon v-else><Document /></el-icon>
                <span>{{ node.label }}</span>
              </el-space>
            </template>
          </el-tree>
        </el-card>
      </el-col>
      <el-col :span="19">
        <el-form
          :model="queryParams"
          ref="queryRef"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="名称">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入名称"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item label="类型">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入类型"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item label="标签">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入标签"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="Plus"
              @click="handleAdd"
              v-hasPermi="['dataAsset:assetDetail:add']"
              >新增</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="Edit"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['dataAsset:assetDetail:edit']"
              >修改</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="Delete"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['dataAsset:assetDetail:remove']"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="Download"
              @click="handleExport"
              v-hasPermi="['dataAsset:assetDetail:export']"
              >导出</el-button
            >
          </el-col>
          <right-toolbar
            v-model:showSearch="showSearch"
            @queryTable="getList"
            :columns="columns"
          ></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="list"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="编号"
            align="center"
            key=""
            prop=""
            v-if="columns[0].visible"
          />
          <el-table-column
            label="来源系统"
            align="center"
            key=""
            prop=""
            v-if="columns[1].visible"
          />
          <el-table-column
            label="英文名称"
            align="center"
            key=""
            prop=""
            v-if="columns[2].visible"
          />
          <el-table-column
            label="中文名称"
            align="center"
            key=""
            prop=""
            v-if="columns[3].visible"
          />
          <el-table-column
            label="类型"
            align="center"
            key=""
            prop=""
            v-if="columns[4].visible"
          />
          <el-table-column
            label="描述"
            align="center"
            key=""
            prop=""
            v-if="columns[5].visible"
          />
          <el-table-column
            label="标签"
            align="center"
            key=""
            prop=""
            v-if="columns[6].visible"
          />
          <el-table-column
            label="负责人"
            align="center"
            key=""
            prop=""
            v-if="columns[7].visible"
          />
          <el-table-column
            label="建立时间"
            align="center"
            key=""
            prop=""
            v-if="columns[8].visible"
          />
          <el-table-column
            label="更新时间"
            align="center"
            key=""
            prop=""
            v-if="columns[9].visible"
          />
          <el-table-column
            label="操作"
            align="center"
            width="100"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-tooltip content="修改" placement="top">
                <el-button
                  link
                  type="primary"
                  icon="Edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['dataAsset:assetDetail:edit']"
                ></el-button>
              </el-tooltip>
              <el-tooltip content="删除" placement="top">
                <el-button
                  link
                  type="primary"
                  icon="Delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['dataAsset:assetDetail:remove']"
                ></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="AssetDetail">
const { proxy } = getCurrentInstance()
const defaultProps = {
  children: 'children',
  label: 'name',
}
const currentNode = ref({})
const treeData = ref([
  {
    catalogId: '-1',
    name: '系统',
    isLeaf: 0,
    children: [
      {
        parentId: '-1',
        id: '1',
        name: 'wind',
        isLeaf: 1,
      },
      {
        parentId: '-1',
        id: '2',
        name: 'O32',
        isLeaf: 1,
      },
    ],
  },
])

const handleNodeClick = (data) => {
  currentNode.value = data
}

const filterText = ref(undefined)
const treeRef = ref(null)
watch(filterText, (val) => {
  treeRef.value.filter(val)
})

const filterNode = (value, data) => {
  if (!value) {
    return true
  }
  return data.catalogName.includes(value)
}

const columns = ref([
  { key: 0, label: `编号`, visible: true },
  { key: 1, label: `来源系统`, visible: true },
  { key: 2, label: `英文名称`, visible: true },
  { key: 3, label: `中文名称`, visible: true },
  { key: 4, label: `类型`, visible: true },
  { key: 5, label: `描述`, visible: true },
  { key: 6, label: `标签`, visible: true },
  { key: 7, label: `负责人`, visible: true },
  { key: 8, label: `建立时间`, visible: true },
  { key: 9, label: `更新时间`, visible: true },
])
const loading = ref(false)
const list = ref([])
const total = ref(0)
const showSearch = ref(true)
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  name: undefined,
})
const getList = () => {}
const handleQuery = () => {
  queryParams.value.pageNum = 1
  getList()
}
const resetQuery = () => {
  proxy.resetForm('queryRef')
  handleQuery()
}

const handleAdd = () => {}
const handleUpdate = (row) => {}
const handleDelete = (row) => {}
const handleExport = () => {}

const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const handleSelectionChange = (selection) => {
  ids.value = selection.map((item) => item.userId)
  single.value = selection.length != 1
  multiple.value = !selection.length
}
</script>
