<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="components/vue/vue-list :: head('quartz任务', 'commit')"></head>
<body>
<div id="app" style="padding-top: 10px">
    <el-row>
        <el-col :xs="{span: 24, offset: 0}" :sm="{span: 12, offset: 6}" :md="{span: 8, offset: 8}"
                :lg="{span: 8, offset: 8}" :xl="{span: 8, offset: 8}">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                <el-form-item th:label="#{quartzJob.jobName}" prop="jobName">
                    <el-input v-model="ruleForm.jobName" th:placeholder="#{pleaseInput} + #{quartzJob.jobName}"></el-input>
                </el-form-item>
                <el-form-item th:label="#{quartzJob.jobGroup}" prop="jobGroup">
                    <el-input v-model="ruleForm.jobGroup" th:placeholder="#{pleaseInput} + #{quartzJob.jobGroup}"></el-input>
                </el-form-item>
                <el-form-item th:label="#{quartzJob.cronExpression}" prop="cronExpression">
                    <el-input v-model="ruleForm.cronExpression" th:placeholder="#{pleaseInput} + #{quartzJob.cronExpression}"></el-input>
                </el-form-item>

                <el-form-item th:label="#{quartzJob.description}" prop="description">
                    <el-input v-model="ruleForm.description" th:placeholder="#{pleaseInput} + #{quartzJob.description}"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')"><span th:text="#{submit}"></span></el-button>
                    <el-button @click="closeWindow"><span th:text="#{close}"></span></el-button>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
</div>
</body>
<script th:src="@{/js/vue/common.js}"></script>
<script th:src="@{/js/vue/validateRule.js}"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    //Vue.http.options.emulateJSON = true;
    //Vue.http.options.emulateHTTP = true;
    var headerName = [[${_csrf.headerName}]];
    axios.defaults.headers.common[headerName] = [[${_csrf.token}]];

    //国际化
    international([[${session.locale}]]);

    var requestUrls = {
        url: "/api/quartzJobs/add"
    };

    var app = new Vue({
        el: '#app',
        data: {
            ruleForm: {
                cronExpression: "",
                description: "",
                jobName: "",
                jobGroup: ""
            },
            rules: {
                jobName: [
                    {required: true, message: [[#{quartzJob.jobName}]] + [[#{notEmpty}]], trigger: 'blur'}
                ],
                beanName: [
                    {required: true, message: [[#{quartzJob.beanName}]] + [[#{notEmpty}]], trigger: 'blur'}
                ],
                cronExpression: [
                    {required: true, message: [[#{quartzJob.cronExpression}]] + [[#{notEmpty}]], trigger: 'blur'}
                ],
                description: [
                    {required: true, message: [[#{quartzJob.description}]] + [[#{notEmpty}]], trigger: 'blur'}
                ]
            }
        },
        mounted: function () {

        },
        methods: {
            sendMessage(event) {
                console.log("sendMessage");
                closeLayer();
            },
            submitForm(formName) {
                parent.openLoading();
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$http.post(requestUrls.url, this.ruleForm).then((response) => {
                            parent.closeLoading();
                            parent.showSuccess([[#{insertSuccess}]]);
                            parent.updateListData();
                            closeLayer();
                        }).catch((error) => {
                            let errorMessage = [[#{insertFailed}]];
                            if (error.response) {
                                errorMessage = error.response.data.message;
                            }
                            parent.closeLoading();
                            this.$message.error(errorMessage);
                        });
                    } else {
                        parent.closeLoading();
                        setTimeout(()=>{
                            let isError= document.getElementsByClassName("is-error");
                            isError[0].querySelector('input').focus();
                        },100);
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            closeWindow(event) {
                closeLayer();
            },
            handleAvatarSuccess(res, file) {
                //this.ruleForm.headPhoto = URL.createObjectURL(file.raw);
                console.log(eval(res));
                res = eval(res);
                this.ruleForm.headPhoto = res.data[0];
            },
            beforeAvatarUpload(file) {
                console.log(file.type);
                const isJPG = file.type === 'image/jpeg';
                const isPNG = file.type === 'image/png';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG && !isPNG) {
                    this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            }
        }
    });
    /*]]>*/
</script>
</html>