admedia.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // 获取表格数据
  2. function getList(page){
  3. page = page || 1;
  4. var pageSize = 10, data = {
  5. "name" : $("#name").val(),
  6. "rank" : $("#rank").val(),
  7. "pageNo" : page,
  8. "pageSize" : pageSize
  9. }, html = "";
  10. $("#page, #list").empty();
  11. ajax("ajax_list.do", data, function(res){
  12. if (res.code == 1 && res.list.records.length > 0){
  13. $.each(res.list.records, function(index, item){
  14. html += '<tr>'+
  15. '<td><input type="checkbox" class="checkbox {click:itemCheck}" name="chk" value="'+item.id+'" /><label></label></td>'+
  16. '<td>'+ (item.name == undefined || item.name == null ? '' : item.name ) +'</td>'+
  17. '<td>'+ (item.rankName == undefined || item.rankName == null ? '' : item.rankName ) +'</td>'+
  18. '<td class="nop">'+(item.imgUrl ? '<img src="'+item.imgUrl.toNull()+'" width="98" height="58" valign="middle" onerror="this.src=_PUBLIC_ + \'static/img/noimg.jpg\'"/>':'&nbsp;')+'</td>'+
  19. '<td class="edit">'+
  20. (update_flag == 1 ? '<a href="javascript:platformModfiy(\'edit\',\'品牌型号信息\','+item.id+');">编辑</a>&nbsp;&nbsp;' : '') +
  21. (delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '' ) +
  22. '</td>'+
  23. '</tr>';
  24. });
  25. $("#list").html(html);
  26. $.checkbox();
  27. $("#count").text(res.list.total);
  28. var newpage = new createPage(res.list.total, page, pageSize, 3);
  29. $("#page").html(newpage.pageHtml);
  30. } else {
  31. $("#list").info("暂无数据。");
  32. }
  33. });
  34. }
  35. pageGo = function(page){
  36. resetCheckAll();
  37. getList(page);
  38. }
  39. // 删除单个
  40. function delRecord(id){
  41. confirm("确定删除该条记录吗?", function(){
  42. ajax("del.do", {"id" : id}, function(res){
  43. if (res.code == 1){
  44. alert("删除成功。", 1, function(){
  45. window.location.href = "index.do";
  46. });
  47. } else {
  48. alert(res.msg);
  49. }
  50. });
  51. });
  52. }
  53. // 删除多个
  54. function delRecordBatch(){
  55. var arr = document.getElementsByName("chk");
  56. var ids = "";
  57. for (i=0; i<arr.length; i++){
  58. if (arr[i].checked){
  59. ids += ("," + arr[i].value);
  60. }
  61. }
  62. if (ids.isEmpty()){
  63. alert("请至少选择一条记录");
  64. return false;
  65. }
  66. confirm("确定删除这些记录吗?", function(){
  67. ajax("batch_del.do", {"ids" : ids.substring(1,ids.length)}, function(res){
  68. if (res.code == 1){
  69. alert("删除成功。", 1, function(){
  70. window.location.href = "index.do";
  71. });
  72. } else {
  73. alert(res.msg);
  74. }
  75. });
  76. });
  77. }
  78. // 导入表格数据
  79. function importExcel(obj){
  80. $("#fileForm").submit();
  81. }
  82. // 导入结果
  83. function excelCallback(code, msg) {
  84. if (code == 1) {
  85. // 导入成功
  86. alert("导入成功。", 1, function(){
  87. window.location.href = "index.do";
  88. });
  89. } else {
  90. // 导入失败
  91. alert(msg, 0, function(){
  92. location.reload();
  93. });
  94. }
  95. }
  96. // 保存品牌型号信息
  97. function save(){
  98. // 得到数据
  99. var data = $('#dataForm').serializeJSON();
  100. data.id = $.getParam("id");
  101. data.imgUrl = $("#imgUrl")[0].src;
  102. console.log(data);
  103. // 数据是否完整
  104. if (data['name'].isEmpty()){
  105. top.alert("请填写媒体名称", 0, function(){
  106. $("input[name='name']").focus();
  107. });
  108. return false;
  109. }
  110. if (data['imgUrl'].isEmpty() || data['imgUrl'].indexOf("ylcm_sys") > 1){
  111. top.alert("请上传媒体LOGO");
  112. return false;
  113. }
  114. if (data['rank'].isEmpty()){
  115. top.alert("请选择媒体等级");
  116. return false;
  117. }
  118. // 提交数据
  119. top.ajax("save.do", data, function(res){
  120. if (res.code == 1){
  121. top.alert("保存成功。", 1, function(){
  122. top.getList(1);
  123. top.$.closeWindow();
  124. });
  125. } else {
  126. top.alert(res.msg);
  127. }
  128. });
  129. }
  130. // 弹窗
  131. function platformModfiy(act, title, id){
  132. title = title || "";
  133. id = id || "";
  134. $.openWindow(act.decode("add","新增","edit","修改","")+title, "detail.do?id="+id, 500, 370, true);
  135. }