<!--
 * @Author: WangJiaCheng
 * @Date: 2021-05-11 17:37:33
 * @LastEditors: WangJiaCheng
 * @LastEditTime: 2021-08-20 14:14:34
 * @Description: 表单配置
-->
<template>
  <div class="form-config">
    <el-form
      ref="form"
      :model="formData"
      label-width="100px"
    >
      <el-form-item label="表单模型" prop="formModel">
        <el-select v-model="formData.formModel" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.label"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="表单模型预览">
        123
      </el-form-item>
      <el-form-item label="查询接口" prop="searchApi">
        <el-input v-model="formData.searchApi" />
      </el-form-item>
      <el-form-item label="请求方式" prop="apiMethod">
        <el-input v-model="formData.searchApi" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="next">
          下一步
        </el-button>
        <el-button type="primary" @click="previewCode">
          预览代码
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'

export default {
  name: 'FormConfig',
  components: {
  },
  data() {
    return {
      formData: {},
      options: []
    }
  },
  mounted() {
    const formModel = localStorage.getItem('formModel')
    if (formModel) {
      this.options.push({
        value: JSON.parse(formModel),
        label: '表单模型1'
      })
    }
  },
  methods: {
    ...mapMutations('page', ['setFormConfig', 'setActiveTab']),
    next() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.setFormConfig(this.formData)
          this.setActiveTab('list')
        }
      })
    },
    previewCode() {
      this.$emit('preview', { ...this.formData, list: this.tableData }, 'form')
    }
  }
}
</script>

<style lang="less">

</style>
