zone.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. alert(1);
  93. var zoneId = $(this).attr("value");
  94. var url = ctx+"/operator/main/ad/zone/getCode?zoneId="+zoneId;
  95. $.getJSON(url, function(data) {
  96. var data_1 = data;
  97. $('.bootbox-body').text(data_1);
  98. });
  99. bootbox.dialog({
  100. message:"代码为:",
  101. title: "该广告位的代码",
  102. locale: 'zh_CN',
  103. buttons: {
  104. success: {
  105. label: "复制",
  106. className: "btn-success",
  107. callback: function() {
  108. var _content = $('.bootbox-body').text();
  109. }
  110. },
  111. main: {
  112. label: "关闭",
  113. className: "btn-primary",
  114. callback: function() {
  115. }
  116. }
  117. }
  118. });
  119. //以下代码实现复制功能,利用ZeroClipboard插件实现
  120. var client = new ZeroClipboard($('.modal-footer .btn-success'));
  121. client.on('ready', function(event) {
  122. // console.log( 'movie is loaded' );
  123. client.on('copy', function(event) {
  124. event.clipboardData.setData('text/plain', $('.bootbox-body').text());
  125. });
  126. client.on('aftercopy', function(event) {
  127. console.log('Copied text to clipboard: ' + event.data['text/plain']);
  128. });
  129. });
  130. client.on('error', function(event) {
  131. // console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
  132. ZeroClipboard.destroy();
  133. });
  134. });
  135. //取代码
  136. $("#btn-getcode3,#btn-getcode4").click(function(){
  137. alert(1);
  138. var zoneId = $(this).attr("value");
  139. var url = ctx+"/operator/main/ad/zone/getCodeStatistics?zoneId="+zoneId;
  140. $.getJSON(url, function(data) {
  141. var data_1 = data;
  142. $('.bootbox-body').text(data_1);
  143. });
  144. bootbox.dialog({
  145. message:"代码为:",
  146. title: "该广告位的代码",
  147. locale: 'zh_CN',
  148. buttons: {
  149. success: {
  150. label: "复制",
  151. className: "btn-success",
  152. callback: function() {
  153. var _content = $('.bootbox-body').text();
  154. }
  155. },
  156. main: {
  157. label: "关闭",
  158. className: "btn-primary",
  159. callback: function() {
  160. }
  161. }
  162. }
  163. });
  164. //以下代码实现复制功能,利用ZeroClipboard插件实现
  165. var client = new ZeroClipboard($('.modal-footer .btn-success'));
  166. client.on('ready', function(event) {
  167. // console.log( 'movie is loaded' );
  168. client.on('copy', function(event) {
  169. event.clipboardData.setData('text/plain', $('.bootbox-body').text());
  170. });
  171. client.on('aftercopy', function(event) {
  172. console.log('Copied text to clipboard: ' + event.data['text/plain']);
  173. });
  174. });
  175. client.on('error', function(event) {
  176. // console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
  177. ZeroClipboard.destroy();
  178. });
  179. });
  180. /*************************** 创建,编辑广告主 ***************************/
  181. //初始化加载上传控件
  182. if($("#filepicture_picture").html()){
  183. if($("#uploadfilehidden").val() !=""){
  184. $("#imgDivs").css("display","block");
  185. }else{
  186. $("#imgDivs").css("display","none");
  187. }
  188. initFile($("#uploadfile"),$("#pictureName").val());
  189. $('#uploadfilestr').unbind('click').click(function() {
  190. getUploadFile();
  191. });
  192. }
  193. //选中右移
  194. $("#all_industry li").live("click",function() {
  195. var mychoice = this.innerHTML;
  196. $(this).remove();
  197. var ul = document.getElementById("blacklist");
  198. $(ul).append("<li value='"+$(this).attr("value")+"'>" + mychoice + "<input type='button' class='movedel'/></li>");
  199. //将黑名单数据传入后端,格式“***,***,***”
  200. if($("#industry_blacklist").val() == ""){
  201. $("#industry_blacklist").val($(this).attr("value"));
  202. }else{
  203. $("#industry_blacklist").val($("#industry_blacklist").val()+","+$(this).attr("value"));
  204. }
  205. });
  206. //选中左移
  207. $('#blacklist li input.movedel').live("click",function() {
  208. var mychoice = $(this).parents("li").text();
  209. var mychoicevalue = $(this).parents("li").attr("value");
  210. $(this).parents("li").remove();
  211. var ul = document.getElementById("all_industry");
  212. $(ul).append("<li value="+mychoicevalue+">" + mychoice + "</li>");
  213. //左移黑名单删除传值
  214. var industryArr = $("#industry_blacklist").val().split(",");
  215. for(var i=0;i<industryArr.length;i++){
  216. if(industryArr[i] == mychoicevalue){
  217. industryArr.splice(i,1);
  218. }
  219. }
  220. if(industryArr != 0){
  221. for(var j=0;j<industryArr.length;j++){
  222. if(j == 0){
  223. $("#industry_blacklist").val(industryArr[0]);
  224. }else{
  225. $("#industry_blacklist").val($("#industry_blacklist").val()+","+industryArr[j]);
  226. }
  227. }
  228. }else{
  229. $("#industry_blacklist").val("");
  230. }
  231. });
  232. //添加全部
  233. $('#add_all').live("click",function() {
  234. var lis = $('#all_industry li');
  235. var industry_blackname = "";
  236. var len = lis.length;
  237. var ul = document.getElementById("blacklist");
  238. for(var i=0; i<len;i++){
  239. var mychoice = lis[i].innerHTML;
  240. var mychoicevalue = lis[i].value;
  241. lis[i].remove();
  242. $(ul).append("<li value="+mychoicevalue+">" + mychoice + "<input type='button' class='movedel'/></li>");
  243. if($("#industry_blacklist").val() == ""){
  244. $("#industry_blacklist").val(mychoicevalue);
  245. }else{
  246. $("#industry_blacklist").val($("#industry_blacklist").val()+","+mychoicevalue);
  247. }
  248. }
  249. //传值同步添加全部
  250. // document.getElementById("industry_blacklist").value = industry_blackname;
  251. });
  252. //清空全部
  253. $('#clear_all').live("click",function() {
  254. var lis = $('#blacklist li');
  255. var len = lis.length;
  256. var ul = document.getElementById("all_industry");
  257. for(var i=0; i<len;i++){
  258. var mychoice = $(lis[i]).text();
  259. lis[i].remove();
  260. $(ul).append("<li>" + mychoice +"</li>");
  261. }
  262. $("#industry_blacklist").val("");
  263. //传值同步清空
  264. // document.getElementById("industry_blacklist").value ="";
  265. });
  266. //网站添加黑名单
  267. var web_blackname = "";
  268. var glo_web_blacklist = $('#web_blacklist li');
  269. for(var counts=0;counts<glo_web_blacklist.length;counts++){
  270. if(web_blackname){
  271. web_blackname = web_blackname +"," + $(glo_web_blacklist[counts]).text();
  272. }else{
  273. web_blackname =$(glo_web_blacklist[counts]).text();
  274. }
  275. }
  276. $("#add_web").live("click",function() {
  277. var blackname=$('#blackname').val();
  278. if(blackname == ""){
  279. bootbox.alert("请输入要添加的网站黑名单!");
  280. return false;
  281. }
  282. var blacknameArr = $("#web_blacklistvalue").val().split(",");
  283. if($.inArray(blackname, blacknameArr) != -1){
  284. bootbox.alert("您输入的网站黑名单已存在!");
  285. return false;
  286. }
  287. var ul = document.getElementById("web_blacklist");
  288. $(ul).append("<li>" + blackname + "<input type='button' class='movedel'/></li>");
  289. $('#blackname').val("");
  290. //黑名单传值
  291. if($("#web_blacklistvalue").val() == ""){
  292. $("#web_blacklistvalue").val(blackname);
  293. }else{
  294. $("#web_blacklistvalue").val($("#web_blacklistvalue").val()+","+blackname);
  295. }
  296. });
  297. //删除黑名单
  298. $('#web_blacklist li input.movedel').live("click",function() {
  299. $(this).parents("li").remove();
  300. var mychoice = $(this).parents("li").text();
  301. var blacknameArr = $("#web_blacklistvalue").val().split(",");
  302. for(var i=0;i<blacknameArr.length;i++){
  303. if(blacknameArr[i] == mychoice){
  304. blacknameArr.splice(i,1);
  305. }
  306. }
  307. //左移黑名单删除传值
  308. if(blacknameArr.length !=0){
  309. for(var j=0;j<blacknameArr.length;j++){
  310. if(j == 0){
  311. $("#web_blacklistvalue").val(blacknameArr[0]);
  312. }else{
  313. $("#web_blacklistvalue").val($("#web_blacklistvalue").val()+","+blacknameArr[j]);
  314. }
  315. }
  316. }else{
  317. $("#web_blacklistvalue").val("");
  318. }
  319. });
  320. //清空黑名单
  321. $("#clear_allweb").live("click",function() {
  322. var lis = $('#web_blacklist li');
  323. var len = lis.length;
  324. for(var i=0; i<len;i++){
  325. lis[i].remove();
  326. }
  327. //传值处同步删除
  328. document.getElementById("web_blacklistvalue").value ="";
  329. });
  330. //初始校验表单
  331. if($("#validateForm").html()){
  332. $("#validateForm").autovalidate();
  333. }
  334. $(".btn-save").click(function(){
  335. if (!$("#validateForm").validate()) {
  336. return false;
  337. }
  338. $("#validateForm").submit();
  339. return false;
  340. });
  341. $(".btn-cancel").click(function(){
  342. location.href = ctx+"/operator/main/ad/zone";
  343. });
  344. //鼠标划过小图片显示大图片
  345. $("#son_imgDiv").mousemove(function(event){
  346. var event = event || window.event;
  347. $("#enlarge_images").css("display","block");
  348. var imgsrc = $(this).find("img#smallImg").attr("src");
  349. imgsrc = imgsrc.substring(0,imgsrc.lastIndexOf(".")-6)+imgsrc.substring(imgsrc.lastIndexOf("."),imgsrc.length);
  350. $("#enlarge_images").html('<img src="'+imgsrc+'"/>');
  351. $("#enlarge_images").css("top",document.body.scrollTop + event.clientY - 300 + "px");
  352. $("#enlarge_images").css("left",document.body.scrollLeft + event.clientX - 660 + "px");
  353. });
  354. $("#son_imgDiv").mouseout(function(event){
  355. $("#enlarge_images").html("");
  356. $("#enlarge_images").css("display","none");
  357. });
  358. });
  359. function exportExcel_list(){
  360. var searchValue = $("#searchValue").val();
  361. if(searchValue == "请输入关键字"){
  362. searchValue = "";
  363. }
  364. var param = "?width="+$("#width").val()+"&height="+$("#height").val()+"&device="+$("#device").val()+"&position="+$("#position").val()+"&status="+$("#status").val()+"&searchValue="+searchValue;
  365. $("#exportExcel").attr("href",$("#ctx").val()+"/operator/main/ad/zone/exportDataReportExcel"+param);
  366. return false;
  367. }
  368. //初始化选择文件框
  369. function initFile(obj,pictureName){
  370. var name = "";
  371. if(pictureName == "" || pictureName == null || pictureName == "noFiles"){
  372. name = "No File ...";
  373. }else{
  374. name = pictureName.substring(pictureName.lastIndexOf("\\")+1,pictureName.length);
  375. }
  376. obj.ace_file_input({
  377. no_file:name,
  378. btn_choose:'选择',
  379. btn_change:'改变',
  380. droppable:false,
  381. onchange:null,
  382. thumbnail:false
  383. });
  384. }
  385. //文件上传ajax文件上传
  386. function getUploadFile(){
  387. var _href = $("#uploadfilestr").attr('href');
  388. $.ajaxFileUpload({
  389. url:_href,
  390. secureuri:false,
  391. fileElementId:"uploadfile",
  392. dataType: 'json',
  393. success: function (result, status) {
  394. var path = result.data['url'];
  395. removeFile("uploadfile","filepicture_picture","uploadfilehidden",result);
  396. if (result.status == 'ok') {
  397. var orgImg = path.substring(0,path.indexOf(","));
  398. var smallImg = path.substring(path.indexOf(",")+1);
  399. $("#uploadfilehidden").val(orgImg);
  400. $("#smallImg").attr("src",smallImg);
  401. $("#default_path_small").val(smallImg);
  402. $("#imgDivs").css("display","block");
  403. var result = 0;
  404. removeFile("uploadfile","filepicture_picture","uploadfilehidden",result);
  405. bootbox.alert("上传成功!");
  406. }else if (result.status == 'error') {
  407. $("#uploadfilehidden").val("");
  408. $("#smallImg").attr("src","");
  409. $("#default_path_small").val("");
  410. $("#imgDivs").css("display","none");
  411. bootbox.alert(result.msg);
  412. }
  413. },
  414. error: function (data, status, e)
  415. {
  416. $("#uploadfilehidden").val("");
  417. $("#smallImg").attr("src","");
  418. $("#default_path_small").val("");
  419. $("#imgDivs").css("display","none");
  420. removeFile("uploadfile","filepicture_picture","uploadfilehidden");
  421. console.log(e);
  422. }
  423. });
  424. return false;
  425. }
  426. //上传文件时conle file 删除 file
  427. function removeFile(_elemId,_removeId,picPathId,result){
  428. var filename = $('#'+_elemId).parent().find("span").attr("data-title");
  429. var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;//判断是否是谷歌浏览器
  430. if(filename==null || filename==''){
  431. filename = "No File ...";
  432. }
  433. var option = {};
  434. var defaultOptions = {
  435. no_file:'No File ...',
  436. btn_choose:'选择',
  437. btn_change:'改变',
  438. droppable:false,
  439. onchange:null,
  440. thumbnail:false
  441. };
  442. if(isChrome && result == 0){
  443. option = {no_file:filename };
  444. }else if(isChrome && result == 1){
  445. option = {no_file:'No File ...' };
  446. }else{
  447. option = {no_file:filename };
  448. }
  449. var opts = $.extend(defaultOptions,option);
  450. var newfile = $("#"+_elemId).clone();
  451. $("#"+_removeId).find(".ace-file-input").remove();
  452. $("#"+_removeId+" #"+picPathId).after(newfile);
  453. $("#"+_elemId).ace_file_input(opts);
  454. }