brand.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // 获取表格数据
  2. function getList(page){
  3. page = page || 1;
  4. var firstInd = $("#firstInd option:selected").text();
  5. var pageSize = 10, data = {
  6. "brand" : $("#brand").val(),
  7. "model" : $("#model").val(),
  8. "advertiser" : $("#advertiser").val(),
  9. "firstInd" : ( firstInd == "一级行业" ? "" : firstInd),
  10. "secondInd" : $("#secondInd option:selected").val(),
  11. "pageNo" : page,
  12. "pageSize" : pageSize
  13. }, html = "";
  14. $("#page, #list").empty();
  15. ajax("ajax_brand_list.do", data, function(res){
  16. if (res.code == 1 && res.list.length > 0){
  17. $.each(res.list, function(index, item){
  18. html += '<tr>'+
  19. '<td><input type="checkbox" class="checkbox {click:itemCheck}" name="chk" value="'+item.id+'" /><label></label></td>'+
  20. '<td>'+item.model.toNull()+'</td>'+
  21. '<td class="nop">'+(item.modelImgUrl ? '<img src="'+item.modelImgUrl.toNull()+'" width="98" height="58" valign="middle" onerror="this.src=\'static/img/noimg.jpg\'"/>':'&nbsp;')+'</td>'+
  22. '<td>'+item.brand.toNull()+'</td>'+
  23. '<td class="nop">'+(item.brandImgUrl ? '<img src="'+item.brandImgUrl.toNull()+'" width="98" height="58" valign="middle" onerror="this.src=\'static/img/noimg.jpg\'"/>':'&nbsp;')+'</td>'+
  24. '<td>'+item.advertiser.toNull()+'</td>'+
  25. '<td>'+item.firstInd.toNull()+'</td>'+
  26. '<td>'+item.secondInd.toNull()+'</td>'+
  27. '<td class="edit">'+
  28. (update_flag == 1 ? '<a href="javascript:platformModfiy(\'edit\',\'品牌型号信息\','+item.id+');">编辑</a>&nbsp;&nbsp;' : '') +
  29. (delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '' ) +
  30. '</td>'+
  31. '</tr>';
  32. });
  33. $("#list").html(html);
  34. $.checkbox();
  35. $("#count").text(res.count);
  36. var newpage = new createPage(res.count, page, pageSize, 3);
  37. $("#page").html(newpage.pageHtml);
  38. } else {
  39. $("#list").info("暂无数据。");
  40. }
  41. });
  42. }
  43. pageGo = function(page){
  44. resetCheckAll();
  45. getList(page);
  46. }
  47. // 删除单个
  48. function delRecord(id){
  49. confirm("确定删除该条记录吗?", function(){
  50. ajax("del_brand.do", {"id" : id}, function(res){
  51. if (res.code == 1){
  52. alert("删除成功。", 1, function(){
  53. window.location.href = "brand_list.do";
  54. });
  55. } else {
  56. alert(res.msg);
  57. }
  58. });
  59. });
  60. }
  61. // 删除多个
  62. function delRecordBatch(){
  63. var arr = document.getElementsByName("chk");
  64. var ids = "";
  65. for (i=0; i<arr.length; i++){
  66. if (arr[i].checked){
  67. ids += ("," + arr[i].value);
  68. }
  69. }
  70. if (ids.isEmpty()){
  71. alert("请至少选择一条记录");
  72. return false;
  73. }
  74. confirm("确定删除这些记录吗?", function(){
  75. ajax("batch_del_for_brand.do", {"ids" : ids.substring(1,ids.length)}, function(res){
  76. if (res.code == 1){
  77. alert("删除成功。", 1, function(){
  78. window.location.href = "brand_list.do";
  79. });
  80. } else {
  81. alert(res.msg);
  82. }
  83. });
  84. });
  85. }
  86. // 导入表格数据
  87. function importExcel(obj){
  88. $("#fileForm").submit();
  89. }
  90. // 导入结果
  91. function excelCallback(code, msg) {
  92. if (code == 1) {
  93. // 导入成功
  94. alert("导入成功。", 1, function(){
  95. window.location.href = "brand_list.do";
  96. });
  97. } else {
  98. // 导入失败
  99. alert(msg, 0, function(){
  100. location.reload();
  101. });
  102. }
  103. }
  104. // 保存品牌型号信息
  105. function save(){
  106. // 得到数据
  107. var data = $('#dataForm').serializeJSON();
  108. data.id = $.getParam("id");
  109. data.firstInd = $("select[name='firstInd']>option:selected").text();
  110. data.modelImgUrl = $("#modelImgUrl")[0].src;
  111. data.brandImgUrl = $("#brandImgUrl")[0].src;
  112. console.log(data);
  113. // 数据是否完整
  114. if (data['model'].isEmpty()){
  115. top.alert("请填写产品型号", 0, function(){
  116. $("input[name='model']").focus();
  117. });
  118. return false;
  119. }
  120. if (data['modelImgUrl'].isEmpty() || data['modelImgUrl'].indexOf("ylcm_sys") > 1){
  121. top.alert("请上传产品LOGO");
  122. return false;
  123. }
  124. if (data['brand'].isEmpty()){
  125. top.alert("请填写所属品牌", 0, function(){
  126. $("input[name='brand']").focus();
  127. });
  128. return false;
  129. }
  130. if (data['brandImgUrl'].isEmpty() || data['brandImgUrl'].indexOf("ylcm_sys") > 1){
  131. top.alert("请上传品牌LOGO");
  132. return false;
  133. }
  134. if (data['advertiser'].isEmpty()){
  135. top.alert("请填写广告主", 0, function(){
  136. $("input[name='advertiser']").focus();
  137. });
  138. return false;
  139. }
  140. if (data['firstInd'].isEmpty() || data['firstInd'] == "下拉选择"){
  141. top.alert("请选择一级行业");
  142. return false;
  143. }
  144. if (data['secondInd'].isEmpty()){
  145. top.alert("请选择二级行业");
  146. return false;
  147. }
  148. // 提交数据
  149. top.ajax("save_brand_info.do", data, function(res){
  150. if (res.code == 1){
  151. top.alert("保存成功。", 1, function(){
  152. top.getList(1);
  153. top.$.closeWindow();
  154. });
  155. } else {
  156. top.alert(res.msg);
  157. }
  158. });
  159. }
  160. // 弹窗
  161. function platformModfiy(act, title, id){
  162. title = title || "";
  163. id = id || "";
  164. $.openWindow(act.decode("add","新增","edit","修改","")+title, "brand_info.do?id="+id, 500, 470, true);
  165. }
  166. // 切换,一级行业
  167. function onchangeByFirstInd(secondIndName){
  168. var html = "", number = $("select[name='firstInd']>option:selected").val();
  169. if(number.isEmpty()){
  170. html = '<option value="">二级行业</option>';
  171. $("select[name='secondInd']").html(html);
  172. $(".select").uiSelect();
  173. return false;
  174. }
  175. ajax({url:"ajax_brand_type.do",data:{"number":number},callBack:function(res){
  176. if(res.code == 1 && res.list.length > 0){
  177. $.each(res.list,function(index, item){
  178. html+='<option value="'+item.name+'" '+(item.name == secondIndName ? " selected":"")+'>'+item.name+'</option>';
  179. });
  180. $("select[name='secondInd']").html(html);
  181. $(".select").uiSelect();
  182. }
  183. },load:false});
  184. }