adproduct.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. "productName" : $("#productName").val(),
  69. "brandName" : $("#brandName").val(),
  70. "firstInd" : $("#firstInd").val(),
  71. "secondInd" : $("#secondInd").val(),
  72. "pageNo" : page,
  73. "pageSize" : pageSize
  74. }, html = "";
  75. $("#page, #list").empty();
  76. ajax("ajax_list.do", data, function(res){
  77. if (res.code == 1 && res.list.records.length > 0){
  78. $.each(res.list.records, function(index, item){
  79. html += '<tr>'+
  80. '<td><input type="checkbox" class="checkbox {click:itemCheck}" name="chk" value="'+item.id+'" /><label></label></td>'+
  81. '<td>'+ (item.productName == undefined || item.productName == null ? '' : item.productName)+'</td>'+
  82. '<td class="nop">'+(item.nameImgUrl ? '<img src="'+item.nameImgUrl.toNull()+'" width="98" height="58" valign="middle" onerror="this.src=_PUBLIC_ + \'static/img/noimg.jpg\'"/>':'&nbsp;')+'</td>'+
  83. '<td>'+ (item.brandName == undefined || item.brandName == null ? '' : item.brandName)+'</td>'+
  84. '<td>'+ (item.firstInd == undefined || item.firstInd == null ? '' : item.firstInd ) +'</td>'+
  85. '<td>'+ (item.secondInd == undefined || item.secondInd == null ? '' : item.secondInd ) +'</td>'+
  86. '<td class="edit">'+
  87. (update_flag == 1 ? '<a href="javascript:platformModfiy(\'edit\',\'产品信息\','+item.id+');">编辑</a>&nbsp;&nbsp;' : '') +
  88. (delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '' ) +
  89. '</td>'+
  90. '</tr>';
  91. });
  92. $("#list").html(html);
  93. $.checkbox();
  94. $("#count").text(res.list.total);
  95. var newpage = new createPage(res.list.total, page, pageSize, 3);
  96. $("#page").html(newpage.pageHtml);
  97. } else {
  98. $("#list").info("暂无数据。");
  99. $("#count").text(0);
  100. }
  101. });
  102. }
  103. pageGo = function(page){
  104. resetCheckAll();
  105. getList(page);
  106. }
  107. // 删除单个
  108. function delRecord(id){
  109. confirm("确定删除该条记录吗?", function(){
  110. ajax("del.do", {"id" : id}, function(res){
  111. if (res.code == 1){
  112. alert("删除成功。", 1, function(){
  113. window.location.href = "index.do";
  114. });
  115. } else {
  116. alert(res.msg);
  117. }
  118. });
  119. });
  120. }
  121. // 删除多个
  122. function delRecordBatch(){
  123. var arr = document.getElementsByName("chk");
  124. var ids = "";
  125. for (i=0; i<arr.length; i++){
  126. if (arr[i].checked){
  127. ids += ("," + arr[i].value);
  128. }
  129. }
  130. if (ids.isEmpty()){
  131. alert("请至少选择一条记录");
  132. return false;
  133. }
  134. confirm("确定删除这些记录吗?", function(){
  135. ajax("batch_del.do", {"ids" : ids.substring(1,ids.length)}, function(res){
  136. if (res.code == 1){
  137. alert("删除成功。", 1, function(){
  138. window.location.href = "index.do";
  139. });
  140. } else {
  141. alert(res.msg);
  142. }
  143. });
  144. });
  145. }
  146. // 导入表格数据
  147. function importExcel(obj){
  148. $("#fileForm").submit();
  149. }
  150. // 导入结果
  151. function excelCallback(code, msg) {
  152. if (code == 1) {
  153. // 导入成功
  154. alert("导入成功。", 1, function(){
  155. window.location.href = "index.do";
  156. });
  157. } else {
  158. // 导入失败
  159. alert(msg, 0, function(){
  160. location.reload();
  161. });
  162. }
  163. }
  164. // 保存品牌型号信息
  165. function save(){
  166. // 得到数据
  167. var data = $('#dataForm').serializeJSON();
  168. data.id = $.getParam("id");
  169. data.nameImgUrl = $("#imgUrl")[0].src;
  170. // 数据是否完整
  171. if (data['productName'].isEmpty()){
  172. top.alert("请填写产品名称", 0, function(){
  173. $("input[name='productName']").focus();
  174. });
  175. return false;
  176. }
  177. if (data['brandName'].isEmpty()){
  178. top.alert("请填写产品品牌", 0, function(){
  179. $("input[name='brandName']").focus();
  180. });
  181. return false;
  182. }
  183. if (data['nameImgUrl'].isEmpty() || data['nameImgUrl'].indexOf("ylcm_sys") > 1){
  184. top.alert("请上传产品LOGO");
  185. return false;
  186. }
  187. if (data['firstInd'].isEmpty()){
  188. top.alert("请选择一级行业");
  189. return false;
  190. }
  191. if (data['secondInd'].isEmpty()){
  192. top.alert("请选择二级行业");
  193. return false;
  194. }
  195. // 提交数据
  196. top.ajax("save.do", data, function(res){
  197. if (res.code == 1){
  198. top.alert("保存成功。", 1, function(){
  199. top.getList(1);
  200. top.$.closeWindow();
  201. });
  202. } else {
  203. top.alert(res.msg);
  204. }
  205. });
  206. }
  207. // 弹窗
  208. function platformModfiy(act, title, id){
  209. title = title || "";
  210. id = id || "";
  211. $.openWindow(act.decode("add","新增","edit","修改","")+title, "detail.do?id="+id, 500, 370, true);
  212. }