resource_recom.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // 获取表格数据
  2. function getList(page){
  3. page = page || 1;
  4. var resourceType = $("#resourceType option:selected").val();
  5. var status = $("#status option:selected").val();
  6. var pageSize = 10, data = {
  7. "resourceName" : $("#resourceName").val(),
  8. "resourceType" : ( resourceType == "" ? "" : resourceType),
  9. "status" : ( status == "" ? "" : status),
  10. "pageNo" : page,
  11. "pageSize" : pageSize
  12. }, html = "";
  13. $("#page, #list,#count").empty();
  14. ajax("ajax_resource_recom_list.do", data, function(res){
  15. if (res.code == 1 && res.list.length > 0){
  16. $.each(res.list, function(index, item){
  17. html += '<tr>'+
  18. '<td><input type="checkbox" class="checkbox {click:itemCheck}" name="chk" value="'+item.id+'" /><label></label></td>'+
  19. '<td>'+item.resourceName+'</td>'+
  20. '<td>'+
  21. (item.resourceType == 1 ? "电视节目" :item.resourceType == 2 ? "电视硬广" :
  22. item.resourceType == 3 ? "网络长视频" : item.resourceType == 4 ? "网络短视频" :
  23. item.resourceType == 5 ? "APP" :"未知类型") +
  24. '</td>'+
  25. '<td>'+item.platform+'</td>'+
  26. '<td class="nop">'+(item.imgUrl ? '<img id="'+item.imgUrl+'" src="'+item.imgUrl.toNull()+'" onclick="showimg(\''+item.imgUrl+'\')" width="98" height="58" valign="middle" onerror="this.src=\'static/img/noimg.jpg\';" />':'&nbsp;')+'</td>'+
  27. '<td>'+(item.recomType == 1 ? "头部轮播区" : item.recomType == 2 ? "非头部" : "未知")+'</td>'+
  28. '<td>'+item.rank+'</td>'+
  29. '<td>'+(item.status == 2 ? "已显示" : item.status == 0 ? "已隐藏" : "未知")+'</td>'+
  30. '<td class="edit">'+
  31. (update_status_flag == 1 ?
  32. (item.status==2 ? '<a href="javascript:setStatus('+item.id+');">设为隐藏</a><br />' :
  33. item.status==0 ? '<a href="javascript:setStatus('+item.id+');">设为显示</a><br />' : '' ):'<br />') +
  34. (update_flag == 1 ? '<a href="javascript:platformModfiy(\'edit\',\'资源推荐\','+item.id+');">编辑</a>&nbsp;&nbsp;' : '<br />') +
  35. (delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '<br />' ) +
  36. '</td>'+
  37. '</tr>';
  38. });
  39. $("#list").html(html);
  40. $.checkbox();
  41. $("#count").text(res.count);
  42. $("#curPage").val(page);
  43. var newpage = new createPage(res.count, page, pageSize, 3);
  44. $("#page").html(newpage.pageHtml);
  45. } else {
  46. $("#list").info("暂无数据。");
  47. }
  48. });
  49. }
  50. pageGo = getList
  51. // 删除单个
  52. function delRecord(id){
  53. confirm("确定删除该条记录吗?", function(){
  54. ajax("delete_resource_recom.do", {"id" : id}, function(res){
  55. if (res.code == 1){
  56. alert("删除成功。", 1, function(){
  57. window.location.href = "resource_recom_list.do";
  58. });
  59. } else {
  60. alert(res.msg);
  61. }
  62. });
  63. });
  64. }
  65. // 删除多个
  66. function delRecordBatch(){
  67. var arr = document.getElementsByName("chk");
  68. var ids = "";
  69. for (i=0; i<arr.length; i++){
  70. if (arr[i].checked){
  71. ids += ("," + arr[i].value);
  72. }
  73. }
  74. if (ids.isEmpty()){
  75. alert("请至少选择一条记录");
  76. return false;
  77. }
  78. confirm("确定删除这些记录吗?", function(){
  79. ajax("batch_del_for_resource_recom.do", {"ids" : ids.substring(1,ids.length)}, function(res){
  80. if (res.code == 1){
  81. alert("删除成功。", 1, function(){
  82. window.location.href = "resource_recom_list.do";
  83. });
  84. } else {
  85. alert(res.msg);
  86. }
  87. });
  88. });
  89. }
  90. // 保存资源信息
  91. function save(){
  92. // 得到数据
  93. var data = $('#dataForm').serializeJSON();
  94. data.id = $.getParam("id");
  95. data.resourceType = $("select[name='resourceType']>option:selected").val();
  96. data.imgUrl = $("#imgUrl")[0].src;
  97. console.log(data);
  98. // 数据是否完整
  99. if (data['resourceType'].isEmpty()){
  100. top.alert("请选择资源类型", 0, function(){
  101. $("input[name='resourceType']").focus();
  102. });
  103. return false;
  104. }
  105. if (data['imgUrl'].isEmpty() || data['imgUrl'].indexOf("ylcm_sys") > 1){
  106. top.alert("请上传推荐图");
  107. return false;
  108. }
  109. if (data['resourceName'].isEmpty()){
  110. top.alert("请填写资源名称", 0, function(){
  111. $("input[name='resourceName']").focus();
  112. });
  113. return false;
  114. }
  115. if (data['rank'].isEmpty()){
  116. top.alert("请填写推荐顺序", 0, function(){
  117. $("input[name='rank']").focus();
  118. });
  119. return false;
  120. }
  121. if (data['platform'].isEmpty()){
  122. top.alert("请填写播出频道", 0, function(){
  123. $("input[name='platform']").focus();
  124. });
  125. return false;
  126. }
  127. if (data['recomType'].isEmpty()){
  128. top.alert("请选择投放类型");
  129. return false;
  130. }
  131. // 提交数据
  132. top.ajax("save_resource_recom_info.do", data, function(res){
  133. if (res.code == 1){
  134. top.alert("保存成功。", 1, function(){
  135. top.getList(1);
  136. top.$.closeWindow();
  137. });
  138. } else {
  139. top.alert(res.msg);
  140. }
  141. });
  142. }
  143. // 弹窗
  144. function platformModfiy(act, title, id){
  145. title = title || "";
  146. id = id || "";
  147. $.openWindow(act.decode("add","新增","edit","修改","")+title, "resource_recom_info.do?id="+id, 500, 470, true);
  148. }
  149. function setStatus(id){
  150. var page = $("#curPage").val();
  151. confirm("确定更改状态吗?", function(){
  152. $.post("update_resource_recom_status.do", {"id" : id}, function(res){
  153. if (res.code == 1){
  154. alert("更改成功。", 1, function(){
  155. top.getList(page);
  156. });
  157. } else {
  158. alert(res.msg);
  159. }
  160. });
  161. });
  162. }
  163. function showimg(imgurl){
  164. var url = document.getElementById(imgurl).src;
  165. if(url!='' && url!='http://localhost:8080/ylcm_sys/static/img/noimg.jpg'){
  166. var html = '<img src='+url+' width="480px" height="380px" />';
  167. $.openWindow(" ",html,500,380,false);
  168. }
  169. }