serviceList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. // <a href="${globalConfig.context}/portal/service/serviceDetail?id=${thisdata.id?thisdata.id:''}">
  188. theArrs.push(`
  189. <li dataId="${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 class="btnTxts">
  199. <a href="javascript:(0)" class="companyName"><span class="glyphicon glyphicon-user"></span>${thisdata.companyName?thisdata.companyName:''}</a>
  200. <span class="number">销量 : ${thisdata.dealCount?thisdata.dealCount:0}</span>
  201. </div>
  202. </div>
  203. </li>`);
  204. };
  205. };
  206. $('.loading').hide().stop(true,true);
  207. $('.achievementHot .hotList').empty();
  208. $('.achievementHot .hotList').append(theArrs.join(''));
  209. $('.pagination_box').css('display', 'block');
  210. $('.inp').css('display', 'block');
  211. if (data.data.list.length === 0) {
  212. $('.achievementHot .hotList').html("<div class='list_none'></div>");
  213. $('.pagination_box').css('display', 'none')
  214. $('.inp').css('display', 'none');
  215. };
  216. thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
  217. $('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
  218. var pageArr = [],
  219. firstNo = 1,
  220. thePageNo=pageNo||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. urlDetaile();
  242. }
  243. });
  244. }
  245. //跳转详情函数
  246. function urlDetaile(){
  247. $('.hotList>li').click(function(){
  248. let idUrl = $(this).attr('dataId');
  249. window.location.href=globalConfig.context+'/portal/service/serviceDetail?id='+idUrl;
  250. })
  251. }
  252. //时间转换
  253. function formatDuring(mss) {
  254. var days = parseInt(mss / (1000 * 60 * 60 * 24));
  255. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  256. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  257. var seconds = (mss % (1000 * 60)) / 1000;
  258. return days ;
  259. }
  260. //f分页
  261. function pages() {
  262. $('.pagination').on('click', 'li', function (e) {
  263. e.preventDefault();
  264. if (this.className === 'pagePre') {
  265. if (thePageNo > 1) {
  266. thePageNo = 1;
  267. loadDate(thePageNo);
  268. }
  269. } else if (this.className === 'pageNext') {
  270. if (thePageNo < thePageLength) {
  271. thePageNo = thePageLength;
  272. loadDate(thePageNo);
  273. }
  274. } else {
  275. var nextPageNo = $(this).children()[0].text;
  276. if (thePageNo != nextPageNo) {
  277. $(this).siblings("li").removeClass("active");
  278. $(this).addClass("active");
  279. thePageNo = nextPageNo;
  280. loadDate(thePageNo);
  281. };
  282. };
  283. });
  284. }
  285. //输入跳转
  286. function inpFun() {
  287. $('.inp button').on('click', function () {
  288. let val = $(this).siblings().val();
  289. if (!isNaN(val) && val <= thePageLength && val > 0) {
  290. thePageNo = val;
  291. loadDate(thePageNo);
  292. }else{
  293. msg('请输入正确页码')
  294. }
  295. })
  296. }
  297. //已选类型
  298. function onSelect(data) {
  299. $('.industryList ul li').click(function(){
  300. let index = $(this).index();
  301. $(this).addClass('active').siblings().removeClass('active');
  302. $('.objList div span').removeClass('active');
  303. $('.objList div').eq(index).addClass('active').siblings().removeClass('active');
  304. if(!index){
  305. $('.objList div').eq(index).find('span').addClass('active');
  306. }
  307. $('.productionType ol').html('<li class="active" data-id=" ">不限</li>')
  308. $('.preFirst').show();
  309. $('.preFirst').html($(this).text());
  310. $('.next').css('display', 'none')
  311. dataList.name='';
  312. dataList.topId='';
  313. dataList.secondId='';
  314. dataList.module=$(this).attr('data-module');
  315. loadDate();
  316. secH();
  317. })
  318. $('.objList div span').on('click', function () {
  319. let secondTxt = [],
  320. scondHtml = [];
  321. $('.hot ul li').removeClass('active');
  322. $(this).parent('div').addClass('active').siblings().removeClass('active')
  323. $('.industryList ul li p').removeClass('active');
  324. $(this).addClass('active').siblings().removeClass('active')
  325. dataList.topId = $(this).attr('data-id');
  326. dataList.name = '';
  327. dataList.secondId = '';
  328. $('.next').css('display', 'none')
  329. data.map(item => {
  330. if(item.list&&(item.list).length){
  331. (item.list).map(atem=>{
  332. if (atem.topLevelId == dataList.topId) {
  333. secondTxt = atem.children
  334. }
  335. })
  336. }
  337. })
  338. secondTxt.map(item => {
  339. scondHtml.push(`
  340. <li data-id=${item.id}>${item.name}</li>
  341. `)
  342. })
  343. if (!dataList.topId) {
  344. dataList.topId = '';
  345. dataList.secondId = '';
  346. $('.preFirst').html('不限');
  347. $('.next').css('display', 'none')
  348. scondHtml = ['<li>不限</li>'];
  349. }
  350. $('.productionType ol').html(scondHtml);
  351. let txt = $(this).text();
  352. $('.onSelect .preFirst').css('display', 'block').html(`
  353. <span>${txt}</span>
  354. `)
  355. loadDate();
  356. secSelect();
  357. secH();
  358. });
  359. secSelect();
  360. secH()
  361. }
  362. //二级菜单高度处理
  363. function secH(){
  364. let proH = $('.productionType ol').height();
  365. if(proH>50){
  366. $('.productionType p').css({'height':proH,'line-height':proH+'px'})
  367. }else{
  368. $('.productionType p').css({'height':'50px','line-height':'50px'})
  369. }
  370. }
  371. function secSelect(){
  372. $('.productionType ol li').on('click', function () {
  373. dataList.name = '';
  374. dataList.topId = $('.industryList ul li.active').attr('data-id');
  375. $(this).addClass('active').siblings().removeClass('active');
  376. dataList.secondId = $(this).attr('data-id');
  377. if (!dataList.secondId) return;
  378. let txt = $(this).text();
  379. $('.onSelect .next').css('display', 'block').html(`
  380. <span>${txt}</span>
  381. `)
  382. loadDate();
  383. })
  384. }
  385. //搜索
  386. function search() {
  387. $('.hot ul li').click(function () {
  388. $(this).addClass('active').siblings().removeClass('active');
  389. dataList.name = $(this).text();
  390. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  391. $('.industryList ul li').removeClass('active');
  392. $('.productionType ol li').removeClass('active')
  393. $('.demandSearch').val(dataList.name);
  394. $('.objList div span').removeClass('active');
  395. dataList.topId = '';
  396. dataList.secondId = '';
  397. dataList.module='';
  398. loadDate();
  399. });
  400. $('.searchBtn').click(function () {
  401. let val = $('.demandSearch').val();
  402. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  403. $('.industryList ul li').removeClass('active');
  404. $('.productionType ol li').removeClass('active');
  405. $('.objList div span').removeClass('active');
  406. dataList.name = val;
  407. dataList.topId = '';
  408. dataList.secondId = '';
  409. dataList.module='';
  410. loadDate();
  411. })
  412. }
  413. /* 提示 */
  414. //提示框渐隐函数
  415. function msg(txt) {
  416. if($('.smg').hasClass('active')){
  417. return ;
  418. }
  419. $('.smg').addClass('active');
  420. var lit = $('#msg').val(txt);
  421. setTimeout(function () {
  422. $('.smg').removeClass('active')
  423. $('#msg').val('');
  424. }, 2000)
  425. }
  426. })