serviceList.js 15 KB

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