activityMessagepush_add.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. var selectedObj, StreetIds = '', BuildIds = '', CompanyIds = '', Names = '';
  2. $('input[name="streetAll"]').click(function () {
  3. //alert(this.checked);
  4. if ($(this).is(':checked')) {
  5. $('input[name="street"]').each(function () {
  6. //此处如果用attr,会出现第三次失效的情况
  7. $(this).prop("checked", true);
  8. });
  9. } else {
  10. $('input[name="street"]').each(function () {
  11. $(this).removeAttr("checked", false);
  12. });
  13. //$(this).removeAttr("checked");
  14. }
  15. });
  16. $('input[name="buildAll"]').click(function () {
  17. //alert(this.checked);
  18. if ($(this).is(':checked')) {
  19. $('input[name="build"]').each(function () {
  20. //此处如果用attr,会出现第三次失效的情况
  21. $(this).prop("checked", true);
  22. });
  23. } else {
  24. $('input[name="build"]').each(function () {
  25. $(this).removeAttr("checked", false);
  26. });
  27. //$(this).removeAttr("checked");
  28. }
  29. });
  30. $('input[name="companyAll"]').click(function () {
  31. //alert(this.checked);
  32. if ($(this).is(':checked')) {
  33. $('input[name="company"]').each(function () {
  34. //此处如果用attr,会出现第三次失效的情况
  35. $(this).prop("checked", true);
  36. });
  37. } else {
  38. $('input[name="company"]').each(function () {
  39. $(this).removeAttr("checked", false);
  40. });
  41. //$(this).removeAttr("checked");
  42. }
  43. });
  44. $("#type_id").change(function () {
  45. getCompanys();
  46. checkIds();
  47. });
  48. function getBuilds() {
  49. var ids = new Array();
  50. $("input:checkbox[name='street']:checked").each(function (i) {
  51. var val = $(this).val() + ',';
  52. ids += val;
  53. });
  54. if (ids.length > 0) {
  55. $.ajax({
  56. url: pagePath + "/government/activity/getBuildsByStreetIds",
  57. type: "post",
  58. data: {
  59. 'streetIds': ids
  60. },
  61. dataType: "json",
  62. success: function (result) {
  63. if (result.success) {
  64. bindBuild(result.obj);
  65. } else {
  66. errorMessage(result.message);
  67. }
  68. },
  69. error: function () {
  70. errorMessage('系统错误!');
  71. }
  72. });
  73. } else {
  74. $(".buildList").empty();
  75. }
  76. }
  77. function bindStreet(streetList) {
  78. $(".streetListPre").empty();
  79. $(".streetListPre").append('<ul class="streetList"></ul>');
  80. $(".streetList").empty();
  81. var str = '';
  82. for (var i = 0; i < streetList.length; i++) {
  83. str += '<li>';
  84. str += '<input type="checkbox" value="' + streetList[i].id + '" id="' + streetList[i].id + '" name="street" streetName="' + streetList[i].name + '" onchange="setTimeout(function(){getCompanys();checkIds()},200);">';
  85. str += '<span>' + streetList[i].name + '</span>';
  86. str += '</li>';
  87. }
  88. $(".streetList").append(str);
  89. }
  90. function bindBuild(buildList) {
  91. $(".buildList").empty();
  92. var str = '';
  93. for (var i = 0; i < buildList.length; i++) {
  94. str += '<li>';
  95. str += '<input type="checkbox" value="' + buildList[i].id + '" id="' + buildList[i].id + '" name="build" buildName="' + buildList[i].name + '" onchange="setTimeout(function(){getCompanys();checkIds()},200);">';
  96. str += '<span>' + buildList[i].name + '</span>';
  97. str += '</li>';
  98. }
  99. $(".buildList").append(str);
  100. }
  101. function getCompanys() {
  102. var ids = new Array();
  103. $("input:checkbox[name='build']:checked").each(function (i) {
  104. var val = $(this).val() + ',';
  105. ids += val;
  106. });
  107. if (ids.length > 0) {
  108. $.ajax({
  109. url: pagePath + "/government/activity/getCompanysByBuildIds",
  110. type: "post",
  111. data: {
  112. 'buildIds': ids,
  113. 'type_id': $('#type_id').val()
  114. },
  115. dataType: "json",
  116. success: function (result) {
  117. if (result.success) {
  118. bindCompany(result.obj);
  119. } else {
  120. errorMessage(result.message);
  121. }
  122. },
  123. error: function () {
  124. errorMessage('系统错误!');
  125. }
  126. });
  127. } else {
  128. $(".companyList").empty();
  129. }
  130. }
  131. function bindCompany(companyList) {
  132. $(".companyList").empty();
  133. var str = '';
  134. for (var i = 0; i < companyList.length; i++) {
  135. str += '<div class="col-sx-3 col-sm-3 right-line" style="padding: 0;">'
  136. str += '<ul>'
  137. str += '<li>'
  138. str += '<input type="checkbox" value="' + companyList[i].id + '" name="company" companyName="' + companyList[i].company_name + '" onchange="setTimeout(function(){checkIds()},200);">'
  139. if (companyList[i].type_id == '1') {
  140. str += '<span>工业</span>'
  141. } else if (companyList[i].type_id == '0') {
  142. str += '<span>非工业</span>'
  143. } else {
  144. str += '<span></span>'
  145. }
  146. str += '</li>'
  147. str += '</ul>'
  148. str += '</div>'
  149. str += '<div class="col-sx-9 col-sm-9">'
  150. str += '<ul>'
  151. str += '<li>'
  152. str += '<span>' + companyList[i].company_name + '</span>'
  153. str += '</li>'
  154. str += '</ul>'
  155. str += '</div>'
  156. }
  157. $(".companyList").append(str);
  158. }
  159. function checkIds() {
  160. var ids = new Array();
  161. StreetIds = '', BuildIds = '', CompanyIds = '', Names = '';
  162. $("input:checkbox[name='street']:checked").each(function (i) {
  163. var val = $(this).val();
  164. StreetIds += val + ',';
  165. Names += "<span>"+$(this).attr("streetName") + "</span>";
  166. ids.push({id: val, type: 4});
  167. });
  168. $("input:checkbox[name='build']:checked").each(function (i) {
  169. var val = $(this).val();
  170. BuildIds += val + ',';
  171. Names += "<span>"+$(this).attr("buildName") + "</span>";
  172. ids.push({id: val, type: 1});
  173. });
  174. $("input:checkbox[name='company']:checked").each(function (i) {
  175. var val = $(this).val();
  176. CompanyIds += val + ',';
  177. Names += "<span>"+$(this).attr("companyName") + "</span>";
  178. ids.push({id: val, type: 3});
  179. });
  180. selectedObj = ids;
  181. }
  182. $("body").keydown(function (event) {
  183. if (event.keyCode == "13") {//keyCode=13是回车键
  184. $('#searchBtn').trigger("click");
  185. }
  186. });
  187. $('#searchBtn').click(function () {
  188. var name = $("input[ name='search']").val();
  189. $.ajax({
  190. url: pagePath + "/government/activity/findStreetBuildCompanyByName",
  191. type: "post",
  192. data: {
  193. 'name': name
  194. },
  195. dataType: "json",
  196. success: function (result) {
  197. if (result.success) {
  198. var list = result.obj;
  199. var streetList = new Array();
  200. var buildList = new Array();
  201. var companyList = new Array();
  202. for (var i = 0; i < list.length; i++) {
  203. if (list[i].type == '4') {
  204. streetList.push(list[i]);
  205. } else if (list[i].type == '1') {
  206. buildList.push(list[i]);
  207. } else if (list[i].type == '3') {
  208. companyList.push({id: list[i].id, company_name: list[i].name});
  209. }
  210. }
  211. bindStreet(streetList);
  212. bindBuild(buildList);
  213. bindCompany(companyList);
  214. } else {
  215. errorMessage(result.message);
  216. }
  217. },
  218. error: function () {
  219. errorMessage('系统错误!');
  220. }
  221. });
  222. });
  223. function saveItems() {
  224. parent.$("#pushStreetIds").val(StreetIds);
  225. parent.$("#pushBuildIds").val(BuildIds);
  226. parent.$("#pushCompanyIds").val(CompanyIds);
  227. parent.$("#pushNames").html(Names);
  228. var index = parent.layer.getFrameIndex(window.name);
  229. parent.layer.close(index);
  230. }