
(function (KDApi, $) {
    // 构造函数
    function MyComponent (model) {
      this._setModel(model)
    }
  
    MyComponent.prototype = {
      // 绑定model
      _setModel: function (model) {
        this.model = model
      },
      // 生命周期：初始化
      init: function (props) {
        console.log('-----init', this.model, props)
        // setHtml(this.model, props)
      },
      // 生命周期：更新
      update: function (props) {
        console.log('-----update', this.model, props)
        setHtml(this.model, props)
      },
      // 生命周期：销毁
      destoryed: function () {
        console.log('-----destoryed', this.model)
      }
    }
  
    // 加载文件和模板
    var setHtml = function (model, props) {
      var APIJson = props.data || {
          useDesc: '',
          requestType: '',
          requestUrl: '',
          inputData: {
          },
          propDesc:[

          ],
          remark: '',
          demo: '',
          result: '',
		  resultDesc: [
		  
		  ]
      }
      KDApi.loadFile('./css/index.css', model, function() {
        KDApi.getTemplateStringByFilePath('./html/index.html', model, {
            useDesc: APIJson.useDesc || '',
            requestType: APIJson.requestType || '',
            requestUrl: APIJson.requestUrl || '',
            inputData: JSON.stringify(APIJson.inputData, undefined, '  '),
            propDesc: APIJson.propDesc || [],
            remark: APIJson.remark || '对于基础资料类型参数，按id赋值效率会更高，按number会对不存在的编码给出校验提示',
            demo: APIJson.demo || '',
            result: APIJson.result || '',
			resultDesc: APIJson.resultDesc || []
        }).then(function(result){
            if (!result || !APIJson) {
                model.dom.innerHTML = ''
            } else {
               model.dom.innerHTML = result 
            }
        })
      })
    }
    console.log('-----------------init')
    // 注册自定义控件
    KDApi.register('apihtml', MyComponent)
  })(window.KDApi, jQuery)
  