<template>
  <s-code-editor v-model="textJSON" lang="json"></s-code-editor>
  <s-group-table
    :index="true"
    v-model:data="tableData"
    :columns="columns"
    :pageConfig="pageConfig"
    @changePageNumber="changePageNumber"
  >
  </s-group-table>
  <s-group-table
    :index="true"
    :calculator="(val)=>`第${val+1}`"
    v-model:data="tableData"
    :columns="columns"
    :pageConfig="pageConfig"
    @changePageNumber="changePageNumber"
  >
  </s-group-table>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'

const textJSON = computed({
  get () {
    return JSON.stringify(tableData.value, null, '\t')
  },
  set (value) {
    tableData.value = JSON.parse(value)
  }
})

const tableData = ref([
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 }
])

const columns = ref([
  {
    label: 'zoom',
    key: 'zoom',
  },
  {
    label: '倾斜度',
    key: 'pitch',
  },
  {
    label: '中心',
    key: 'center',
    type: 'group',
    props: {
      mode: 'array',
      size: 'small',
      grid: {
        span: 4
      }
    },
    children: [
      {
        label: '经度',
        key: 'jd',
      },
      {
        label: '纬度',
        key: 'wd',
      }
    ]
  },
])

const pageConfig = ref({
  page: 1,
  total: 1000
})

function changePageNumber (page) {
  pageConfig.value.page = page
}


function changeValue (key: string, value: any) {
  console.log(key, value)
}
</script>
