$(function() { getbaseList(1); $('#addBtn').on('click',function(e) { // 通知浏览器不要执行与事件关联的默认动作 e.preventDefault(); cleanForm(); JY.Model.edit("auDiv", "新增", function() { if (JY.Validate.form("auForm")) { var that = $(this); var phone = document.getElementById('phone').value; if(!(/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/.test(phone))){ layer.msg('联系方式有误,请重填'); return false; } JY.Ajax.doRequest("auForm", bonuspath+'/backstage/subcontractors/insert', null, function(data) { that.dialog("close"); JY.Model.info(data.resMsg, function() { search(); }); }); } }); }); }); function search(){ getbaseList(); } function getbaseList(init) { if (init == 1) $(".pageNum").val(1); JY.Model.loading(); JY.Ajax.doRequest( "baseForm",bonuspath + '/backstage/subcontractors/findByPage',null,function(data) { $("#baseTable tbody").empty(); var obj = data.obj; var list = obj.list; var results = list.results; var permitBtn = obj.permitBtn; var pageNum = list.pageNum, pageSize = list.pageSize, totalRecord = list.totalRecord; var html = ""; if (results != null && results.length > 0) { var leng = (pageNum - 1) * pageSize; for (var i = 0; i < results.length; i++) { var l = results[i]; html += ""; html += ""+ (i + leng + 1) + ""; html += ""+ JY.Object.notEmpty(l.name) + ""; html += ""+ JY.Object.notEmpty(l.chargePerson) + ""; html += ""+ JY.Object.notEmpty(l.phone) + ""; html += ""+ JY.Object.notEmpty(l.remark) + ""; html += rowFunction(l.id); html += ""; } $("#baseTable tbody").append(html); JY.Page.setPage("baseForm", "pageing", pageSize,pageNum, totalRecord, "getbaseList"); } else { html += "没有相关数据"; $("#baseTable tbody").append(html); $("#pageing ul").empty();// 清空分页 } JY.Model.loadingClose(); }); } function rowFunction(id){ var h=""; h+=""; h+=""; h+=""; return h; } function del(id) { JY.Model.confirm("确认删除吗?", function() { JY.Ajax.doRequest(null, bonuspath + '/backstage/subcontractors/delete', { id : id }, function(data) { JY.Model.info(data.resMsg, function() { search(); }); }); }); } function edit(id){ cleanForm(); JY.Ajax.doRequest(null,bonuspath +'/backstage/subcontractors/find',{id:id},function(data){ setForm(data); JY.Model.edit("auDiv","修改",function(){ if(JY.Validate.form("auForm")){ var that =$(this); var phone = document.getElementById('phone').value; if(!(/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/.test(phone))){ layer.msg('联系方式有误,请重填'); return false; } //alert("ist="+ist); JY.Ajax.doRequest("auForm",bonuspath +'/backstage/subcontractors/update',{id:id},function(data){ that.dialog("close"); JY.Model.info(data.resMsg,function(){search();}); }); } }); }); } function cleanForm(){ JY.Tags.cleanForm("auForm"); $("#auForm input[name$='name']").val(''); $("#auForm input[name$='phone']").val(''); $("#auForm input[name$='chargePerson']").val(''); $("#auForm input[name$='remark']").val(''); } function setForm(data){ var l = data.obj[0]; JY.Tags.cleanForm("auForm"); $("#auForm input[name$='name']").val(l.name); $("#auForm input[name$='phone']").val(l.phone); $("#auForm input[name$='chargePerson']").val(l.chargePerson); $("#auForm input[name$='remark']").val(l.remark); }