<template>
    <div>
        <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small"
                 style="max-width: 500px;">
                                                                                        <el-form-item prop="药品编号" label="药品编号">
                <el-input v-model="formData.药品编号"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="药品名称" label="药品名称">
                <el-input v-model="formData.药品名称"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="计量单位" label="计量单位">
                <el-input v-model="formData.计量单位"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="规格" label="规格">
                <el-input v-model="formData.规格"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="主要成分" label="主要成分">
                <el-input v-model="formData.主要成分"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="有效成分" label="有效成分">
                <el-input v-model="formData.有效成分"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="单价" label="单价">
                <el-input v-model="formData.单价"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="生产厂家" label="生产厂家">
                <el-input v-model="formData.生产厂家"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="药品制定部门" label="药品制定部门">
                <el-input v-model="formData.药品制定部门"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="flagcolumn" label="FlagColumn">
                <el-input v-model="formData.flagcolumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                    <el-form-item>
                <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
                <el-button @click="$router.go(-1)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    import formValidator from '../formValidator'

    export default {
        created() {
            if (this.$route.query.id) {
                this.$http.get({
                    url: '/tableShouyiYaopinxinxi/getOne',
                    data: {
                        id: this.$route.query.id
                    }
                }).then(res => {
                    if (res.success) {
                        this.formData = res.data;
                    }
                })
            }
        },
        data() {
            return {
                saving: false,
                formData: {},
                rules: {
                                                                                                                                                                                                                                                                                                                                        },
        }
        },
        methods: {
            onSave() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.submit();
                    } else {
                        return false;
                    }
                });
            },
            submit() {
                var data = JSON.parse(JSON.stringify(this.formData));
                this.$http.post({
                    url: this.formData.id ? '/tableShouyiYaopinxinxi/update' : '/tableShouyiYaopinxinxi/save',
                    data: data
                }).then(res => {
                    if (res.success) {
                        this.$message.success('成功');
                        this.$router.go(-1);
                    } else {
                        this.$message.warning('失败')
                    }
                });
            }
        }
    }
</script>
<style lang="less" scoped>
</style>
