serviceList.js 13 KB

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