<!--
 * @Author: your name
 * @Date: 
 * @LastEditTime: 2022-06-15 13:31:49
 * @LastEditors: xinranli 1251980725@qq.ccom
 * @Description: 
 * @FilePath: 
-->
<template>
  <a-card :bordered="false" class="card-area">
    <a-spin size="large" :spinning="loading">
      <k-form-build
        :value="jsonData"
        :defaultValue="defaultValue"
        ref="kfb"
        @logEvent="logEvent"/>
    </a-spin>
 </a-card>
</template>
<script>
import { getFormConfig } from '../../../packages/api/manage.js'
export default {
  data () {
    return {
      // 配置到数据库的pageId，根据业务需要进行修改
      pageId: 'TEST_05253',
      // 后台接口，根据业务需要进行修改
      serviceName: 'codeService',
      //弹窗标题
      title: '',
      loading: false,
      url: {
        // 以下方法，根据业务需要进行修改
        detail: 'getUnique',
        insert: 'save',
        edit: 'updateById'
      },
      pageType: 'form',
      selectedRowsList: [],
      defaultFilter: {},
      defaultValue: {},
      dynamicData: {},
      jsonData: {}
    }
  },
  created () {
    this.init()
  },
  methods: {
   // 该方法由父组件发起调用打开弹窗
    init () {
      this.visible = true
      // this.loading = true
      getFormConfig(this.pageId).then((response) => {
        // this.loading = false
        if (response.responseData.statusCode === 0) {
          let result = response.responseData.resultData
          this.jsonData = JSON.parse(result.configJson)
          let valueData = { 
                            baseTable:[
                              {id: 1, input1: 'AA', number1: 50, 'input2': 'BBBB'},
                            ]
          }
          this.$refs.kfb.setData(valueData)
        } else {
          this.$message.error('加载动态表单失败!')
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // kform batch value change event
    logEvent (value, key) {
      if (value.event === 'onSelectionChanged') {
      this.selectedRowsList = value.selectedRowsData
      }else if (value.event === 'onRowDblClick') {

      }
    }
  }
}
</script>
