<template>
  <div style="width: 100%;height: 100%;">
    <el-form ref="form" :model="formData" label-width="100px" :inline="true">
      <el-form-item v-for="i in defaultData.formData" :label="i.data.label">
        <el-input v-if="i.type==='input'" v-bind="i.data" v-model="formData[(i.data.model || '')]"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>


export default {
  props: ['defaultData','bind'],
  expose: ['getRequestData'],
  components: {},
  data() {
    return {
      formData: {}
    }
  },
  watch: {
    defaultData: {
      handler(a, b) {
        this.getOption()
      },
      deep: true
    },
  },
  mounted() {
    this.getRequestData()
    this.getOption()
  },
  methods: {
    getOption() {
    },
    onSubmit(){
      if(this.bind){
        console.log(this.$parent)
        console.log(this.bind)
        console.log(this.$parent.$refs['item'+this.bind]?.[0])
      }
    },
    async getRequestData() {
      this.requestData = {}
      for (const e of this.defaultData.requests) {
        let fn = new Function('_this', e.text)
        let data = await fn(this)
        e.data = data
        this.requestData = ({...this.requestData, ...data})
      }
    }
  },
}
</script>
<style>

</style>
