puzhibing
2024-02-05 640ff18d2d7f4be02ddb7f8f75e899f05545eb98
cloud-server-management/src/main/webapp/static/modular/system/introduce/introduce.js
@@ -13,18 +13,19 @@
 */
TCompetition.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '所在省市', field: 'provinceAndCity', visible: true, align: 'center', valign: 'middle',width:'8%',},
        {title: '开始时间', field: 'startTime', visible: true, align: 'center', valign: 'middle',width:'8%',},
        {title: '结束时间', field: 'endTime', visible: true, align: 'center', valign: 'middle',width:'5%',},
        {title: '赠送课时数', field: 'giveClass', visible: true, align: 'center', valign: 'middle',width:'8%',},
        {title:  '参与次数', field: 'number', visible: true, align: 'center', valign: 'middle',width:'8%',},
        {title: '状态', field: 'state', visible: true, align: 'center', valign: 'middle',width:'8%',
        {field: 'selectItem', checkbox: true},
        {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '所在省市', field: 'provinceAndCity', visible: true, align: 'center', valign: 'middle',},
        {title: '开始时间', field: 'startTime', visible: true, align: 'center', valign: 'middle',},
        {title: '结束时间', field: 'endTime', visible: true, align: 'center', valign: 'middle',},
        {title: '赠送课时数', field: 'giveClass', visible: true, align: 'center', valign: 'middle',},
        {title:  '参与次数', field: 'number', visible: true, align: 'center', valign: 'middle',},
        {title: '状态', field: 'activityState', visible: true, align: 'center', valign: 'middle',
            formatter:function (data) {
                return {1:"已开始",2:"已结束",3:"未开始"}[data]
                return {1:"已开始",2:"未开始",3:"已结束"}[data]
            }
        },
        {title: '活动状态', field: 'activityState', visible: true, align: 'center', valign: 'middle',width:'8%',
        {title: '活动状态', field: 'state', visible: true, align: 'center', valign: 'middle',
            formatter:function (data) {
                return {1:"已上架",2:"已下架"}[data]
            }
@@ -78,6 +79,137 @@
    }
};
TCompetition.addSubmit = function(){
    var data = {
        id:null,
        province:"",
        provinceCode:"",
        city:"",
        cityCode:"",
        startTime:"",
        endTime:"",
        giveClass:"",
        state:1
    };
    data.province                = $('#pCode option:selected').text();
    data.provinceCode            = $("#pCode").val()
    data.city                    = $('#cCode option:selected').text();
    data.cityCode                = $("#cCode").val()
    data.startTime                   = $("#startTime").val()
    data.endTime             = $("#endTime").val()
    data.giveClass                = $("#giveClass").val()
    if($("#pCode").val()==''){
        Feng.info("请选择省")
        return;
    }
    if($("#cCode").val()==''){
        Feng.info("请选择市")
        return;
    }
    if($("#startTime").val()=='' ){
        Feng.info("请选择开始时间")
        return;
    }
    if($("#endTime").val()=='' ){
        Feng.info("请选择结束时间")
        return;
    }
    if($("#giveClass").val()=='' ){
        Feng.info("请输入赠送课时数")
        return;
    }
    var date = new Date(data.endTime);
    var date1 = new Date(data.startTime);
    if (date<date1){
        Feng.error("开始时间必须小于等于结束时间!")
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/introduce/addIntroduce" ,
        type: "POST",
        data: JSON.stringify(data),
        contentType: "application/json",
        success: function (response) {
            if (response=="5001"){
                Feng.error("当前手机号 已被注册")
            }else{
                window.parent.TCompetition.table.refresh();
                TQuestion.close();
                Feng.success("添加成功");
            }
        },
        error: function (xhr, status, error) {
            Feng.error("添加失败!" + error);
        }
    });
};
TCompetition.onShelf = function () {
    if (this.check()){
        var selected = $('#' + this.id).bootstrapTable('getSelections');
        const data1 = {
            ids:[],
            state:null
        };
        selected.forEach(function(obj) {
            var id = obj.id;
            data1.ids.push(id);
        });
        data1.state = 1;
        $.ajax({
            url: Feng.ctxPath + "/introduce/changeState",
            type: "POST",
            contentType: "application/json", // 设置请求头的 Content-Type
            data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
            success: function(response) {
                Feng.success("上架成功!");
                TCompetition.search();
            },
            error: function(xhr, status, error) {
                var errorMessage = xhr.responseText ? xhr.responseText : "上架失败!";
            }
        });
    }
};
/**
 * 下架
 */
