<template>
  <div>
    <!-- 添加或修改角色配置对话框 -->
    <el-form ref="form"  :model="form" :rules="rules" label-width="100px" clearable :style="{width: '100%'}">
      <el-form-item v-for="(item,index) in formFiled"  :label="item.inputTitle"  :prop="item.inputName" >
        <el-input   v-model="form[item.inputName]" :placeholder="item.inputTitle"  />
      </el-form-item>
    </el-form>
    <div slot="footer"align="center" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>

    </div>

  </div>
</template>
<script>
    import {getFromList,addFromData} from "@/api/system/autoform";
    import {getForm} from "@/api/system/form";
    export default {
        name: "Role",
        components: {},
        props: [],
        data() {

            return {
                formData: {

                },
                form: {pass: ''},
                formToList: {},
                w:{},
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 总条数
                total: 0,
                // 角色表格数据
                formList: [],
                formFiled: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: true,
                // 是否显示弹出层（数据权限）
                openDataScope: false,
                // 日期范围
                dateRange: [],
                // 状态数据字典
                statusOptions: [],
                // 菜单列表
                menuOptions: [],
                // 部门列表
                deptOptions: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    status: undefined
                },
                // 表单参数
                form: {},
                defaultProps: {
                    children: "children",
                    label: "label"
                },
                // 表单校验
                rules: {},
                tableName: this.$route.query.tableName,
            };
        },
        created() {
            this.getList();
            this.getDicts("sys_normal_disable").then(response => {
                this.statusOptions = response.data;
            });

        },
        methods: {
            cancel (row) {
                this.$router.push(
                    {path: '/autoform/createform/',query:{ tableName: row.action, title: row.formTitle}}
                )
            },

            getList() {
                this.loading = true;
                var formdata=new FormData();
                formdata.append("tableName",this.tableName)
                formdata.append("pageNum",this.queryParams.pageNum)
                formdata.append("pageSize",this.queryParams.pageSize)
                getFromList(formdata).then(response => {
                    this.formFiled=JSON.parse(response.msg);
                    this.formList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },


            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = false;
                this.title = "添加"+this.tableName;
            },


            /** 提交按钮 */
            submitForm: function() {
                this.$refs["form"].validate(valid => {
                    addFromData(this.tableName,JSON.stringify(this.form)).then(response => {
                        if (response.code === 200) {

                            this.msgSuccess("添加成功");
                            // 数据列表地址
                            //this.$route.router.go()
                            alert("row")
                            //this.getList();
                            // this.$router.push({path:'/autoform/configIndex/',query:{ tableName: row.action, title: row.formTitle}})

                        }
                    });
                });
            },

        }
    };
</script>
<style>
</style>
