serviceList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 class="btnTxts">
  199. <a href="javascript:(0)" class="companyName"><span class="glyphicon glyphicon-user"></span>${thisdata.companyName}</a>
  200. <span class="number">销量 : ${thisdata.dealCount?thisdata.dealCount:0}</span>
  201. </div>
  202. </div>
  203. </a>
  204. </li>`);
  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. thePageNo=pageNo||1,
  222. endNo = 5;
  223. if (thePageNo > 3) {
  224. firstNo = thePageNo - 2;
  225. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  226. } else {
  227. endNo = Math.min(thePageLength, 5);
  228. };
  229. for (let i = firstNo; i <= endNo; i++) {
  230. if (i == thePageNo) {
  231. pageArr.push(
  232. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  233. );
  234. } else {
  235. pageArr.push(
  236. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  237. );
  238. }
  239. };
  240. $('.pageNumber').remove();
  241. $('.pagePre').after(pageArr.join(''));
  242. }
  243. });
  244. }
  245. //时间转换
  246. function formatDuring(mss) {
  247. var days = parseInt(mss / (1000 * 60 * 60 * 24));
  248. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  249. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  250. var seconds = (mss % (1000 * 60)) / 1000;
  251. return days ;
  252. }
  253. //f分页
  254. function pages() {
  255. $('.pagination').on('click', 'li', function (e) {
  256. e.preventDefault();
  257. if (this.className === 'pagePre') {
  258. if (thePageNo > 1) {
  259. thePageNo = 1;
  260. loadDate(thePageNo);
  261. }
  262. } else if (this.className === 'pageNext') {
  263. if (thePageNo < thePageLength) {
  264. thePageNo = thePageLength;
  265. loadDate(thePageNo);
  266. }
  267. } else {
  268. var nextPageNo = $(this).children()[0].text;
  269. if (thePageNo != nextPageNo) {
  270. $(this).siblings("li").removeClass("active");
  271. $(this).addClass("active");
  272. thePageNo = nextPageNo;
  273. loadDate(thePageNo);
  274. };
  275. };
  276. });
  277. }
  278. //输入跳转
  279. function inpFun() {
  280. $('.inp .btn').on('click', function () {
  281. let val = $(this).siblings().val();
  282. if (!isNaN(val) && val <= thePageLength && val > 0) {
  283. thePageNo = val;
  284. loadDate(thePageNo);
  285. }else{
  286. msg('请输入正确页码')
  287. }
  288. })
  289. }
  290. //已选类型
  291. function onSelect(data) {
  292. $('.industryList ul li').click(function(){
  293. let index = $(this).index();
  294. $(this).addClass('active').siblings().removeClass('active');
  295. $('.objList div span').removeClass('active');
  296. $('.objList div').eq(index).addClass('active').siblings().removeClass('active');
  297. if(!index){
  298. $('.objList div').eq(index).find('span').addClass('active');
  299. }
  300. $('.productionType ol').html('<li class="active" data-id=" ">不限</li>')
  301. $('.preFirst').show();
  302. $('.preFirst').html($(this).text());
  303. $('.next').css('display', 'none')
  304. dataList.name='';
  305. dataList.topId='';
  306. dataList.secondId='';
  307. dataList.module=$(this).attr('data-module');
  308. loadDate();
  309. secH();
  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 txt = $(this).text();
  345. $('.onSelect .preFirst').css('display', 'block').html(`
  346. <span>${txt}</span>
  347. `)
  348. loadDate();
  349. secSelect();
  350. secH();
  351. });
  352. secSelect();
  353. secH()
  354. }
  355. //二级菜单高度处理
  356. function secH(){
  357. let proH = $('.productionType ol').height();
  358. if(proH>50){
  359. $('.productionType p').css({'height':proH,'line-height':proH+'px'})
  360. }else{
  361. $('.productionType p').css({'height':'50px','line-height':'50px'})
  362. }
  363. }
  364. function secSelect(){
  365. $('.productionType ol li').on('click', function () {
  366. dataList.name = '';
  367. dataList.topId = $('.industryList ul li.active').attr('data-id');
  368. $(this).addClass('active').siblings().removeClass('active');
  369. dataList.secondId = $(this).attr('data-id');
  370. if (!dataList.secondId) return;
  371. let txt = $(this).text();
  372. $('.onSelect .next').css('display', 'block').html(`
  373. <span>${txt}</span>
  374. `)
  375. loadDate();
  376. })
  377. }
  378. //搜索
  379. function search() {
  380. $('.hot ul li').click(function () {
  381. $(this).addClass('active').siblings().removeClass('active');
  382. dataList.name = $(this).text();
  383. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  384. $('.industryList ul li').removeClass('active');
  385. $('.productionType ol li').removeClass('active')
  386. $('.demandSearch').val(dataList.name);
  387. $('.objList div span').removeClass('active');
  388. dataList.topId = '';
  389. dataList.secondId = '';
  390. dataList.module='';
  391. loadDate();
  392. });
  393. $('.searchBtn').click(function () {
  394. let val = $('.demandSearch').val();
  395. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  396. $('.industryList ul li').removeClass('active');
  397. $('.productionType ol li').removeClass('active');
  398. $('.objList div span').removeClass('active');
  399. dataList.name = val;
  400. dataList.topId = '';
  401. dataList.secondId = '';
  402. dataList.module='';
  403. loadDate();
  404. })
  405. }
  406. /* 提示 */
  407. //提示框渐隐函数
  408. function msg(txt) {
  409. if($('.smg').hasClass('active')){
  410. return ;
  411. }
  412. $('.smg').addClass('active');
  413. var lit = $('#msg').val(txt);
  414. setTimeout(function () {
  415. $('.smg').removeClass('active')
  416. $('#msg').val('');
  417. }, 2000)
  418. }
  419. })