$(function(){ $('select[name="brandName"]').select2({ placeholder: "请选择品牌", allowClear: true, width: '120px' }); $('select[name="showEnv"]').select2({ placeholder: "请选择播出环境", allowClear: true, width: '120px' }); }); function isEmpty(obj){ if (obj != null && obj != '') { return false; } else { return true; } } // 播出媒体 var mediaNameSelect = $('select[name="mediaName"]').select2({ placeholder: "请输入播出媒体", allowClear: true, width:'120px', ajax:{ url: _PUBLIC_ +'ad-media/select/list.do', dataType:'json', quietMillis:100, data:function(params){ return { name : params.term, pageNo : params.page || 1, pageSize : 20 } }, processResults: function (data, params) { params.page = params.page || 1; return { results: data.results, pagination: { more: (params.page * 20) < data.total } }; }, cache: true } }); // 产品/栏目 var productNameSelect = $('select[name="productName"]').select2({ placeholder: "请输入名称", allowClear: true, width:'120px', ajax:{ url: _PUBLIC_ + ($("#type").val() == 0 ? 'ad-product/select/list.do' : 'ad-platform/select/list.do'), dataType:'json', quietMillis:100, data:function(params){ return { productName : params.term, pageNo : params.page || 1, pageSize : 20 } }, processResults: function (data, params) { params.page = params.page || 1; return { results: data.results, pagination: { more: (params.page * 20) < data.total } }; }, cache: true } }); // 品牌 $('select[name="productName"]').live('change',function(){ if($("#type").val() == 0){ ajax( _PUBLIC_ +"ad-product/brand_name_by_product_name.do", {"productName" : $("#productName").val()}, function(res){ $('select[name="brandName"]').html(''); }) } }); // 电视剧 var productNameSelect = $('select[name="tvName"]').select2({ placeholder: "请输入播出节目", allowClear: true, width:'120px', ajax:{ url: _PUBLIC_ +'ad-tv/select/list.do', dataType:'json', quietMillis:100, data:function(params){ return { name : params.term, pageNo : params.page || 1, pageSize : 20 } }, processResults: function (data, params) { params.page = params.page || 1; return { results: data.results, pagination: { more: (params.page * 20) < data.total } }; }, cache: true } }); // 获取表格数据 function getList(page){ page = page || 1; var pageSize = 10, data = { "type" : $("#type").val(), "productName" : $("#productName").val(), "brandName" : $("#brandName").val(), "advMaster" : $("#advMaster").val(), "brandName" : $("#brandName").val(), "mediaName" : $("#mediaName").val(), "showEnv" : $("#showEnv").val(), "tvName" : $("#tvName").val(), "showTimeStart" : $("#showTimeStart").val(), "showTimeEnd" : $("#showTimeEnd").val(), "showDateStart" : $("#showDateStart").val(), "showDateEnd" : $("#showDateEnd").val(), "showDurationMin" : $("#showDurationMin").val(), "showDurationMax" : $("#showDurationMax").val(), "priceMin" : $("#priceMin").val(), "priceMax" : $("#priceMax").val(), "phone" : $("#phone").val(), "pageNo" : page, "pageSize" : pageSize }, html = ""; if(!isEmpty(data.showDurationMin) || !isEmpty(data.showDurationMax)){ var reg = /^[0-9]+$/; if (!reg.test(data.showDuration) || !reg.test(data.showDurationMax)) { top.alert('请输入正确的播出时长'); return false; } } if(!isEmpty(data.priceMin) || !isEmpty(data.priceMax)){ var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/; if (!reg.test(data.priceMin) || !reg.test(data.priceMax) ) { top.alert('请输入正确刊例价格'); return false; } } if(!isEmpty(data.phone)){ var reg = /^1\d{10}$/; if (!reg.test(data.phone)) { top.alert('请输入正确手机号'); return false; } } $("#page, #list").empty(); ajax("ajax_list.do", data, function(res){ if (res.code == 1 && res.list.records.length > 0){ $.each(res.list.records, function(index, item){ html += ''+ ''+ ''+ (item.productName == undefined || item.productName == null ? '' : item.productName ) +''+ ''+ (item.brandName == undefined || item.brandName == null ? '' : item.brandName ) +''+ ''+ (item.advMaster == undefined || item.advMaster == null ? '' : item.advMaster ) +''+ ''+ (item.mediaName == undefined || item.mediaName == null ? '' : item.mediaName) +''+ ''+ (item.showDate == undefined || item.showDate == null ? '' : item.showDate) +''+ ''+ (item.showTime == undefined || item.showTime == null ? '' : item.showTime) +''+ ''+ (item.showEnv == undefined || item.showEnv == null ? '' : item.showEnv) +''+ ''+ (item.tvName == undefined || item.tvName == null ? '' : item.tvName) +''+ ''+ (item.phone == undefined || item.phone == null ? '' : item.phone) +''+ ''+ (item.showDuration == undefined || item.showDuration == null ? '' : item.showDuration) +''+ ''+ (item.price == undefined || item.price == null ? '' : item.price) +''+ ''+ (update_flag == 1 && item.type == 0 ? '编辑  ' : '') + (update_flag == 1 && item.type == 1 ? '编辑  ' : '') + (delete_flag == 1 ? '删除' : '' ) + ''+ ''; }); $("#list").html(html); $.checkbox(); $("#count").text(res.list.total); var newpage = new createPage(res.list.total, page, pageSize, 3); $("#page").html(newpage.pageHtml); } else { $("#list").info("暂无数据。"); $("#count").text(0); } }); } pageGo = function(page){ resetCheckAll(); getList(page); } // 删除单个 function delRecord(id){ confirm("确定删除该条记录吗?", function(){ ajax("del.do", {"id" : id}, function(res){ if (res.code == 1){ alert("删除成功。", 1, function(){ window.location.href = "index.do?type="+$("#type").val(); }); } else { alert(res.msg); } }); }); } // 删除多个 function delRecordBatch(){ var arr = document.getElementsByName("chk"); var ids = ""; for (i=0; i