<template>
  <x-tree-view ref="xTreeView" @itemChecked="itemChecked">
    <x-add-native-form ref="nativeForm" />
  </x-tree-view>
</template>

<script>

import XTreeView from '@vue2-client/base-client/components/layout/XTreeView'
import { mapState } from 'vuex'
import XAddNativeForm from '@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'
import { getConfigByName } from '@vue2-client/services/api/common'

export default {
  components: {
    XAddNativeForm,
    XTreeView,
  },
  data () {
    return {
      currentItem: undefined,
    }
  },
  computed: {
    ...mapState('account', { currUser: 'user' }),
    ...mapState('setting', ['isMobile'])
  },
  mounted () {
    this.initView()
  },
  methods: {
    // 初始化组件
    initView () {
      this.$refs.xTreeView.init({
        configName: 'templateTreeConfig',
        serviceName: 'af-his',
        env: 'dev',
      })
    },
    itemChecked (node) {
      this.currentItem = node
      if (node.type === 'all' || node.type === 'folder') {
        this.$refs.nativeForm.close()
        return
      }
      getConfigByName('编辑模板数据Form', 'af-his', (res) => {
        this.$refs.nativeForm.init({
          serviceName: 'af-his',
          formItems: res.formJson,
          showSubmitBtn: false,
          title: '收费',
          businessType: '新增',
          getDataParams: {
            content: {
              pms_patient_id: 1,
              template_id: node.id
            }
          }
        })
      })
    }
  }
}
</script>

<style>
</style>
