review.js 6.8 KB
define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'swiper', 'layer'], function($, undefined, Frontend, Form, Template, Swiper, Layer) {
    var Controller = {
        midterm: function() {
            var vm = new Vue({
                el:"#app",
                data() {
                    return {
                        formSet:Config.formSets || [],
                        form:Config.form || [],
                        rules:Config.form.rules || [],
                        itemId:Config.itemId || '',
                        isCaptain:Config.isCaptain || '',
                    };

                },
                mounted(){
                    this.initData();
                },
                methods: {
                    test() {
                        console.log(this.form);
                    },
                    initData() {
                        var _this = this;
                        _this.$nextTick(function () {
                            $.each(_this.formSet.fields_setting,function(k,v){
                                if(v.type == 'file') {
                                    var uploadName = v.name;
                                    var uploadKey = v.file_key;
                                    $("#"+uploadName).data("upload-success", function (res) {
                                        $("#"+uploadName).parent().siblings('.file_box').show();
                                        _this.$set(_this.form[_this.formSet.stage_type],uploadName,res.file.url);
                                        _this.$set(_this.form[_this.formSet.stage_type],uploadKey,res.file.name);
                                    });
                                }
                            });
                            Form.api.bindevent($("#form"));
                        });
                    },
                    del_file(key,name,stage_type) {
                        var _this = this;
                        $("#"+key).parents(".file_box").hide();
                        _this.$set(_this.form[stage_type],name,'');
                        _this.$set(_this.form[stage_type],key,'');
                    },
                    submitForm(form) {
                        this.$refs[form].validate((valid) => {
                            if (valid) {
                                $.ajax({
                                    type:'post',
                                    url:'/index/review/midterm',
                                    data:{form:this.form,itemId:this.itemId},
                                    dataType:'json',
                                    success:function(res){
                                        if(res.code != 1) {
                                            layer.msg(res.msg, {icon: 5});
                                        }else{
                                            layer.msg(res.msg, {icon: 1});
                                            setTimeout(function () {
                                                window.location.href = res.url;
                                            },800);
                                        }

                                    },
                                    error:function(error){
                                        layer.msg('网络失败,请重试', {icon: 5});
                                    }
                                });
                            }
                        });
                    },
                }
            });
        },
        conclusion: function() {
            var vm = new Vue({
                el:"#app",
                data() {
                    return {
                        formSet:Config.formSets || [],
                        form:Config.form || [],
                        rules:Config.form.rules || [],
                        itemId:Config.itemId || '',
                        isCaptain:Config.isCaptain || '',
                    };

                },
                mounted(){
                    this.initData();
                },
                methods: {
                    test() {
                        console.log(this.form);
                    },
                    del_file(key,name,stage_type) {
                        var _this = this;
                        $("#"+key).parents(".file_box").hide();
                        _this.$set(_this.form[stage_type],name,'');
                        _this.$set(_this.form[stage_type],key,'');
                    },
                    initData() {
                        var _this = this;
                        _this.$nextTick(function () {
                            $.each(_this.formSet.fields_setting,function(k,v){
                                if(v.type == 'file') {
                                    var uploadName = v.name;
                                    var uploadKey = v.file_key;
                                    $("#"+uploadName).data("upload-success", function (res) {
                                        $("#"+uploadName).parent().siblings('.file_box').show();
                                        _this.$set(_this.form[_this.formSet.stage_type],uploadName,res.file.url);
                                        _this.$set(_this.form[_this.formSet.stage_type],uploadKey,res.file.name);
                                    });
                                }
                            });
                            Form.api.bindevent($("#form"));
                        });
                    },

                    submitForm(form) {
                        this.$refs[form].validate((valid) => {
                            if (valid) {
                                $.ajax({
                                    type:'post',
                                    url:'/index/review/conclusion',
                                    data:{form:this.form,itemId:this.itemId},
                                    dataType:'json',
                                    success:function(res){
                                        if(res.code != 1) {
                                            layer.msg(res.msg, {icon: 5});
                                        }else{
                                            layer.msg(res.msg, {icon: 1});
                                            setTimeout(function () {
                                                window.location.href = res.url;
                                            },800);
                                        }

                                    },
                                    error:function(error){
                                        layer.msg('网络失败,请重试', {icon: 5});
                                    }
                                });
                            }
                        });
                    },
                }
            });
        },
    }
    return Controller;
});