<template>
  <s-code-editor v-model="textJSON" lang="json"></s-code-editor>
  <s-group-table
    ref="table"
    :select="true"
    :index="true"
    v-model:data="tableData"
    :columns="columns"
    :option="option"
  >
  </s-group-table>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { cloneDeep } from 'lodash-es'

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: 2, pitch: 2, jd: 1, wd: 2 }
])

const table = ref()

const option = ref({
  width: '140px',
  name:'自定义操作列名称',
  btns: [
    {
      name: '详情'
    },
    {
      show: (row) => row.zoom === 1,
      name: '上架'
    },
    {
      show: (row) => row.zoom === 2,
      name: '下架'
    }
  ]
})

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

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