serviceList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * @author:liting
  3. * @update:2018/06/20
  4. *
  5. */
  6. import 'css/bootstrap.less';
  7. import 'bootstrap/dist/js/bootstrap.js';
  8. import 'css/newMenu/public.css';
  9. import 'css/newMenu/header.css'
  10. import 'css/newMenu/serviceList.css';
  11. import 'js/public.js';
  12. "use strict";
  13. $(function () {
  14. var thePageNo = 1,
  15. thePageLength = 1,
  16. dataList = {},
  17. pageSize = 15;
  18. init();
  19. function init() {
  20. pages();
  21. inpFun();
  22. summary();
  23. search();
  24. jump();
  25. $('.onSelect .preFirst').css('display', 'none');
  26. $('.onSelect .next').css('display', 'none');
  27. };
  28. //一级界面跳转此页面
  29. function jump() {
  30. let hash = window.location.search;
  31. if (hash) {
  32. if (hash.indexOf('name') > -1 || hash.indexOf('topId') > -1 || hash.indexOf('secondId') > -1) {
  33. let newHash = hash.substr(1, hash.length)
  34. if (newHash.indexOf('&') > -1) {
  35. let hashArr = newHash.split('&');
  36. hashArr.map(item => {
  37. if (item.indexOf('name') > -1) {
  38. let names = item.split('=')
  39. dataList.name = decodeURIComponent(names[1])
  40. }
  41. if (item.indexOf('topId') > -1) {
  42. let topIds = item.split('=')
  43. dataList.topId = decodeURIComponent(topIds[1])
  44. }
  45. if (item.indexOf('secondId') > -1) {
  46. let secondIds = item.split('=')
  47. dataList.secondId = decodeURIComponent(secondIds[1])
  48. }
  49. })
  50. } else {
  51. if (newHash.indexOf('name') > -1) {
  52. let names = newHash.split('=')
  53. dataList.name = decodeURIComponent(names[1])
  54. }
  55. if (newHash.indexOf('topId') > -1) {
  56. let topIds = newHash.split('=')
  57. dataList.topId = decodeURIComponent(topIds[1])
  58. }
  59. if (newHash.indexOf('secondId') > -1) {
  60. let secondIds = newHash.split('=')
  61. dataList.secondId = decodeURIComponent(secondIds[1])
  62. }
  63. }
  64. loadDate()
  65. }
  66. } else {
  67. dataList.name = "",
  68. dataList.topId = "", //行业
  69. dataList.secondId = "" //类型
  70. loadDate();
  71. }
  72. }
  73. function summary() {
  74. let hash = window.location.search;
  75. $.ajax({
  76. method: "get",
  77. dataType: "json",
  78. url: globalConfig.context + "/portal/service/jtBusiness/getCategoryList",
  79. data: {
  80. },
  81. success: function (data) {
  82. var theArrs = [];
  83. if (data.data && data.data.length) {
  84. let thisdata = data.data;
  85. thisdata.unshift({
  86. topLevelId: '',
  87. topLevel: '不限',
  88. children: [{
  89. id: '',
  90. name: '不限'
  91. }]
  92. })
  93. thisdata.map((item,index) => {
  94. if(index||hash){
  95. theArrs.push(`
  96. <li data-id=${item.topLevelId}>${item.topLevel}</li>
  97. `)
  98. }else{
  99. theArrs.push(`
  100. <li class="active" data-id=${item.topLevelId}>${item.topLevel}</li>
  101. `)
  102. }
  103. })
  104. $('.industryList ul').html(theArrs);
  105. $('.industryList ul li').eq(0).className = "active";
  106. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  107. $('.productionType ol li ').eq(0).addClass = "active";
  108. onSelect(thisdata);
  109. };
  110. }
  111. })
  112. }
  113. function loadDate(pageNo) {
  114. $('.loading').show();
  115. $.ajax({
  116. method: "get",
  117. dataType: "json",
  118. url: globalConfig.context + "/portal/service/jtProject/list",
  119. data: {
  120. pageNo: pageNo || 1,
  121. pageSize: 15,
  122. name: dataList.name,
  123. topId: dataList.topId, //行业
  124. secondId: dataList.secondId //类型
  125. },
  126. success: function (data) {
  127. var theArrs = [];
  128. if(data.data&&data.data.error){
  129. msg(data.data.error[0])
  130. };
  131. if (data.data && data.data.list.length) {
  132. let nub = data.data.list.length;
  133. for (let i = 0; i < nub; i++) {
  134. let thisdata = data.data.list[i];
  135. theArrs.push(`
  136. <li>
  137. <a href="${globalConfig.context}/portal/service/serviceDetail?id=${thisdata.id?thisdata.id:''}">
  138. <div class="img">
  139. <img src="${thisdata.maxImgUrl}" alt="">
  140. <span></span>
  141. </div>
  142. <div class="txtIntroduce">
  143. <div class="txts">
  144. <h5>${thisdata.name}</h5>
  145. </div>
  146. <div class="hr"></div>
  147. <div class="btnTxt">
  148. <p>${thisdata.introduce}</p>
  149. </div>
  150. </div>
  151. </a>
  152. </li>`);
  153. };
  154. };
  155. $('.loading').hide();
  156. $('.achievementHot .hotList').empty();
  157. $('.achievementHot .hotList').append(theArrs.join(''));
  158. $('.pagination_box').css('display', 'block');
  159. $('.inp').css('display', 'block');
  160. if (data.data.list.length === 0) {
  161. $('.achievementHot .hotList').html("<div class='list_none'></div>");
  162. $('.pagination_box').css('display', 'none')
  163. $('.inp').css('display', 'none');
  164. };
  165. thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
  166. $('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
  167. var pageArr = [],
  168. firstNo = 1,
  169. endNo = 5;
  170. if (thePageNo > 3) {
  171. firstNo = thePageNo - 2;
  172. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  173. } else {
  174. endNo = Math.min(thePageLength, 5);
  175. };
  176. for (let i = firstNo; i <= endNo; i++) {
  177. if (i == thePageNo) {
  178. pageArr.push(
  179. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  180. );
  181. } else {
  182. pageArr.push(
  183. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  184. );
  185. }
  186. };
  187. $('.pageNumber').remove();
  188. $('.pagePre').after(pageArr.join(''));
  189. }
  190. });
  191. }
  192. //f分页
  193. function pages() {
  194. $('.pagination').on('click', 'li', function (e) {
  195. e.preventDefault();
  196. if (this.className === 'pagePre') {
  197. if (thePageNo > 1) {
  198. thePageNo = 1;
  199. loadDate(thePageNo);
  200. }
  201. } else if (this.className === 'pageNext') {
  202. if (thePageNo < thePageLength) {
  203. thePageNo = thePageLength;
  204. loadDate(thePageNo);
  205. }
  206. } else {
  207. var nextPageNo = $(this).children()[0].text;
  208. if (thePageNo != nextPageNo) {
  209. $(this).siblings("li").removeClass("active");
  210. $(this).addClass("active");
  211. thePageNo = nextPageNo;
  212. loadDate(thePageNo);
  213. };
  214. };
  215. });
  216. }
  217. //输入跳转
  218. function inpFun() {
  219. $('.inp .btn').on('click', function () {
  220. let val = $(this).siblings().val();
  221. if (!isNaN(val) && val <= thePageLength && val > 0) {
  222. thePageNo = val;
  223. loadDate(thePageNo);
  224. }else{
  225. msg('请输入正确页码')
  226. }
  227. })
  228. }
  229. //已选类型
  230. function onSelect(data) {
  231. $('.industryList ul li').on('click', function () {
  232. let secondTxt = [],
  233. scondHtml = [];
  234. $(this).addClass('active').siblings().removeClass('active')
  235. dataList.topId = $(this).attr('data-id');
  236. dataList.name = '';
  237. dataList.secondId = '';
  238. $('.next').css('display', 'none')
  239. data.map(item => {
  240. if (item.topLevelId == dataList.topId) {
  241. secondTxt = item.children
  242. }
  243. })
  244. secondTxt.map(item => {
  245. scondHtml.push(`
  246. <li data-id=${item.id}>${item.name}</li>
  247. `)
  248. })
  249. if (!dataList.topId) {
  250. dataList.topId = '';
  251. dataList.secondId = '';
  252. $('.preFirst').html('不限');
  253. $('.next').css('display', 'none')
  254. scondHtml = ['<li>不限</li>'];
  255. }
  256. $('.productionType ol').html(scondHtml);
  257. let txt = $(this).text();
  258. $('.onSelect .preFirst').css('display', 'block').html(`
  259. <span>${txt}</span>
  260. `)
  261. loadDate();
  262. $('.productionType ol li').on('click', function () {
  263. dataList.name = '';
  264. dataList.topId = $('.industryList ul li.active').attr('data-id');
  265. $(this).addClass('active').siblings().removeClass('active');
  266. dataList.secondId = $(this).attr('data-id');
  267. if (!dataList.secondId) return;
  268. let txt = $(this).text();
  269. $('.onSelect .next').css('display', 'block').html(`
  270. <span>${txt}</span>
  271. <span class="typeClose">x</span>
  272. `)
  273. loadDate();
  274. })
  275. });
  276. }
  277. //搜索
  278. function search() {
  279. $('.hot ul li').click(function () {
  280. dataList.name = $(this).text();
  281. dataList.topId = '';
  282. dataList.secondId = '';
  283. loadDate();
  284. });
  285. $('.searchBtn').click(function () {
  286. let val = $('.demandSearch').val();
  287. if (val) {
  288. dataList.name = val;
  289. dataList.topId = '';
  290. dataList.secondId = '';
  291. loadDate();
  292. }
  293. })
  294. }
  295. /* 提示 */
  296. //提示框渐隐函数
  297. function msg(txt) {
  298. $('.smg').addClass('active');
  299. var lit = $('#msg').val(txt);
  300. setTimeout(function () {
  301. $('.smg').removeClass('active')
  302. $('#msg').val('');
  303. }, 2000)
  304. }
  305. })