brand_placement.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. // 获取表格数据
  2. function getList(page){
  3. page = page || 1;
  4. var pageSize = 10, data = {
  5. "brand" : $("#brand").val(),
  6. "model" : $("#model").val(),
  7. "programName" : $("#programName").val(),
  8. "type" : $("#type option:selected").val(),
  9. "form" : $("#form option:selected").val(),
  10. "priceMin" : $("#priceMin").val(),
  11. "priceMax" : $("#priceMax").val(),
  12. "tvMode" : $("#tvMode option:selected").val(),
  13. "showMode" : $("#showMode option:selected").val(),
  14. "frequencyMin" : $("#frequencyMin").val(),
  15. "frequencyMax" : $("#frequencyMax").val(),
  16. "lengthMin" : $("#lengthMin").val(),
  17. "lengthMax" : $("#lengthMax").val(),
  18. "pageNo" : page,
  19. "pageSize" : pageSize
  20. }, html = "";
  21. $("#page, #list").empty();
  22. ajax("ajax_brand_placement.do", data, function(res){
  23. if (res.code == 1 && res.list.length > 0){
  24. $.each(res.list, function(index, item){
  25. html += '<tr>'+
  26. '<td><input type="checkbox" class="checkbox {click:itemCheck}" name="chk" value="'+item.id+'" /><label></label></td>'+
  27. '<td>'+item.brand.toNull()+'</td>'+
  28. '<td>'+item.model.toNull()+'</td>'+
  29. '<td>'+item.program_name.toNull()+'</td>'+
  30. '<td>'+(item.type ? item.type.toString().decode(1,"综艺",2,"栏目",3,"电视剧",4,"电影","") : "")+'</td>'+
  31. // '<td>'+item.type.toString().decode("1",item.show_year!=''?item.show_year+"年":item.show_year.toNull(), "2",item.show_year!=''?"第"+item.show_year +"季":item.show_year.toNull(), "/") +'</td>'+
  32. '<td>'+ (item.type == 1 || item.type == 2 ? item.showCycle.toString().decode("1",item.show_year != '' ? item.show_year + "年":item.show_year.toNull(),"2",item.show_year != '' ?"第" + item.show_year +"季" :item.show_year.toNull(),""):"") +'</td>'+
  33. '<td>'+item.type.toString().decode("1",item.show_phase!=''?"第"+item.show_phase+"期":item.show_phase.toNull(), "2",item.show_phase!=''?"第"+item.show_phase+"期":item.show_phase.toNull(), "3",item.episode!=''?"第"+item.episode+"集":item.episode.toNull(), "/") +'</td>'+
  34. '<td>'+item.show_time.toNull()+'</td>'+
  35. '<td>'+(item.type ? (item.type<=2?retForm(item.form):"/") : "/")+'</td>'+
  36. '<td class="edit">'+
  37. '<a href="javascript:placementModfiyOnList(\'\',\'广告属性/植入方式\','+item.id+');">'+item.mode.replace(/\,/img, "、").toNull()+'</a><br />'+
  38. '</td>'+
  39. '<td>'+(item.frequency != -1 ? item.frequency : "")+'</td>'+// 频次
  40. '<td>'+(item.length != -1 ? item.length : "")+'</td>'+// 时长
  41. '<td>'+item.price+'</td>'+// 预估价格
  42. '<td class="edit">'+
  43. (update_flag == 1 ? '<a href="brand_placement_info.do?id='+item.id+'" target="_blank" >编辑</a>&nbsp;&nbsp;' : '')+
  44. (delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '')+
  45. '</td>'+
  46. '</tr>';
  47. });
  48. $("#list").html(html);
  49. $.checkbox();
  50. // $(".table").hoverTable(true);
  51. $("#count").text(res.count);
  52. var newpage = new createPage(res.count,page,pageSize,3);
  53. $("#page").html(newpage.pageHtml);
  54. } else {
  55. $("#list").info("暂无数据。");
  56. }
  57. });
  58. }
  59. pageGo = function(page){
  60. resetCheckAll();
  61. getList(page);
  62. }
  63. // 广告形式
  64. function retForm(form){
  65. return form == undefined ? "" : form.replace(/1/,"冠名").replace(/2/,"特约").replace(/3/,"互动支持").replace(/4/,"合作伙伴").replace(/5/,"指定产品").replace(/6/,"指定用车").replace(/7/,"其他").replace(/8/,"创意中插").replace(/\,/g,"、");
  66. }
  67. // 删除单个品牌植入
  68. function delRecord(id){
  69. confirm("您确定需要删除该条记录吗?", function(){
  70. ajax("del_brand_placement.do", {"id" : id}, function(res){
  71. if (res.code == 1){
  72. alert("删除成功", 1, function(){
  73. window.location.href = "brand_placement.do";
  74. });
  75. } else {
  76. alert(res.msg);
  77. }
  78. });
  79. });
  80. }
  81. // 删除多个品牌植入
  82. function delRecordBatch(){
  83. var arr = document.getElementsByName("chk");
  84. var ids = "";
  85. for (i=0; i<arr.length; i++){
  86. if (arr[i].checked){
  87. ids += ("," + arr[i].value);
  88. }
  89. }
  90. if (ids.isEmpty()){
  91. alert("请至少选择一条记录");
  92. return false;
  93. }
  94. confirm("确定删除这些记录吗?", function(){
  95. ajax("batch_del_for_placement.do", {"ids" : ids.substring(1,ids.length)}, function(res){
  96. if (res.code == 1){
  97. alert("删除成功。", 1, function(){
  98. window.location.href = "brand_placement.do";
  99. });
  100. } else {
  101. alert(res.msg);
  102. }
  103. });
  104. });
  105. }
  106. // 删除单个植入方式(从表格中移除)
  107. function delMode(){
  108. }
  109. // 保存详情信息
  110. function save(){
  111. /* 得到并验证基本信息数据 */
  112. var data = $('#dataForm').serializeJSON();
  113. data.id = $.getParam("id");
  114. data.programName = $("#programName option:selected").val();
  115. data.showYear = $("#showYear option:selected").val();
  116. data.showPhase = $("#showPhase option:selected").val();
  117. // 广告形式
  118. var arr = document.getElementsByName("form");
  119. var form = "";var formCount = 0;
  120. for (i=0; i<arr.length; i++){
  121. if (arr[i].checked){
  122. form += ("," + arr[i].value);
  123. formCount += 1;
  124. }
  125. }
  126. if (formCount < 1){
  127. top.alert("请选择广告形式");
  128. return false;
  129. }
  130. data.form = form.substring(1,form.length);
  131. if (data['type'].isEmpty()){
  132. alert("请选择节目类型。");
  133. return false;
  134. }
  135. if (data['brand'].isEmpty()){
  136. alert("请选择品牌。");
  137. return false;
  138. }
  139. if (data['model'].isEmpty()){
  140. alert("请选择产品型号。");
  141. return false;
  142. }
  143. if (data['programName'].isEmpty()){
  144. alert("请选择节目。");
  145. return false;
  146. }
  147. if (data['type'] == 1 || data['type'] == 2){
  148. if (data['showYear'].isEmpty()){
  149. alert("请选择年份/季。");
  150. return false;
  151. }
  152. if (data['showPhase'].isEmpty()){
  153. alert("请选择期数。");
  154. return false;
  155. }
  156. if (data['form'].isEmpty()){
  157. alert("请选择广告形式。");
  158. return false;
  159. }
  160. }
  161. if (data['type'] == 3){
  162. if (data['episode'].isEmpty()){
  163. alert("请选择集数。");
  164. return false;
  165. }
  166. data['form'] = "";
  167. }
  168. if (data['type'] == 4){
  169. data['form'] = "";
  170. }
  171. /* 得到子关联信息(具体植入方式) */
  172. data.sonJsonStr = [];
  173. $(".table>tbody>tr").each(function(){
  174. var obj = {};
  175. obj.mode = $(this).attr("data-mode");;// 广告植入方式
  176. obj.imgUrls = $(this).attr("data-img");// 植入截图
  177. obj.frequency = $(this).attr("data-frequency");// 频次
  178. obj.length = $(this).attr("data-length");// 时长
  179. obj.slogan = $(this).attr("data-slogan");// 广告语
  180. if(obj.mode.isEmpty()){
  181. return false;
  182. }else{
  183. data.sonJsonStr.push(obj);
  184. }
  185. });
  186. // 数组转json字符串
  187. data.sonJsonStr = ObjectArrayToJsonString(data.sonJsonStr);
  188. ajax("save_brand_placement.do", data, function(res){
  189. if (res.code == 1){
  190. alert("保存成功。", 1, function(){
  191. window.location.href = "brand_placement.do";
  192. });
  193. } else {
  194. alert(res.msg);
  195. }
  196. });
  197. }
  198. // “品牌”下拉值变动:获取产品型号
  199. function onchangeByBrand(model){
  200. var html = "", brand = $("select[name='brand']>option:selected").val();
  201. if(brand.isEmpty()){
  202. return false;
  203. }
  204. ajax({url:"ajax_model_by_brand.do",data:{"q":brand},callBack:function(res){
  205. if(res.list.length > 0){
  206. $.each(res.list,function(index, item){
  207. html+='<option value="'+item.model+'" '+(item.model == model ? " selected":"")+'>'+item.model+'</option>';
  208. });
  209. $("select[name='model']").html(html);
  210. $(".select").uiSelect();
  211. }
  212. },load:false});
  213. }
  214. // “节目名称”下拉值变动:获取“年份/季” or “集数”
  215. function onchangeByProgramName(showYear,episode){
  216. var html = "", programName = $("select[name='programName']>option:selected").val();
  217. var typeParame = 2, type = $("input[name='type']:checked").val();
  218. if(programName.isEmpty()){
  219. return false;
  220. }
  221. // 该参数默认为2,如果节目类型是电视剧,则为4
  222. if(type == 3){
  223. typeParame = 4;
  224. }
  225. ajax({url:"ajax_program_info.do",data:{"type":typeParame,"programName":programName},callBack:function(res){
  226. if(res.list.length > 0){
  227. if (type == 1 || type == 2){
  228. // 综艺or栏目(修改年份下拉)
  229. $.each(res.list, function(index, item){
  230. html += '<option value="'+item.showYear+'" '+(item.showYear == showYear ? " selected":"")+'>'+item.showYear+'</option>';
  231. });
  232. $("select[name='showYear']").html(html);
  233. } else if (type == 3){
  234. // 电视剧(修改集数下拉)
  235. $.each(res.list, function(index, item){
  236. html += '<option value="'+item.episode+'" '+(item.episode == episode ? " selected":"")+'>'+item.episode+'</option>';
  237. });
  238. $("select[name='episode']").html(html);
  239. } else {
  240. $.each(res.list, function(){
  241. html += '<option value=""></option>';
  242. });
  243. }
  244. }else{
  245. $("#showYear").html('<option value="">年份/季</option>');// 年份
  246. $("#showPhase").html('<option value="">期数</option>');// 期数
  247. $("#episode").html('<option value="">请选择集数</option>');// 集数
  248. }
  249. $(".select").uiSelect();
  250. },load:false});
  251. }
  252. // “节目年份”下拉值变动:获取期数
  253. function onchangeByShowYear(showPhase){
  254. var html = "", programName = $("select[name='programName']>option:selected").val();
  255. var showYear = $("select[name='showYear']>option:selected").val();
  256. if(programName.isEmpty() || showYear.isEmpty()){
  257. return false;
  258. }
  259. ajax({url:"ajax_program_info.do",data:{"type":3,"programName":programName,"showYear":showYear},callBack:function(res){
  260. if(res.list.length > 0){
  261. $.each(res.list,function(index, item){
  262. html+='<option value="'+item.showPhase+'" '+(item.showPhase == showPhase ? " selected":"")+'>'+item.showPhase+'</option>';
  263. });
  264. $("select[name='showPhase']").html(html);
  265. }else{
  266. $("#showPhase").html('<option value="">期数</option>');// 期数
  267. }
  268. $(".select").uiSelect();
  269. },load:false});
  270. }
  271. // to 列表页子弹窗
  272. function placementModfiyOnList(act, title, id){
  273. title = title || "";
  274. id = id || "";
  275. $.openWindow(act.decode("add","新增","edit","修改","")+title, "brand_placement_box.do?id="+id, 500, 470, true);
  276. }
  277. // to 详情页子弹窗
  278. function placementModfiy(act, title, id, index){
  279. // title = title || "广告属性";
  280. title = "广告属性";
  281. id = id || "";
  282. index = index == undefined ? -1 : index;
  283. var type = $("input[name='type']:checked").val(), modeType = 1;
  284. // modeType 植入方式的所属类型(1综艺、栏目,2电视剧、电影)
  285. if (type == 3 || type == 4){
  286. modeType = 2;
  287. title = "植入方式";
  288. }
  289. $.openWindow(act.decode("add","新增","edit","修改","")+title, "brand_placement_info_box.do?act="+act+"&id="+id+"&modeType="+modeType+'&index='+index, 540, 460, true);
  290. }
  291. // 将 box 页面中的数据提交到 info 页面
  292. function saveInfoBox(){
  293. var data = $('#saveInfoFrm').serializeJSON(), imgs = [], table = top.$(".table>tbody>tr"), html = "", index = $.getParam("index");
  294. $("#imgShow .img").each(function(){
  295. imgs.push($(this).prop("href"));
  296. });
  297. data['modeName'] = $("input[name='mode']:checked").next("label").text();
  298. data['img'] = imgs.join(";");
  299. data['id'] = $.getParam("id");
  300. data['act'] = $.getParam("act");
  301. data['modeType'] = $.getParam("modeType");
  302. data['slogan'] = data['slogan'] || "";
  303. html = '<tr data-id="'+data.id+'" data-mode="'+data.mode+'" data-img="'+data.img+'" data-slogan="'+data.slogan+'" data-frequency="'+data.frequency+'" data-length="'+data.length+'">\n\
  304. <td>'+data.modeName+'</td>\n\
  305. <td class="nop">'+(imgs.length > 0 ? '<img src="'+imgs[0]+'" width="98" height="58" valign="middle" />':'')+'</td>\n\
  306. '+(data.modeType == 1 ? "<td>"+data.slogan+"</td>":"")+'\n\
  307. <td>'+data.frequency+'</td>\n\
  308. <td>'+data.length+'</td>\n\
  309. <td class="edit">\n\
  310. <a href="javascript:placementModfiy(\'edit\',\'植入方式\',\''+data.id+'\','+(data['act'] == "edit" ? $.getParam("index") : table.length)+');">编辑</a>&nbsp;&nbsp;\n\
  311. <a class="del">删除</a>\n\
  312. </td>\n\
  313. </tr>';
  314. if(data['act'] == "edit"){
  315. table.eq(index).replaceWith(html);
  316. }else{
  317. top.$(".table>tbody").append(html);
  318. }
  319. top.$.closeWindow();
  320. }
  321. function delImg(obj){
  322. $(obj).closest("li").remove();
  323. }
  324. function setDefaultData(){
  325. var index = $.getParam("index"), table = top.$(".table>tbody>tr").eq(index), html = "", data = {};
  326. if(index != -1){
  327. data.id = table.data("id");
  328. data.mode = table.data("mode");
  329. data.img = table.data("img");
  330. data.slogan = table.data("slogan");
  331. data.frequency = table.data("frequency");
  332. data.length = table.data("length");
  333. $("input[name='mode']").each(function(){
  334. if($(this).val() == data.mode){
  335. $(this).prop("checked",true);
  336. }
  337. });
  338. $.radio();
  339. if(!data.img.isEmpty()){
  340. data.img = data.img.split(";");
  341. $.each(data.img,function(i,item){
  342. html+='<li><a href="javascript:void(0);" class="del" onclick="delImg(this);"></a><a href="'+item+'" class="img" style="background-image:url('+item+');"></a></li>';
  343. });
  344. $("#imgShow").html(html);
  345. }
  346. $("input[name='slogan']").val(data.slogan);
  347. $("input[name='frequency']").val(data.frequency);
  348. $("input[name='length']").val(data.length);
  349. $(".lInput").hide();
  350. }
  351. }
  352. // 切换节目类型
  353. function brandType(obj){
  354. var val = $(obj).val(), th = $(".table>thead>tr>th"), td = $(".table>tbody>tr");
  355. // 1.修改"节目名称"下拉项
  356. $("#programName").empty();
  357. ajax("ajax_programname_list.do", {"type" : val}, function(res){
  358. $("#programName").append('<option value="">请选择节目</option>');
  359. if (res.code == 1 && res.list.length > 0){
  360. $.each(res.list, function(index, item){
  361. $("#programName").append('<option value="'+item.programName+'">'+item.programName+'</option>');
  362. });
  363. }
  364. $("#episode").html('<option value="">请选择集数</option>');// 集数
  365. $("#showYear").html('<option value="">年份/季</option>');// 年份
  366. $("#showPhase").html('<option value="">期数</option>');// 期数
  367. $(".select").uiSelect();
  368. },false);
  369. // 2.其他
  370. switch(parseInt(val)){
  371. case 3:
  372. $(".column").addClass("contentTxt");// "广告形式"的显示/隐藏
  373. $(".tv").removeClass("contentTxt");
  374. th.eq(0).text("植入方式");// 表格表头文字(广告属性/植入方式)
  375. th.eq(1).text("植入截图");// 表格表头文字(广告创意/植入截图)
  376. // 表格->"广告语"的显示/隐藏
  377. th.eq(2).hide();
  378. td.each(function(){
  379. $(this).find("td").eq(2).hide();
  380. }).eq(2).show();
  381. break;
  382. case 4:
  383. $(".column, .tv").addClass("contentTxt");
  384. th.eq(0).text("植入方式");
  385. th.eq(1).text("植入截图");
  386. th.eq(2).hide();
  387. td.each(function(){
  388. $(this).find("td").eq(2).hide();
  389. }).eq(2).show();
  390. break;
  391. default:
  392. $(".tv").addClass("contentTxt");
  393. $(".column").removeClass("contentTxt");
  394. th.eq(0).text("广告属性");
  395. th.eq(1).text("广告创意");
  396. th.eq(2).show();
  397. td.each(function(){
  398. $(this).find("td").eq(2).show();
  399. }).eq(2).show();
  400. break;
  401. }
  402. }
  403. //导入表格数据
  404. function importExcel(obj){
  405. $("#fileForm").submit();
  406. }
  407. // 导入视频
  408. function updVideo(){
  409. $("#updVideo").submit();
  410. }
  411. // 导入结果
  412. function excelCallback(code, msg) {
  413. if (code == 1) {
  414. // 导入成功
  415. alert("导入成功。", 1, function(){
  416. window.location.href = "brand_placement.do";
  417. });
  418. } else {
  419. // 导入失败
  420. alert(msg, 0, function(){
  421. location.reload();
  422. });
  423. }
  424. }