zone.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. $(document).ready(function(){
  2. var ctx = $("#ctx").val();//获取服务器地址
  3. /*************************** 广告位列表页 ***************************/
  4. //获取尺寸
  5. if($("#size").val() == 0 || $("#size").val() == ""){
  6. $("#selectBar_size a:first").addClass("selectBar_change");
  7. }
  8. $("#selectBar_size a").each(function(){
  9. var value = $(this).attr("value");
  10. if($("#size").val() == value){
  11. $(this).addClass("selectBar_change").siblings('.selectBar_change').removeClass('selectBar_change');
  12. }
  13. });
  14. $("#selectBar_size a").click(function(){
  15. $("#size").val($(this).attr("value"));
  16. if($(this).attr("value") != ""){
  17. var _size = $(this).attr("value").split('X',2);
  18. $("#width").val(_size[0]);
  19. $("#height").val(_size[1]);
  20. }else{
  21. $("#width").val("");
  22. $("#height").val("");
  23. }
  24. refreshData();
  25. });
  26. //类型
  27. if($("#device").val() == -1 || $("#device").val() == ""){
  28. $("#selectBar_type a:first").addClass("selectBar_change");
  29. }
  30. $("#selectBar_type a").each(function(){
  31. var value = $(this).attr("value");
  32. if($("#device").val() == value){
  33. $(this).addClass("selectBar_change").siblings('.selectBar_change').removeClass('selectBar_change');
  34. }
  35. });
  36. $("#selectBar_type a").click(function(){
  37. $("#device").val($(this).attr("value"));
  38. refreshData();
  39. });
  40. //获取创意尺寸
  41. if($("#position").val() == -1 || $("#position").val() == ""){
  42. $("#selectBar_position a:first").addClass("selectBar_change");
  43. }
  44. $("#selectBar_position a").each(function(){
  45. var value = $(this).attr("value");
  46. if($("#position").val() == value){
  47. $(this).addClass("selectBar_change").siblings('.selectBar_change').removeClass('selectBar_change');
  48. }
  49. });
  50. $("#selectBar_position a").click(function(){
  51. $("#position").val($(this).attr("value"));
  52. refreshData();
  53. });
  54. //状态全部、开启、停用
  55. if($("#status").val() == -1 || $("#status").val() == ""){
  56. $("#selectBar_status a:first").addClass("selectBar_change");
  57. }
  58. $("#selectBar_status a").each(function(){
  59. var value = $(this).attr("value");
  60. if($("#status").val() == value){
  61. $(this).addClass("selectBar_change").siblings('.selectBar_change').removeClass('selectBar_change');
  62. }
  63. });
  64. $("#selectBar_status a").click(function(){
  65. $("#status").val($(this).attr("value"));
  66. refreshData();
  67. });
  68. //开启,暂停
  69. $("#btn-enable,#btn-disable,#btn-delete").click(function(){
  70. if($(this).attr("id") == "btn-enable"){
  71. url = ctx+"/operator/main/ad/zone/enable";
  72. }else if($(this).attr("id") == "btn-disable"){
  73. url = ctx+"/operator/main/ad/zone/disable";
  74. }else if($(this).attr("id") == "btn-delete"){
  75. url = ctx+"/operator/main/ad/zone/delete";
  76. }
  77. singleOper($(this),url);
  78. });
  79. //批量开启,批量暂停
  80. $("#all-btn-enable,#all-btn-disable,#all-btn-delete").click(function(){
  81. if($(this).attr("id") == "all-btn-enable"){
  82. url = ctx+"/operator/main/ad/zone/enable";
  83. }else if($(this).attr("id") == "all-btn-disable"){
  84. url = ctx+"/operator/main/ad/zone/disable";
  85. }else if($(this).attr("id") == "all-btn-delete"){
  86. url = ctx+"/operator/main/ad/zone/delete";
  87. }
  88. batchOpear($(this),url);
  89. });
  90. //取代码
  91. $("#btn-getcode,#btn-getcode2").click(function(){
  92. var zoneId = $(this).attr("value");
  93. var url = ctx+"/operator/main/ad/zone/getCode?zoneId="+zoneId;
  94. $.getJSON(url, function(data) {
  95. var data_1 = data;
  96. $('.bootbox-body').text(data_1);
  97. });
  98. bootbox.dialog({
  99. message:"代码为:",
  100. title: "该广告位的代码",
  101. locale: 'zh_CN',
  102. buttons: {
  103. success: {
  104. label: "复制",
  105. className: "btn-success",
  106. callback: function() {
  107. var _content = $('.bootbox-body').text();
  108. }
  109. },
  110. main: {
  111. label: "关闭",
  112. className: "btn-primary",
  113. callback: function() {
  114. }
  115. }
  116. }
  117. });
  118. //以下代码实现复制功能,利用ZeroClipboard插件实现
  119. var client = new ZeroClipboard($('.modal-footer .btn-success'));
  120. client.on('ready', function(event) {
  121. // console.log( 'movie is loaded' );
  122. client.on('copy', function(event) {
  123. event.clipboardData.setData('text/plain', $('.bootbox-body').text());
  124. });
  125. client.on('aftercopy', function(event) {
  126. console.log('Copied text to clipboard: ' + event.data['text/plain']);
  127. });
  128. });
  129. client.on('error', function(event) {
  130. // console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
  131. ZeroClipboard.destroy();
  132. });
  133. });
  134. //取代码统计
  135. $("#btn-getcode3,#btn-getcode4").click(function(){
  136. var zoneId = $(this).attr("value");
  137. var url = ctx+"/operator/main/ad/zone/getCodeStatistics?zoneId="+zoneId;
  138. $.getJSON(url, function(data) {
  139. var data_1 = data;
  140. $('.bootbox-body').text(data_1);
  141. });
  142. bootbox.dialog({
  143. message:"代码为:",
  144. title: "该广告位的代码",
  145. locale: 'zh_CN',
  146. buttons: {
  147. success: {
  148. label: "复制",
  149. className: "btn-success",
  150. callback: function() {
  151. var _content = $('.bootbox-body').text();
  152. }
  153. },
  154. main: {
  155. label: "关闭",
  156. className: "btn-primary",
  157. callback: function() {
  158. }
  159. }
  160. }
  161. });
  162. //以下代码实现复制功能,利用ZeroClipboard插件实现
  163. var client = new ZeroClipboard($('.modal-footer .btn-success'));
  164. client.on('ready', function(event) {
  165. // console.log( 'movie is loaded' );
  166. client.on('copy', function(event) {
  167. event.clipboardData.setData('text/plain', $('.bootbox-body').text());
  168. });
  169. client.on('aftercopy', function(event) {
  170. console.log('Copied text to clipboard: ' + event.data['text/plain']);
  171. });
  172. });
  173. client.on('error', function(event) {
  174. // console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
  175. ZeroClipboard.destroy();
  176. });
  177. });
  178. /*************************** 创建,编辑广告主 ***************************/
  179. //初始化加载上传控件
  180. if($("#filepicture_picture").html()){
  181. if($("#uploadfilehidden").val() !=""){
  182. $("#imgDivs").css("display","block");
  183. }else{
  184. $("#imgDivs").css("display","none");
  185. }
  186. initFile($("#uploadfile"),$("#pictureName").val());
  187. $('#uploadfilestr').unbind('click').click(function() {
  188. getUploadFile();
  189. });
  190. }
  191. //选中右移
  192. $("#all_industry li").live("click",function() {
  193. var obj = $(this);
  194. $("#industryFatherName").val(this.innerHTML);
  195. $.post(ctx+'/operator/main/ad/zone/isExistIndustry',{fatherId:$(this).attr("value")},function(data){
  196. if(data == false){
  197. layer.open({
  198. type: 2,
  199. title: '选择行业',
  200. shadeClose: false,
  201. shade: 0.6,
  202. fix:false,
  203. area: ['685px','430px'],
  204. content: [ctx+'/operator/main/ad/zone/getIndustry?fatherId='+obj.attr("value")]
  205. });
  206. return false;
  207. }else{
  208. var industryId = obj.attr("value");
  209. $("#blacklist").append("<li value='"+industryId+"' title='"+obj.text()+"-"+obj.text()+"'><span id='industryName'>" + obj.text() + "</span><input type='button' class='movedel'/></li>");
  210. if($("#industry_blacklist").val() == ""){
  211. $("#industry_blacklist").val(industryId);//父层的元素
  212. }else {
  213. $("#industry_blacklist").val($("#industry_blacklist").val()+","+industryId);//父层的元素
  214. }
  215. return false;
  216. }
  217. });
  218. });
  219. //选中左移
  220. $('#blacklist li input.movedel').live("click",function() {
  221. var mychoice = $(this).parents("li").text();
  222. var mychoicevalue = $(this).parents("li").attr("value");
  223. $(this).parents("li").remove();
  224. //左移黑名单删除传值
  225. var industryArr = $("#industry_blacklist").val().split(",");
  226. for(var i=0;i<industryArr.length;i++){
  227. if(industryArr[i] == mychoicevalue){
  228. industryArr.splice(i,1);
  229. }
  230. }
  231. if(industryArr != 0){
  232. for(var j=0;j<industryArr.length;j++){
  233. if(j == 0){
  234. $("#industry_blacklist").val(industryArr[0]);
  235. }else{
  236. $("#industry_blacklist").val($("#industry_blacklist").val()+","+industryArr[j]);
  237. }
  238. }
  239. }else{
  240. $("#industry_blacklist").val("");
  241. }
  242. });
  243. //添加全部
  244. $('#add_all').live("click",function() {
  245. var url = ctx+"/operator/main/ad/zone/getAllIndustry";
  246. var ul = document.getElementById("blacklist");
  247. var industryId = "";
  248. var list = $("#industry_blacklist").val();
  249. $.getJSON( url, function(data) {
  250. $.each( data, function( key, val ) {
  251. if(list.indexOf(val.id) == -1){
  252. industryId += val.id+",";
  253. }
  254. $(ul).append("<li value='"+val.id+"' title='"+val.fatherName+"-"+val.name+"'><span id='industryName'>" + val.name + "</span><input type='button' class='movedel'/></li>");
  255. });
  256. });
  257. if(industryId != ""){
  258. industryId = industryId.substring(0, industryId.length-1);
  259. if(list == ""){
  260. $("#industry_blacklist").val(industryId);
  261. }else {
  262. $("#industry_blacklist").val(list+","+industryId);
  263. }
  264. }
  265. });
  266. //清空全部
  267. $('#clear_all').live("click",function() {
  268. var lis = $('#blacklist li');
  269. var len = lis.length;
  270. for(var i=0; i<len;i++){
  271. lis[i].remove();
  272. }
  273. $("#industry_blacklist").val("");
  274. //传值同步清空
  275. // document.getElementById("industry_blacklist").value ="";
  276. });
  277. //网站添加黑名单
  278. var web_blackname = "";
  279. var glo_web_blacklist = $('#web_blacklist li');
  280. for(var counts=0;counts<glo_web_blacklist.length;counts++){
  281. if(web_blackname){
  282. web_blackname = web_blackname +"," + $(glo_web_blacklist[counts]).text();
  283. }else{
  284. web_blackname =$(glo_web_blacklist[counts]).text();
  285. }
  286. }
  287. $("#add_web").live("click",function() {
  288. var blackname=$('#blackname').val();
  289. if(blackname == ""){
  290. bootbox.alert("请输入要添加的网站黑名单!");
  291. return false;
  292. }
  293. var blacknameArr = $("#web_blacklistvalue").val().split(",");
  294. if($.inArray(blackname, blacknameArr) != -1){
  295. bootbox.alert("您输入的网站黑名单已存在!");
  296. return false;
  297. }
  298. var ul = document.getElementById("web_blacklist");
  299. $(ul).append("<li>" + blackname + "<input type='button' class='movedel'/></li>");
  300. $('#blackname').val("");
  301. //黑名单传值
  302. if($("#web_blacklistvalue").val() == ""){
  303. $("#web_blacklistvalue").val(blackname);
  304. }else{
  305. $("#web_blacklistvalue").val($("#web_blacklistvalue").val()+","+blackname);
  306. }
  307. });
  308. //删除黑名单
  309. $('#web_blacklist li input.movedel').live("click",function() {
  310. $(this).parents("li").remove();
  311. var mychoice = $(this).parents("li").text();
  312. var blacknameArr = $("#web_blacklistvalue").val().split(",");
  313. for(var i=0;i<blacknameArr.length;i++){
  314. if(blacknameArr[i] == mychoice){
  315. blacknameArr.splice(i,1);
  316. }
  317. }
  318. //左移黑名单删除传值
  319. if(blacknameArr.length !=0){
  320. for(var j=0;j<blacknameArr.length;j++){
  321. if(j == 0){
  322. $("#web_blacklistvalue").val(blacknameArr[0]);
  323. }else{
  324. $("#web_blacklistvalue").val($("#web_blacklistvalue").val()+","+blacknameArr[j]);
  325. }
  326. }
  327. }else{
  328. $("#web_blacklistvalue").val("");
  329. }
  330. });
  331. //清空黑名单
  332. $("#clear_allweb").live("click",function() {
  333. var lis = $('#web_blacklist li');
  334. var len = lis.length;
  335. for(var i=0; i<len;i++){
  336. lis[i].remove();
  337. }
  338. //传值处同步删除
  339. document.getElementById("web_blacklistvalue").value ="";
  340. });
  341. //初始校验表单
  342. if($("#validateForm").html()){
  343. $("#validateForm").autovalidate();
  344. }
  345. $(".btn-save").click(function(){
  346. if (!$("#validateForm").validate()) {
  347. return false;
  348. }
  349. $("#validateForm").submit();
  350. return false;
  351. });
  352. $(".btn-cancel").click(function(){
  353. location.href = ctx+"/operator/main/ad/zone";
  354. });
  355. //鼠标划过小图片显示大图片
  356. $("#son_imgDiv").mousemove(function(event){
  357. var event = event || window.event;
  358. $("#enlarge_images").css("display","block");
  359. var imgsrc = $(this).find("img#smallImg").attr("src");
  360. imgsrc = imgsrc.substring(0,imgsrc.lastIndexOf(".")-6)+imgsrc.substring(imgsrc.lastIndexOf("."),imgsrc.length);
  361. $("#enlarge_images").html('<img src="'+imgsrc+'"/>');
  362. $("#enlarge_images").css("top",document.body.scrollTop + event.clientY - 300 + "px");
  363. $("#enlarge_images").css("left",document.body.scrollLeft + event.clientX - 660 + "px");
  364. });
  365. $("#son_imgDiv").mouseout(function(event){
  366. $("#enlarge_images").html("");
  367. $("#enlarge_images").css("display","none");
  368. });
  369. });
  370. function exportExcel_list(){
  371. var searchValue = $("#searchValue").val();
  372. if(searchValue == "请输入关键字"){
  373. searchValue = "";
  374. }
  375. var param = "?width="+$("#width").val()+"&height="+$("#height").val()+"&device="+$("#device").val()+"&position="+$("#position").val()+"&status="+$("#status").val()+"&searchValue="+searchValue;
  376. $("#exportExcel").attr("href",$("#ctx").val()+"/operator/main/ad/zone/exportDataReportExcel"+param);
  377. return false;
  378. }
  379. //初始化选择文件框
  380. function initFile(obj,pictureName){
  381. var name = "";
  382. if(pictureName == "" || pictureName == null || pictureName == "noFiles"){
  383. name = "No File ...";
  384. }else{
  385. name = pictureName.substring(pictureName.lastIndexOf("\\")+1,pictureName.length);
  386. }
  387. obj.ace_file_input({
  388. no_file:name,
  389. btn_choose:'选择',
  390. btn_change:'改变',
  391. droppable:false,
  392. onchange:null,
  393. thumbnail:false
  394. });
  395. }
  396. //文件上传ajax文件上传
  397. function getUploadFile(){
  398. var _href = $("#uploadfilestr").attr('href');
  399. $.ajaxFileUpload({
  400. url:_href,
  401. secureuri:false,
  402. fileElementId:"uploadfile",
  403. dataType: 'json',
  404. success: function (result, status) {
  405. var path = result.data['url'];
  406. removeFile("uploadfile","filepicture_picture","uploadfilehidden",result);
  407. if (result.status == 'ok') {
  408. var orgImg = path.substring(0,path.indexOf(","));
  409. var smallImg = path.substring(path.indexOf(",")+1);
  410. $("#uploadfilehidden").val(orgImg);
  411. $("#smallImg").attr("src",smallImg);
  412. $("#default_path_small").val(smallImg);
  413. $("#imgDivs").css("display","block");
  414. var result = 0;
  415. removeFile("uploadfile","filepicture_picture","uploadfilehidden",result);
  416. bootbox.alert("上传成功!");
  417. }else if (result.status == 'error') {
  418. $("#uploadfilehidden").val("");
  419. $("#smallImg").attr("src","");
  420. $("#default_path_small").val("");
  421. $("#imgDivs").css("display","none");
  422. bootbox.alert(result.msg);
  423. }
  424. },
  425. error: function (data, status, e)
  426. {
  427. $("#uploadfilehidden").val("");
  428. $("#smallImg").attr("src","");
  429. $("#default_path_small").val("");
  430. $("#imgDivs").css("display","none");
  431. removeFile("uploadfile","filepicture_picture","uploadfilehidden");
  432. console.log(e);
  433. }
  434. });
  435. return false;
  436. }
  437. //上传文件时conle file 删除 file
  438. function removeFile(_elemId,_removeId,picPathId,result){
  439. var filename = $('#'+_elemId).parent().find("span").attr("data-title");
  440. var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;//判断是否是谷歌浏览器
  441. if(filename==null || filename==''){
  442. filename = "No File ...";
  443. }
  444. var option = {};
  445. var defaultOptions = {
  446. no_file:'No File ...',
  447. btn_choose:'选择',
  448. btn_change:'改变',
  449. droppable:false,
  450. onchange:null,
  451. thumbnail:false
  452. };
  453. if(isChrome && result == 0){
  454. option = {no_file:filename };
  455. }else if(isChrome && result == 1){
  456. option = {no_file:'No File ...' };
  457. }else{
  458. option = {no_file:filename };
  459. }
  460. var opts = $.extend(defaultOptions,option);
  461. var newfile = $("#"+_elemId).clone();
  462. $("#"+_removeId).find(".ace-file-input").remove();
  463. $("#"+_removeId+" #"+picPathId).after(newfile);
  464. $("#"+_elemId).ace_file_input(opts);
  465. }