adplatform.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // 一级行业select控件初始化
  2. var firstIndSelect = $('select[name="firstInd"]').select2({
  3. placeholder: "请输入一级行业",
  4. allowClear: true,
  5. width:'120px',
  6. ajax:{
  7. url: _PUBLIC_ +'ad-select/top_category_by_type.do',
  8. dataType:'json',
  9. quietMillis:100,
  10. data:function(params){
  11. return {
  12. name : params.term,
  13. type : 0, //栏目管理
  14. pageNo : params.page || 1,
  15. pageSize : 20
  16. }
  17. },
  18. processResults: function (data, params) {
  19. params.page = params.page || 1;
  20. return {
  21. results: data.results,
  22. pagination: {
  23. more: (params.page * 20) < data.total
  24. }
  25. };
  26. },
  27. cache: true
  28. }
  29. });
  30. //解绑二级行业select控件初始化
  31. $('select[name="firstInd"]').live('change',function(){
  32. $('select[name="secondInd"]').html('<option value=""></option>');
  33. });
  34. // 二级行业select控件初始化
  35. var secondIndSelect = $('select[name="secondInd"]').select2({
  36. placeholder: "请输入二级行业",
  37. allowClear: true,
  38. width:'120px',
  39. ajax:{
  40. url: _PUBLIC_ +'ad-select/second_category_by_type.do',
  41. dataType:'json',
  42. quietMillis:100,
  43. data:function(params){
  44. return {
  45. name : params.term,
  46. type : 0, //栏目管理,
  47. parentName : $('#firstInd').val(),
  48. pageNo : params.page || 1,
  49. pageSize : 20
  50. }
  51. },
  52. processResults: function (data, params) {
  53. params.page = params.page || 1;
  54. return {
  55. results: data.results,
  56. pagination: {
  57. more: (params.page * 20) < data.total
  58. }
  59. };
  60. },
  61. cache: true
  62. }
  63. });
  64. // 获取表格数据
  65. function getList(page){
  66. page = page || 1;
  67. var pageSize = 10, data = {
  68. "platformName" : $("#platformName").val(),
  69. "firstInd" : $("#firstInd").val(),
  70. "secondInd" : $("#secondInd").val(),
  71. "pageNo" : page,
  72. "pageSize" : pageSize
  73. }, html = "";
  74. $("#page, #list").empty();
  75. ajax("ajax_list.do", data, function(res){
  76. if (res.code == 1 && res.list.records.length > 0){
  77. $.each(res.list.records, function(index, item){
  78. html += '<tr>'+
  79. '<td><input type="checkbox" class="checkbox {click:itemCheck}" name="chk" value="'+item.id+'" /><label></label></td>'+
  80. '<td>'+ (item.platformName == undefined || item.platformName == null ? '' : item.platformName ) +'</td>'+
  81. '<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>'+
  82. '<td>'+ (item.firstInd == undefined || item.firstInd == null ? '' : item.firstInd ) +'</td>'+
  83. '<td>'+ (item.secondInd == undefined || item.secondInd == null ? '' : item.secondInd ) +'</td>'+
  84. '<td class="edit">'+
  85. (update_flag == 1 ? '<a href="javascript:platformModfiy(\'edit\',\'栏目信息\','+item.id+');">编辑</a>&nbsp;&nbsp;' : '') +
  86. (delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '' ) +
  87. '</td>'+
  88. '</tr>';
  89. });
  90. $("#list").html(html);
  91. $.checkbox();
  92. $("#count").text(res.list.total);
  93. var newpage = new createPage(res.list.total, page, pageSize, 3);
  94. $("#page").html(newpage.pageHtml);
  95. } else {
  96. $("#list").info("暂无数据。");
  97. $("#count").text(0);
  98. }
  99. });
  100. }
  101. pageGo = function(page){
  102. resetCheckAll();
  103. getList(page);
  104. }
  105. // 删除单个
  106. function delRecord(id){
  107. confirm("确定删除该条记录吗?", function(){
  108. ajax("del.do", {"id" : id}, function(res){
  109. if (res.code == 1){
  110. alert("删除成功。", 1, function(){
  111. window.location.href = "index.do";
  112. });
  113. } else {
  114. alert(res.msg);
  115. }
  116. });
  117. });
  118. }
  119. // 删除多个
  120. function delRecordBatch(){
  121. var arr = document.getElementsByName("chk");
  122. var ids = "";
  123. for (i=0; i<arr.length; i++){
  124. if (arr[i].checked){
  125. ids += ("," + arr[i].value);
  126. }
  127. }
  128. if (ids.isEmpty()){
  129. alert("请至少选择一条记录");
  130. return false;
  131. }
  132. confirm("确定删除这些记录吗?", function(){
  133. ajax("batch_del.do", {"ids" : ids.substring(1,ids.length)}, function(res){
  134. if (res.code == 1){
  135. alert("删除成功。", 1, function(){
  136. window.location.href = "index.do";
  137. });
  138. } else {
  139. alert(res.msg);
  140. }
  141. });
  142. });
  143. }
  144. // 导入表格数据
  145. function importExcel(obj){
  146. $("#fileForm").submit();
  147. }
  148. // 导入结果
  149. function excelCallback(code, msg) {
  150. if (code == 1) {
  151. // 导入成功
  152. alert("导入成功。", 1, function(){
  153. window.location.href = "index.do";
  154. });
  155. } else {
  156. // 导入失败
  157. alert(msg, 0, function(){
  158. location.reload();
  159. });
  160. }
  161. }
  162. // 保存品牌型号信息
  163. function save(){
  164. // 得到数据
  165. var data = $('#dataForm').serializeJSON();
  166. data.id = $.getParam("id");
  167. data.imgUrl = $("#imgUrl")[0].src;
  168. // 数据是否完整
  169. if (data['platformName'].isEmpty()){
  170. top.alert("请填写栏目名称", 0, function(){
  171. $("input[name='platformName']").focus();
  172. });
  173. return false;
  174. }
  175. if (data['imgUrl'].isEmpty() || data['imgUrl'].indexOf("ylcm_sys") > 1){
  176. top.alert("请上传栏目LOGO");
  177. return false;
  178. }
  179. if (data['firstInd'].isEmpty()){
  180. top.alert("请选择一级行业");
  181. return false;
  182. }
  183. if (data['secondInd'].isEmpty()){
  184. top.alert("请选择二级行业");
  185. return false;
  186. }
  187. // 提交数据
  188. top.ajax("save.do", data, function(res){
  189. if (res.code == 1){
  190. top.alert("保存成功。", 1, function(){
  191. top.getList(1);
  192. top.$.closeWindow();
  193. });
  194. } else {
  195. top.alert(res.msg);
  196. }
  197. });
  198. }
  199. // 弹窗
  200. function platformModfiy(act, title, id){
  201. title = title || "";
  202. id = id || "";
  203. $.openWindow(act.decode("add","新增","edit","修改","")+title, "detail.do?id="+id, 500, 370, true);
  204. }