serviceList.js 16 KB

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