serviceList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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(theData) {
  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. menuInit(theData)
  43. }
  44. if (item.indexOf('topId') > -1) {
  45. let topIds = item.split('=')
  46. dataList.topId = decodeURIComponent(topIds[1])
  47. menuInit(theData,topIds)
  48. }
  49. if (item.indexOf('secondId') > -1) {
  50. let secondIds = item.split('=')
  51. dataList.secondId = decodeURIComponent(secondIds[1])
  52. menuInit(theData,secondIds[1])
  53. }
  54. })
  55. } else {
  56. if (newHash.indexOf('name') > -1) {
  57. let names = newHash.split('=')
  58. dataList.name = decodeURIComponent(names[1])
  59. $('.demandSearch').val(dataList.name);
  60. menuInit(theData)
  61. }
  62. if (newHash.indexOf('topId') > -1) {
  63. let topIds = newHash.split('=')
  64. dataList.topId = decodeURIComponent(topIds[1])
  65. menuInit(theData,topIds[1])
  66. }
  67. if (newHash.indexOf('secondId') > -1) {
  68. let secondIds = newHash.split('=')
  69. dataList.secondId = decodeURIComponent(secondIds[1])
  70. menuInit(theData,secondIds[1])
  71. }
  72. }
  73. loadDate()
  74. }
  75. } else {
  76. dataList.name = "",
  77. dataList.topId = "", //行业
  78. dataList.secondId = "" //类型
  79. loadDate();
  80. menuInit(theData);
  81. }
  82. }
  83. //跳转渲染菜单
  84. function menuInit(data,id='',state){
  85. var theArrs = '',htmls='',htmlSec='';
  86. htmls+='<div class="objList">';
  87. let thisdata=data,m,n,l;
  88. thisdata.unshift({
  89. module: '',
  90. name: '不限',
  91. list:[{
  92. topLevelId:'',
  93. topLevel:'不限'
  94. }]
  95. })
  96. thisdata.map((item,index)=>{
  97. htmls+='<div>';
  98. theArrs+='<li data-module='+item.module+'><span>'+item.name+'</span></li>';
  99. if(item.list&&(item.list).length){
  100. (item.list).map((atem,ind)=>{
  101. if(atem.topLevelId==id){
  102. m=index;n=ind;
  103. htmls+='<span class="active" data-id='+atem.topLevelId+'>'+atem.topLevel+'</span>'
  104. return;
  105. }else{
  106. atem.children&&(atem.children).map((otem,nub)=>{
  107. if(otem.id==id){
  108. m=index;n=ind,l=nub;
  109. }
  110. })
  111. }
  112. htmls+='<span data-id="'+atem.topLevelId+'">'+atem.topLevel+'</span>'
  113. })
  114. }
  115. htmls+='</div>'
  116. })
  117. if(l>=0){
  118. let listSec = thisdata[m].list[n].children;
  119. listSec.map(ttm=>{
  120. htmlSec+=`<li data-id=${ttm.id}>${ttm.name}</li>`
  121. })
  122. }else{
  123. l=0;
  124. htmlSec='<li data-id="" class="active">不限</li>';
  125. }
  126. htmls+='</div>';
  127. if(!id){
  128. $('.industryList').append(htmls);
  129. $('.industryList ul').html(theArrs);
  130. $('.industryList ul li').eq(0).addClass('active');
  131. $('.objList div').eq(0).addClass('active');
  132. $('.objList div').eq(0).find('span').addClass('active');
  133. $('.productionType ol').html(`<li data-id='' class="active">不限</li>`);
  134. }else{
  135. $('.industryList').append(htmls);
  136. $('.industryList ul').html(theArrs);
  137. $('.industryList ul li').eq(m).addClass('active');
  138. $('.objList>div').eq(m).addClass('active');
  139. $('.objList>div').eq(m).find('span').eq(n).addClass('active');
  140. $('.productionType ol').html(htmlSec);
  141. $('.productionType ol li').eq(l).addClass('active');
  142. }
  143. onSelect(thisdata);
  144. }
  145. function summary() {
  146. $.ajax({
  147. method: "get",
  148. dataType: "json",
  149. url: globalConfig.context + "/portal/service/jtBusiness/makeMoneyCategoryList",
  150. data: {},
  151. success: function (data) {
  152. if (data.data && data.data.length) {
  153. let thisdata = data.data;
  154. jump(thisdata)
  155. };
  156. }
  157. })
  158. }
  159. function loadDate(pageNo) {
  160. $('.loading').show();
  161. $.ajax({
  162. method: "get",
  163. dataType: "json",
  164. url: globalConfig.context + "/portal/service/jtProject/list",
  165. data: {
  166. pageNo: pageNo || 1,
  167. pageSize: 15,
  168. name: dataList.name,
  169. topId: dataList.topId, //行业
  170. secondId: dataList.secondId, //类型
  171. privateProject:1,
  172. auditStatus:2,
  173. module:dataList.module||'0'
  174. },
  175. success: function (data) {
  176. var theArrs = [];
  177. if(data&&data.error.length){
  178. msg(data.error[0].message)
  179. };
  180. let times = new Date().getTime();
  181. if (data.data && data.data.list.length) {
  182. let nub = data.data.list.length;
  183. for (let i = 0; i < nub; i++) {
  184. let thisdata = data.data.list[i],
  185. news = formatDuring(times)-formatDuring(thisdata.releaseDate);
  186. var introd=thisdata.introduce?(thisdata.introduce).replace(/<\/?.+?>/g,""):thisdata.introduce;
  187. theArrs.push(`
  188. <li>
  189. <a href="${globalConfig.context}/portal/service/serviceDetail?id=${thisdata.id?thisdata.id:''}">
  190. <div class="img serviceImg">
  191. ${thisdata.maxImgUrl&&thisdata.maxImgUrl!=null?'<img src="'+globalConfig.avatarHost+'/upload'+thisdata.maxImgUrl+'"/>':''}
  192. <span style="display:${news>7?'none':'block'}"></span>
  193. </div>
  194. <div class="txtIntroduce">
  195. <div class="txts">
  196. <h5>${thisdata.name}</h5>
  197. </div>
  198. </div>
  199. </a>
  200. </li>`);
  201. /* <div class="hr"></div>
  202. <div class="btnTxt">
  203. <p>${thisdata.introduce!=null?introd:'暂无介绍'}</p>
  204. </div> */
  205. };
  206. };
  207. $('.loading').hide().stop(true,true);
  208. $('.achievementHot .hotList').empty();
  209. $('.achievementHot .hotList').append(theArrs.join(''));
  210. $('.pagination_box').css('display', 'block');
  211. $('.inp').css('display', 'block');
  212. if (data.data.list.length === 0) {
  213. $('.achievementHot .hotList').html("<div class='list_none'></div>");
  214. $('.pagination_box').css('display', 'none')
  215. $('.inp').css('display', 'none');
  216. };
  217. thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
  218. $('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
  219. var pageArr = [],
  220. firstNo = 1,
  221. endNo = 5;
  222. if (thePageNo > 3) {
  223. firstNo = thePageNo - 2;
  224. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  225. } else {
  226. endNo = Math.min(thePageLength, 5);
  227. };
  228. for (let i = firstNo; i <= endNo; i++) {
  229. if (i == thePageNo) {
  230. pageArr.push(
  231. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  232. );
  233. } else {
  234. pageArr.push(
  235. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  236. );
  237. }
  238. };
  239. $('.pageNumber').remove();
  240. $('.pagePre').after(pageArr.join(''));
  241. }
  242. });
  243. }
  244. //时间转换
  245. function formatDuring(mss) {
  246. var days = parseInt(mss / (1000 * 60 * 60 * 24));
  247. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  248. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  249. var seconds = (mss % (1000 * 60)) / 1000;
  250. return days ;
  251. }
  252. //f分页
  253. function pages() {
  254. $('.pagination').on('click', 'li', function (e) {
  255. e.preventDefault();
  256. if (this.className === 'pagePre') {
  257. if (thePageNo > 1) {
  258. thePageNo = 1;
  259. loadDate(thePageNo);
  260. }
  261. } else if (this.className === 'pageNext') {
  262. if (thePageNo < thePageLength) {
  263. thePageNo = thePageLength;
  264. loadDate(thePageNo);
  265. }
  266. } else {
  267. var nextPageNo = $(this).children()[0].text;
  268. if (thePageNo != nextPageNo) {
  269. $(this).siblings("li").removeClass("active");
  270. $(this).addClass("active");
  271. thePageNo = nextPageNo;
  272. loadDate(thePageNo);
  273. };
  274. };
  275. });
  276. }
  277. //输入跳转
  278. function inpFun() {
  279. $('.inp .btn').on('click', function () {
  280. let val = $(this).siblings().val();
  281. if (!isNaN(val) && val <= thePageLength && val > 0) {
  282. thePageNo = val;
  283. loadDate(thePageNo);
  284. }else{
  285. msg('请输入正确页码')
  286. }
  287. })
  288. }
  289. //已选类型
  290. function onSelect(data) {
  291. $('.industryList ul li').click(function(){
  292. let index = $(this).index();
  293. $(this).addClass('active').siblings().removeClass('active');
  294. $('.objList div span').removeClass('active');
  295. $('.objList div').eq(index).addClass('active').siblings().removeClass('active');
  296. if(!index){
  297. $('.objList div').eq(index).find('span').addClass('active');
  298. }
  299. $('.productionType ol').html('<li class="active" data-id=" ">不限</li>')
  300. $('.productionType ol').css({'height':'50px','line-height':'50px'});
  301. $('.productionType p').css({'height':'50px','line-height':'50px'});
  302. $('.preFirst').show();
  303. $('.preFirst').html($(this).text());
  304. $('.next').css('display', 'none')
  305. dataList.name='';
  306. dataList.topId='';
  307. dataList.secondId='';
  308. dataList.module=$(this).attr('data-module');
  309. loadDate();
  310. })
  311. $('.objList div span').on('click', function () {
  312. let secondTxt = [],
  313. scondHtml = [];
  314. $('.hot ul li').removeClass('active');
  315. $(this).parent('div').addClass('active').siblings().removeClass('active')
  316. $('.industryList ul li p').removeClass('active');
  317. $(this).addClass('active').siblings().removeClass('active')
  318. dataList.topId = $(this).attr('data-id');
  319. dataList.name = '';
  320. dataList.secondId = '';
  321. $('.next').css('display', 'none')
  322. data.map(item => {
  323. if(item.list&&(item.list).length){
  324. (item.list).map(atem=>{
  325. if (atem.topLevelId == dataList.topId) {
  326. secondTxt = atem.children
  327. }
  328. })
  329. }
  330. })
  331. secondTxt.map(item => {
  332. scondHtml.push(`
  333. <li data-id=${item.id}>${item.name}</li>
  334. `)
  335. })
  336. if (!dataList.topId) {
  337. dataList.topId = '';
  338. dataList.secondId = '';
  339. $('.preFirst').html('不限');
  340. $('.next').css('display', 'none')
  341. scondHtml = ['<li>不限</li>'];
  342. }
  343. $('.productionType ol').html(scondHtml);
  344. let proH = $('.productionType ol').height();
  345. if(proH>50){
  346. $('.productionType p').css({'height':proH,'line-height':proH+'px'})
  347. }else{
  348. $('.productionType p').css({'height':'50px','line-height':'50px'})
  349. }
  350. let txt = $(this).text();
  351. $('.onSelect .preFirst').css('display', 'block').html(`
  352. <span>${txt}</span>
  353. `)
  354. loadDate();
  355. secSelect();
  356. });
  357. secSelect();
  358. }
  359. function secSelect(){
  360. $('.productionType ol li').on('click', function () {
  361. dataList.name = '';
  362. dataList.topId = $('.industryList ul li.active').attr('data-id');
  363. $(this).addClass('active').siblings().removeClass('active');
  364. dataList.secondId = $(this).attr('data-id');
  365. if (!dataList.secondId) return;
  366. let txt = $(this).text();
  367. $('.onSelect .next').css('display', 'block').html(`
  368. <span>${txt}</span>
  369. `)
  370. loadDate();
  371. })
  372. }
  373. //搜索
  374. function search() {
  375. $('.hot ul li').click(function () {
  376. $(this).addClass('active').siblings().removeClass('active');
  377. dataList.name = $(this).text();
  378. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  379. $('.industryList ul li').removeClass('active');
  380. $('.productionType ol li').removeClass('active')
  381. $('.demandSearch').val(dataList.name);
  382. $('.objList div span').removeClass('active');
  383. dataList.topId = '';
  384. dataList.secondId = '';
  385. dataList.module='';
  386. loadDate();
  387. });
  388. $('.searchBtn').click(function () {
  389. let val = $('.demandSearch').val();
  390. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  391. $('.industryList ul li').removeClass('active');
  392. $('.productionType ol li').removeClass('active');
  393. $('.objList div span').removeClass('active');
  394. dataList.name = val;
  395. dataList.topId = '';
  396. dataList.secondId = '';
  397. dataList.module='';
  398. loadDate();
  399. })
  400. }
  401. /* 提示 */
  402. //提示框渐隐函数
  403. function msg(txt) {
  404. if($('.smg').hasClass('active')){
  405. return ;
  406. }
  407. $('.smg').addClass('active');
  408. var lit = $('#msg').val(txt);
  409. setTimeout(function () {
  410. $('.smg').removeClass('active')
  411. $('#msg').val('');
  412. }, 2000)
  413. }
  414. })