<template>
    <div class="edit-view">
        <el-form
            :model="formData"
            :rules="rules"
            ref="form"
            label-width="178px"
            label-position="right"
            size="small"
            style="max-width: 700px;"
        >
            <el-form-item prop="name" label="企业名称">
                <el-input v-model="formData.name"></el-input>
            </el-form-item>
            <el-form-item prop="uscc" label="注册号">
                <el-input v-model="formData.uscc"></el-input>
            </el-form-item>
            <el-form-item prop="businessScope" label="经营范围">
                <el-input type="textarea" v-model="formData.businessScope"></el-input>
            </el-form-item>
            <el-form-item prop="address" label="企业住所">
                <el-input v-model="formData.address"></el-input>
            </el-form-item>
            <el-form-item prop="businessPremise" label="生产经营场所">
                <el-input v-model="formData.businessPremise"></el-input>
            </el-form-item>
            <el-form-item prop="privacyPolicy" label="法人姓名">
                <el-input v-model="formData.privacyPolicy"></el-input>
            </el-form-item>
            <el-form-item prop="phone" label="短信号码">
                <el-input v-model="formData.phone"></el-input>
            </el-form-item>
            <el-form-item prop="contactPhone" label="企业联系方式">
                <el-input v-model="formData.contactPhone"></el-input>
            </el-form-item>
            <el-form-item prop="district" label="所属管区">
                <el-input v-model="formData.district"></el-input>
            </el-form-item>
            <el-form-item prop="registeredCapital" label="注册资本（万）">
                <el-input-number type="number" v-model="formData.registeredCapital"></el-input-number>
            </el-form-item>
            <el-form-item prop="category" label="单位性质">
                <el-input v-model="formData.category"></el-input>
            </el-form-item>
            <el-form-item prop="specialty" label="专业种类">
                <el-input v-model="formData.specialty"></el-input>
            </el-form-item>
            <el-form-item prop="trainingSite" label="培训点数量三楼及以下">
                <el-input-number type="number" v-model="formData.trainingSite"></el-input-number>
            </el-form-item>
            <el-form-item prop="trainingSiteFour" label="培训点数量四楼及以上">
                <el-input-number type="number" v-model="formData.trainingSiteFour"></el-input-number>
            </el-form-item>
            <el-form-item prop="area" label="总面积">
                <el-input v-model="formData.area"></el-input>
            </el-form-item>
            <el-form-item prop="classroomNum" label="教室数量">
                <el-input-number type="number" v-model="formData.classroomNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="teacherNum" label="教师总数">
                <el-input-number type="number" v-model="formData.teacherNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="fullTimeNum" label="专职数量">
                <el-input-number type="number" v-model="formData.fullTimeNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="partTimeNum" label="兼职数量">
                <el-input-number type="number" v-model="formData.partTimeNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="musicNum" label="音乐类">
                <el-input-number type="number" v-model="formData.musicNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="danceNum" label="舞蹈类">
                <el-input-number type="number" v-model="formData.danceNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="artNum" label="美术类">
                <el-input-number type="number" v-model="formData.artNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="theatreOperaNum" label="戏剧戏曲">
                <el-input-number type="number" v-model="formData.theatreOperaNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="folkMusicNum" label="曲艺类">
                <el-input-number type="number" v-model="formData.folkMusicNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="qualificationNum" label="有教师资格证">
                <el-input-number type="number" v-model="formData.qualificationNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="traineesPerYearNum" label="年培训人数">
                <el-input-number type="number" v-model="formData.traineesPerYearNum"></el-input-number>
            </el-form-item>
            <el-form-item prop="examPoint" label="是否是艺术水平考级考点">
                <!-- <el-input v-model="formData.examPoint"></el-input> -->
                <el-radio-group v-model="formData.examPoint">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item prop="gradingOrganization" label="艺术水平考级机构名称">
                <el-input v-model="formData.gradingOrganization"></el-input>
            </el-form-item>
            <el-form-item prop="remark" label="备注">
                <el-input v-model="formData.remark"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="onSave" :loading="saving" type="primary">保存</el-button>
                <el-button @click="onDelete" :loading="saving" type="danger" v-if="formData.id">删除 </el-button>
                <el-button @click="$router.go(-1)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
export default {
    name: 'TrainingInstitutionEdit',
    created() {
        if (this.$route.query.id) {
            this.$http
                .get('trainingInstitution/get/' + this.$route.query.id)
                .then(res => {
                    this.formData = res;
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        }
    },
    data() {
        return {
            saving: false,
            formData: {},
            rules: {}
        };
    },
    methods: {
        onSave() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        submit() {
            let data = { ...this.formData };

            this.saving = true;
            this.$http
                .post('/trainingInstitution/save', data, { body: 'json' })
                .then(res => {
                    this.saving = false;
                    this.$message.success('成功');
                    this.$router.go(-1);
                })
                .catch(e => {
                    console.log(e);
                    this.saving = false;
                    this.$message.error(e.error);
                });
        },
        onDelete() {
            this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' })
                .then(() => {
                    return this.$http.post(`/trainingInstitution/del/${this.formData.id}`);
                })
                .then(() => {
                    this.$message.success('删除成功');
                    this.$router.go(-1);
                })
                .catch(e => {
                    if (e !== 'cancel') {
                        console.log(e);
                        this.$message.error((e || {}).error || '删除失败');
                    }
                });
        }
    }
};
</script>
<style lang="less" scoped></style>
