<template>
  <xc-select-v2 v-model="obj"
                value="tcode" label="tname"
                :data="data" :remote-method="testmethod"/>
  测试:
  <el-button @click="test1">清空</el-button>
  <el-button @click="generateData">生成数据</el-button>

  <xc-table :data="tableData" row-key="code" localPaging small>
    <el-table-column type="selection" reserve-selection/>
    <el-table-column label="编码" prop="code"></el-table-column>
    <el-table-column label="名称" prop="name"></el-table-column>
    <el-table-column label="其他" prop="qita"></el-table-column>
  </xc-table>

</template>

<script setup name='Test'>
import sleep from "@/utils/sleep";
import XcTable from "@/components/xc/xc-table/XcTable.vue";

let dataV2 = $ref([])

let tableData = $ref({
  data: [],
  currentPage: 1,
  pageSize: 30,
  total: 0
})


const vChange = (val) => {
  console.log(val)
}


const obj = $ref({
  tcode: '',
  tname: ''
})

let data = $ref([])

const generateData = () => {
  for (let i = 0; i < 1000; i++) {
    data.push({
      value: i.toString(),
      label: i === 4 ? 'asdghashjgdhjasgdhjasgdhjasgdhjasgdjhasdg' : 'test' + i
    })
  }

}

const testmethod = async (val) => {
  console.log('触发查询事件', val)
  let length = Math.ceil((Math.random() * 10) * 100)
  let index = Math.ceil((Math.random() * 10) * 10)
  data = []
  for (let i = 0; i < length; i++) {
    if (i === index) {
      data.push({
        value: val,
        label: i + 'label' + '数据'
      })
    }
    data.push({
      value: val + i,
      label: i + 'label'
    })
  }
  await sleep(2000)
  obj.tname = ''
  data = []
}

const test1 = async () => {
  data = []
  await sleep(1000)
  obj.tcode = 'ad' + Math.ceil((Math.random() * 10))
  console.log(obj.tcode)
}

let searchMethod = $ref('')
const te = (val) => {
  searchMethod = val
  console.log(val)
}

for (let i = 0; i < 1000; i++) {
  let children = []
  if (i % 3 === 0) {
    for (let j = 0; j < 10; j++) {
      children.push({
        code: 'code' + i,
        name: 'name' + i,
        qita: 'qita' + 12,
      });
    }
  }
  tableData.data.push({
    code: 'code' + i,
    name: 'name' + i,
    qita: 'qita' + 12,
    children: children
  })
}

console.log(tableData)

tableData.total = tableData.data.length


</script>

<style scoped>

</style>