<template>
  <el-dialog
   :close-on-click-modal="false"
    class="scrollbar-dialog"
    title="测试配置字段"
    :visible.sync="dialogVisible"
    v-if="dialogVisible"
    :append-to-body="true"
    @close="closeDialog">
    <el-scrollbar class="layer-content">
      <el-form ref="dialogForm" label-width="120px" v-loading="dialogLoading">
        <div class="formGroup">
          <el-row :gutter="20">
            <el-col :span="20" v-for="(item, index) in sqlData" :key="index">
              <el-form-item :label="item.paramName" required>
                <el-input v-model="item.paramValue"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
    </el-scrollbar>
    <span slot="footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { scriptValidate } from '@/api/esb_service'

export default {
  data() {
    return {
      dialogVisible: this.value,
      dialogLoading: false,
      dialogForm: {}
    }
  },
  props: {
    value: {
      type: Boolean,
      default: false
    },
    sqlData: {
      type: Array,
      default() {
        return []
      }
    },
    sqlFormData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  watch: {
    value(val) {
      this.dialogVisible = val
      if (val) {

      } else {
        this.dialogForm = {}
      }
    },
    dialogVisible(val) {
      this.$emit('input', val)
    }
  },
  methods: {
    closeDialog() {
      this.$refs.dialogForm.resetFields()
    },
    submit() {
      var that = this
      for (let index = 0; index < this.sqlData.length; index++) {
        const element = this.sqlData[index]
        if (element.paramValue == '') {
          that.$message.warning(`请输入${element.paramName}！`)
          return
        }
      }
      this.$emit('confirm', this.sqlData)
    }
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
  .scrollbar-dialog {
    .el-dialog__body {
      padding: 0;

      .el-scrollbar {
        height: auto;
      }
    }
  }
</style>
