<template>
  <sd-tree-picker
    ref="tree"
    :load-tree-data="loadTreeData"
    single
    option-value="id"
    option-label="text"
    @change="confirm"
  />
</template>

<script>
import SysparamsService from './sysparams-service'
import components from './_import-components/sd-sysparams-select-import'

export default {
  name: 'SdSysparamsSelect',
  components,
  data() {
    return {}
  },
  created() {},
  methods: {
    loadTreeData(parentId, parent) {
      if (!parentId) {
        return Promise.resolve([
          {
            id: 'CXXX',
            text: '参数管理',
            isLeaf: false,
          },
        ])
      }
      const params = {
        listValue: false,
        isOpenAuth: true,
        groupId: -1,
        keyId: parentId,
      }
      const params2 = {
        columns: 'id,name,index',
        maxResults: -1,
        startPosition: 0,
        orderBy: 'index asc',
        expressions: [
          {
            dataType: 'str',
            name: 'keyId',
            op: 'eq',
            stringValue: parentId,
          },
        ],
      }
      return Promise.all([
        SysparamsService.getSystemChildNode(params),
        SysparamsService.getValues(params2),
      ]).then((res) => {
        res[0].forEach((item) => {
          item.isLeaf = item.leaf
        })
        return res[0]
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
