<template>
  <s-code-editor v-model="textJSON" lang="json"></s-code-editor>
  <s-group-table
    auto-scroll
    height="200px"
    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 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
  { zoom: 1, pitch: 2, jd: 1, wd: 2 },
])

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

function changePageNumber (page) {
  console.log(page,11)
  pageConfig.value.page = page
}

const columns = ref([
  {
    label: '倾斜度',
    key: 'pitch',
    type: 'input',
    props: { size: 'small', placeholder: '倾斜' }
  },
  {
    label: '中心',
    key: 'center',
    type: 'group',
    props: {
      mode: 'array',
      size: 'small',
      grid: {
        span: 4
      }
    },
    children: [
      {
        label: '经度',
        key: 'jd',
        type: 'select',
        props: {
          size: 'small',
          placeholder: '经度',
          grid: { span: 2 }
        },
        options: [
          {
            label: '1',
            value: 10
          },
          {
            label: '10',
            value: 10
          },
          {
            label: '100',
            value: 100
          }
        ],
        style: {
          marginRight: '10px'
        }
      },
      {
        label: '纬度',
        key: 'wd',
        type: 'input',
        props: {
          size: 'small',
          placeholder: '纬度',
          grid: { span: 2 }
        }
      }
    ]
  },
])

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