<!--
 * @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_052581',
      // 后台接口，根据业务需要进行修改
      serviceName: 'codeService',
      //弹窗标题
      title: '',
      loading: false,
      url: {
        // 以下方法，根据业务需要进行修改
        detail: 'getUnique',
        insert: 'save',
        edit: 'updateById'
      },
      pageType: 'form',
      selectedRowslist: [],
      defaultFilter: {},
      defaultValue: {},
      dynamicData: {},
      jsonData: {}
    }
  },
  created () {
    this.init()
  },
  methods: {
   // 该方法由父组件发起调用打开弹窗
    init (search) {
      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)
           this.$refs.kfb.reset()
          let valueData = { baseTable:[
                              {id: 1, ctnNo: 'AA', ctnSize: '50'},
                              {id: 2, ctnNo: 'BB', ctnSize: '10'}
                            ],
                            datagrideTest: [
                              {
                                id: 1,
                                slider1: 4,
                                select1:1,
                                slider2: 89,
                                img1: 'https://img.alicdn.com/tps/TB16TQvOXXXXXbiaFXXXXXXXXXX-120-120.svg',
                                img2: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                link1: 'http://www.runoob.com',
                                linkText1: '百度',
                                link2: 'http://www.baidu.com',
                                tags1: ['tag1','tag2', 'tag3', 'tagaa', 'aa'],
                                tags2: ['标签1','标签2', 'a','b', 'c'],
                                tags3: ['a','b', 'c'],
                                childTestData: [
                                  {
                                    id: 1,
                                    slider1: 4,
                                    select1:1,
                                    slider2: 89,
                                    img1: 'https://img.alicdn.com/tps/TB16TQvOXXXXXbiaFXXXXXXXXXX-120-120.svg',
                                    img2: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                    link1: 'http://www.runoob.com',
                                    linkText1: '百度',
                                    link2: 'http://www.baidu.com',
                                    tags1: ['label1','tag2','a','b', 'c'],
                                    tags2: ['标签1','标签2','a','b', 'c'],
                                    tags3: ['a','b', 'c']
                                  },
                                  {
                                    id: 2,
                                    slider1: 14,
                                    select1:2,
                                    slider2: 9,
                                    img1: 'https://img.alicdn.com/imgextra/i2/O1CN012P76ko1dqUbwwmuF8_!!6000000003787-55-tps-56-56.svg',
                                    link1: 'http://www.runoob.com',
                                    linkText1: 'baidu',
                                    link2: 'http://www.baidu.com',
                                    tags1: ['tag1','tag2','a','b', 'c'],
                                    tags2: ['标签1','标签2','a','b', 'c'],
                                    tags3: ['a','b', 'c'],
                                  }
                                ]
                              },
                              {
                                id: 2,
                                slider1: 14,
                                select1:2,
                                slider2: 9,
                                img1: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                img2: 'https://img.alicdn.com/imgextra/i4/O1CN018rBRGK24fx7hzkITN_!!6000000007419-55-tps-56-56.svg',
                                link1: 'http://www.runoob.com',
                                linkText1: 'baidu',
                                link2: 'http://www.baidu.com',
                                tags1: ['tag1','tag2','a','b', 'c'],
                                tags2: ['标签1','标签2','a','b', 'c'],
                                tags3: ['a','b', 'c'],
                                childTestData: [
                                  {
                                    id: 1,
                                    slider1: 4,
                                    select1:1,
                                    slider2: 89,
                                    img1: 'https://img.alicdn.com/tps/TB16TQvOXXXXXbiaFXXXXXXXXXX-120-120.svg',
                                    img2: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                    link1: 'http://www.runoob.com',
                                    linkText1: '百度',
                                    link2: 'http://www.baidu.com',
                                    tags1: ['label1','label2','a','b', 'c'],
                                    tags2: ['标签1','标签2','a','b', 'c'],
                                    tags3: ['a','b', 'c'],
                                  },
                                  {
                                    id: 2,
                                    slider1: 14,
                                    select1:2,
                                    slider2: 9,
                                    img1: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                    link1: 'http://www.runoob.com',
                                    linkText1: 'baidu',
                                    link2: 'http://www.baidu.com',
                                    tags1: ['tag1','tag2','a','b', 'c'],
                                    tags2: ['标签1','标签2','a','b', 'c'],
                                    tags3: ['a','b', 'c'],
                                  }
                                ]
                              },
                              {
                                id: 3,
                                slider1: 64,
                                select1:26,
                                slider2: 49,
                                img1: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                img2: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                link1: 'http://www.runoob.com',
                                linkText1: 'Runoob',
                                link2: 'http://www.baidu.com',
                                tags1: ['tag1','tag2','a','b', 'c'],
                                tags2: ['标签1','标签2','a','b', 'c'],
                                tags3: ['a','b', 'c'],
                                childTestData: [
                                  {
                                    id: 1,
                                    slider1: 4,
                                    select1:1,
                                    slider2: 89,
                                    img1: 'https://img.alicdn.com/tps/TB16TQvOXXXXXbiaFXXXXXXXXXX-120-120.svg',
                                    img2: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                    link1: 'http://www.runoob.com',
                                    linkText1: '百度',
                                    link2: 'http://www.baidu.com',
                                    tags1: ['tag1','tag2','a','b', 'c'],
                                    tags2: ['标签1','标签2','a','b', 'c'],
                                    tags3: ['a','b', 'c'],
                                  },
                                  {
                                    id: 2,
                                    slider1: 14,
                                    select1:2,
                                    slider2: 9,
                                    img1: 'https://img.alicdn.com/imgextra/i3/O1CN01pLbt7T1Mh0woqKEN1_!!6000000001465-55-tps-56-56.svg',
                                    link1: 'http://www.runoob.com',
                                    linkText1: 'baidu',
                                    link2: 'http://www.baidu.com',
                                    tags1: ['tag1','tag2','a','b', 'c'],
                                    tags2: ['标签1','标签2','a','b', 'c'],
                                    tags3: ['a','b', 'c'],
                                  }
                                ]
                              }
                            ]
                          }
          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') {

      }
      // console.log(value + key)
    }
  }
}
</script>
