<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="70%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                 <Field label="名称" :span="20" prop="name" v-model="form.name" placeholder="请输入名称"/>
                <Field label="公司介绍" :span="20" prop="introduction" v-model="form.introduction" rows="8" type="textarea" placeholder="请输入公司介绍"/>
                <Field label="电话号码" :span="20" prop="phone" v-model="form.phone" placeholder="请输入电话号码"/>
                <Field label="地址" :span="20" prop="address" v-model="form.address" type="textarea" placeholder="请输入地址"/>
                <Field label="二维码" :span="20"><imageUpload v-model="form.qrCode" prePath="/file/preview"/></Field>

            </el-row>

            <form-buttons @submit='submitForm' v-if="pageInfo.type!='view'" noCancelBtn />
        </el-form>

    </el-drawer>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    export default {
        name: "CompanyDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("company")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "公司基本信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="company/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改公司基本信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "company/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增公司基本信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="company/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "公司基本信息详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    name : null,
                    introduction : null,
                    phone : null,
                    address : null,
                    qrCode : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