TCompetition.offShelf = function () {
    if (this.check()){
        var selected = $('#' + this.id).bootstrapTable('getSelections');
        const data1 = {
            ids:[],
            state:null
        };
        selected.forEach(function(obj) {
            var id = obj.id;
            data1.ids.push(id);
        });
        data1.state = 2;
        $.ajax({
            url: Feng.ctxPath + "/introduce/changeState",
            type: "POST",
            contentType: "application/json", // 设置请求头的 Content-Type
            data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
            success: function(response) {
                Feng.success("下架成功!");
                TCompetition.search();
            },
            error: function(xhr, status, error) {
                var errorMessage = xhr.responseText ? xhr.responseText : "下架失败!";
            }
        });
    }
};
/**
 * 关闭此对话框
 */
TCompetition.close = function() {
    parent.layer.close(window.parent.TCompetition.layerIndex);
}
/**
 * 点击添加车辆管理
 */
@@ -88,113 +220,52 @@
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tCompetition/tCompetition_add'
        content: Feng.ctxPath + '/introduce/add'
    });
    this.layerIndex = index;
};
/**
 * 打开查看车辆管理详情
 */
TCompetition.openTCompetitionDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title:'编辑',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tCompetition/tCompetition_update/' + TCompetition.seItem.id
        });
        this.layerIndex = index;
    }
};
TCompetition.info = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title:'详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tCompetition/tCompetition_info/' + TCompetition.seItem.id
        });
        this.layerIndex = index;
    }
};
TCompetition.user = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title:'详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tCompetition/tCompetition_user/' + TCompetition.seItem.id
        });
        this.layerIndex = index;
    }
};
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length >1 ){
        Feng.info("只能选择一条进行查看!");
    }else {
        if (this.check()) {
/**
 * 删除车辆管理
 */
TCompetition.delete = function () {
    if (this.check()) {
        var nickname = TCompetition.seItem.carLicensePlate;
        if (nickname == "" || nickname == null || nickname == undefined){
                nickname = "该车辆";
        }else{
            nickname = "【"+nickname+"】";
        }
        swal({
           title: language==1?"您是否确认删除" + nickname + "?":(language==2?"Are you sure to delete the" + nickname + "?":"Apakah Anda pasti akan menghapus" + nickname + "?"),
            text: language==1?"请谨慎操作!":(language==2?' Please operate with caution!':'Harap beroperasi dengan hati -hati!'),
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: language==1?"删除":(language==2?'Delete':'Hapus'),
            closeOnConfirm: true
        }, function () {
            var ajax = new $ax(Feng.ctxPath + "/TCompetition/delete", function (data) {
                  if(language==1){
                    swal("删除成功", "您已经成功删除了" + nickname + "。", "success");
                }else if(language==2){
                    swal("Delete succeeded!", "You have successfully deleted it" + nickname + "。", "success");
                }else {
                    swal("Hapus berhasil!", "Anda berhasil menghapus" + nickname + "。", "success");
                }
                TCompetition.table.refresh();
            }, function (data) {
                if(language==1){
                    swal("删除失败", data.responseJSON.message + "!", "warning");
                }else if(language==2){
                    swal("Failed to delete", data.responseJSON.message + "!", "warning");
                }else {
                    swal("Hapus Gagal", data.responseJSON.message + "!", "warning");
                }
            var index = layer.open({
                type: 2,
                title: '详情',
                area: ['100%', '100%'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/introduce/update/' + TCompetition.seItem.id
            });
            ajax.set("TCompetitionId",TCompetition.seItem.id);
            ajax.start();
        });
            this.layerIndex = index;
        }
    }
};
// 跳转参与用户页面
TCompetition.user = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length >1 ){
        Feng.info("只能选择一条进行查看!");
    }else {
        if (this.check()) {
            var index = layer.open({
                type: 2,
                title: '详情',
                area: ['100%', '100%'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/introduce/user/' + TCompetition.seItem.id
            });
            this.layerIndex = index;
        }
    }
};
TCompetition.carInsurance = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: language==1?'车辆保险':(language==2?'Vehicle insurance':'Asuransi kendaraan'),
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/TCompetition/carInsurance?carId=' + TCompetition.seItem.id
        });
        this.layerIndex = index;
    }
};
@@ -206,22 +277,15 @@
    queryData['province'] = $("#pCode").val();
    queryData['city'] = $("#cCode").val();
    queryData['activityState'] = $("#activityState").val();
    queryData['createTime'] = $("#createTime").val();
    queryData['time'] = $("#createTime").val();
    queryData['state'] = $("#state").val();
    TCompetition.table.refresh({query: queryData});
};
TCompetition.oneChange = function (e) {
    console.log(111)
    var oneId=$(e).val();
    var ajax = new $ax(Feng.ctxPath + "/tCompetition/onChange", function(data){
        if(data!=null){
            if(language==1){
                var content='<option value="">选择市</option>';
            }else if(language==2){
                var content='<option value="">Choose your franchisee</option>';
            }else {
                var content='<option value="">Pilih franchisee Anda</option>';
            }
            var content='<option value="">选择市</option>';
            $.each(data, function(k,v) {
                content += "<option value='"+v.code+"'>"+v.name+"</option>";
            });
@@ -230,7 +294,7 @@
    });
    ajax.set("oneId",oneId);
    ajax.start();
}
};
TCompetition.resetSearch = function () {
    $("#pCode").val("");
    $("#cCode").val("");
@@ -243,109 +307,6 @@
$(function () {
    var defaultColunms = TCompetition.initColumn();
    var table = new BSTable(TCompetition.id, "/introduce/listAll", defaultColunms);
    table.setPaginationType("server");
    table.setPaginationType("client");
    TCompetition.table = table.init();
});
/**
 * 下载模板
 */
TCompetition.uploadCarModel = function () {
    window.location.href = Feng.ctxPath + "/TCompetition/uploadCarModel";
}
var agreement = function(){
    this.init = function(){
        //模拟上传excel  
        $("#uploadEventBtn").unbind("click").bind("click",function(){
            $("#uploadEventFile").click();
        });
    };
}
/**
 * 导入合同
 */
TCompetition.exporTCompetition = function () {
    var uploadEventFile = $("#uploadEventFile").val();
    if(uploadEventFile == ''){
        if(language==1){
            Feng.info("请选择Excel,再上传");
        }else if(language==2){
            Feng.info("Please select Excel and upload");
        }else {
            Feng.info("Silakan pilih Excel dan upload");
        }
    }else if(uploadEventFile.lastIndexOf(".xls")<0){//可判断以.xls和.xlsx结尾的excel  
        if(language==1){
            Feng.info("只能上传Excel文件");
        }else if(language==2){
            Feng.info("Only Excel files can be uploaded");
        }else {
            Feng.info("Hanya berkas Excel yang dapat diunggah");
        }
    }else{
        var url = Feng.ctxPath + '/TCompetition/exporTCompetition';
        var file = document.querySelector('input[name=file]').files[0];
        var reader = new FileReader();
        if (file) {
            var formData = new FormData();
            formData.append("myfile", file);
            this.sendAjaxRequest(url, 'POST', formData);
        }
    }
}
TCompetition.sendAjaxRequest = function(url,type,data){
    $.ajax({
        url : url,
        type : type,
        data : data,
        success : function(result) {
            if(result.code==500) {
                Feng.info(result.message);
            }else {
                if(language==1){
                    Feng.success("导入成功!");
                }else if(language==2){
                    Feng.success("SUCCESSFUL IMPORT!");
                }else {
                    Feng.success("Import berhasil!");
                }
            }
            TCompetition.table.refresh();
        },
        error : function() {
            if(language==1){
                Feng.error("excel上传失败!");
            }else if(language==2){
                Feng.error("Uploading excel Fails. Procedure!");
            }else {
                Feng.error("Gagal mengunggah excel!");
            }
        },
        cache : false,
        contentType : false,
        processData : false
    });
};
var agreement;
$(function(){
    agreement = new agreement();
    agreement.init();
});
/**
 * 导出车辆操作
 */
TCompetition.ouTCompetition = function () {
    var operation = function() {
        window.location.href = Feng.ctxPath + "/TCompetition/ouTCompetition";
    };
    if(language==1){
        Feng.confirm("是否确认导出车辆信息?", operation);
    }else if(language==2){
        Feng.confirm("Are you sure to export vehicle information?", operation);
    }else {
        Feng.confirm("Apakah Anda pasti akan mengekspor informasi kendaraan?", operation);
    }
}