serviceList.js 18 KB

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