/** * 初始化认定条件管理详情对话框 */ var IntegralItemMgrInfo = { integralMgrInfoData: {}, validateFields: { projectId: { validators: { notEmpty: { message: '请选择所属积分项目' } } }, name: { validators: { notEmpty: { message: '请输入标准名称' } } }, active: { validators: { notEmpty: { message: '请选择启用状态' } } }, plan: { validators: { notEmpty: { message: '请选择积分方案' } } }, unit: { validators: { notEmpty: { message: '请输入计量单位' } } }, fstNeedAmount: { validators: { notEmpty: { message: '请输入首次达成量' } } }, fstGainPoints: { validators: { notEmpty: { message: '请输入首次获得积分' } } }, stepNeedAmount: { validators: { notEmpty: { message: '请输入每新增量' } } }, stepGainPoints: { validators: { notEmpty: { message: '请输入每新增获得积分' } } }, maxGainPoints: { validators: { notEmpty: { message: '请输入积分上限' } } }, yearly: { validators: { notEmpty: { message: '请选择累计积分方案' } } } } }; /** * 清除数据 */ IntegralItemMgrInfo.clearData = function () { this.integralMgrInfoData = {}; } /** * 设置对话框中的数据 * * @param key 数据的名称 * @param val 数据的具体值 */ IntegralItemMgrInfo.set = function (key, val) { this.integralMgrInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val; return this; } /** * 设置对话框中的数据 * * @param key 数据的名称 * @param val 数据的具体值 */ IntegralItemMgrInfo.get = function (key) { return $("#" + key).val(); } /** * 关闭此对话框 */ IntegralItemMgrInfo.close = function () { parent.layer.close(window.parent.IntegralMgr.layerIndex); } /** * 收集数据 */ IntegralItemMgrInfo.collectData = function () { this .set('id') .set('type') .set('projectId') .set('name') .set('plan') .set('unit') .set('fstNeedAmount') .set('fstGainPoints') .set('stepNeedAmount') .set('stepGainPoints') .set('maxGainPoints') .set('yearly') .set('fileTypeId') .set('active'); } IntegralItemMgrInfo.onTypeChange = function () { var type = $("#type").val(); Feng.addAjaxSelect({ "id": "projectId", "displayCode": "id", "displayName": "name", "type": "GET", "url": "/admin/integral_mgr/getProjectsByType/type/" + type }); } //切换积分方案 IntegralItemMgrInfo.onIntegralPlanChange = function () { var plan = $("#plan").val(); switch (plan) { case "1": $(".planb").css("display", "none"); $('#integraMgrInfoForm').bootstrapValidator('removeField', "stepNeedAmount"); $('#integraMgrInfoForm').bootstrapValidator('removeField', "stepGainPoints"); $('#integraMgrInfoForm').bootstrapValidator('removeField', "maxGainPoints"); $('#integraMgrInfoForm').bootstrapValidator('removeField', "yearly"); break; case "2": $(".planb").css("display", "block"); $('#integraMgrInfoForm').bootstrapValidator('addField', "stepNeedAmount", {validators: {notEmpty: {message: '请填写每新增量'}}}); $('#integraMgrInfoForm').bootstrapValidator('addField', "stepGainPoints", {validators: {notEmpty: {message: '请填写每新增获得积分'}}}); $('#integraMgrInfoForm').bootstrapValidator('addField', "maxGainPoints", {validators: {notEmpty: {message: '请填写积分上限'}}}); $('#integraMgrInfoForm').bootstrapValidator('addField', "yearly", {validators: {notEmpty: {message: '请选择累计积分方案'}}}); break; } } /** * 提交添加 */ IntegralItemMgrInfo.addSubmit = function () { this.clearData(); this.collectData(); if (!this.validate()) { return; } var ajax = new $ax("/admin/integral_mgr/addItem", function (data) { if (data.code == "200") { Feng.success(data.msg); window.parent.IntegralMgr.table.refresh(); IntegralItemMgrInfo.close(); } else { Feng.error(data.msg); } }, function (data) { Feng.error("添加失败!" + data.responseJSON.message + "!"); }); ajax.set(this.integralMgrInfoData); ajax.start(); } /** * 提交修改 */ IntegralItemMgrInfo.editSubmit = function () { this.clearData(); this.collectData(); if (!this.validate()) { return; } var ajax = new $ax(Feng.ctxPath + "/admin/integral_mgr/editItem", function (data) { if (data.code == "200") { Feng.success(data.msg); window.parent.IntegralMgr.table.refresh(); IntegralItemMgrInfo.close(); } else { Feng.error(data.msg); } }, function (data) { Feng.error("修改失败!" + data.responseJSON.message + "!"); }); ajax.set(this.integralMgrInfoData); ajax.start(); } /** * 验证数据是否为空 */ IntegralItemMgrInfo.validate = function () { $('#integraMgrInfoForm').data("bootstrapValidator").resetForm(); $('#integraMgrInfoForm').bootstrapValidator('validate'); return $("#integraMgrInfoForm").data('bootstrapValidator').isValid(); } $(function () { Feng.initValidator("integraMgrInfoForm", IntegralItemMgrInfo.validateFields); //下拉框数据回显 $("select").each(function () { $(this).val($(this).attr("selectVal")); }); });