serviceList.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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||'0'
  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. theArrs.push(`
  147. <li>
  148. <a href="${globalConfig.context}/portal/service/serviceDetail?id=${thisdata.id?thisdata.id:''}">
  149. <div class="img serviceImg">
  150. ${thisdata.maxImgUrl&&thisdata.maxImgUrl!=null?'<img src="'+globalConfig.avatarHost+'/upload'+thisdata.maxImgUrl+'"/>':''}
  151. <span style="display:${news>7?'none':'block'}"></span>
  152. </div>
  153. <div class="txtIntroduce">
  154. <div class="txts">
  155. <h5>${thisdata.name}</h5>
  156. </div>
  157. <div class="hr"></div>
  158. <div class="btnTxt">
  159. <p>${thisdata.introduce!=null?introd:'暂无介绍'}</p>
  160. </div>
  161. </div>
  162. </a>
  163. </li>`);
  164. };
  165. };
  166. $('.loading').hide().stop(true,true);
  167. $('.achievementHot .hotList').empty();
  168. $('.achievementHot .hotList').append(theArrs.join(''));
  169. $('.pagination_box').css('display', 'block');
  170. $('.inp').css('display', 'block');
  171. if (data.data.list.length === 0) {
  172. $('.achievementHot .hotList').html("<div class='list_none'></div>");
  173. $('.pagination_box').css('display', 'none')
  174. $('.inp').css('display', 'none');
  175. };
  176. thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
  177. $('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
  178. var pageArr = [],
  179. firstNo = 1,
  180. endNo = 5;
  181. if (thePageNo > 3) {
  182. firstNo = thePageNo - 2;
  183. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  184. } else {
  185. endNo = Math.min(thePageLength, 5);
  186. };
  187. for (let i = firstNo; i <= endNo; i++) {
  188. if (i == thePageNo) {
  189. pageArr.push(
  190. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  191. );
  192. } else {
  193. pageArr.push(
  194. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  195. );
  196. }
  197. };
  198. $('.pageNumber').remove();
  199. $('.pagePre').after(pageArr.join(''));
  200. }
  201. });
  202. }
  203. //时间转换
  204. function formatDuring(mss) {
  205. var days = parseInt(mss / (1000 * 60 * 60 * 24));
  206. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  207. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  208. var seconds = (mss % (1000 * 60)) / 1000;
  209. return days ;
  210. }
  211. //f分页
  212. function pages() {
  213. $('.pagination').on('click', 'li', function (e) {
  214. e.preventDefault();
  215. if (this.className === 'pagePre') {
  216. if (thePageNo > 1) {
  217. thePageNo = 1;
  218. loadDate(thePageNo);
  219. }
  220. } else if (this.className === 'pageNext') {
  221. if (thePageNo < thePageLength) {
  222. thePageNo = thePageLength;
  223. loadDate(thePageNo);
  224. }
  225. } else {
  226. var nextPageNo = $(this).children()[0].text;
  227. if (thePageNo != nextPageNo) {
  228. $(this).siblings("li").removeClass("active");
  229. $(this).addClass("active");
  230. thePageNo = nextPageNo;
  231. loadDate(thePageNo);
  232. };
  233. };
  234. });
  235. }
  236. //输入跳转
  237. function inpFun() {
  238. $('.inp .btn').on('click', function () {
  239. let val = $(this).siblings().val();
  240. if (!isNaN(val) && val <= thePageLength && val > 0) {
  241. thePageNo = val;
  242. loadDate(thePageNo);
  243. }else{
  244. msg('请输入正确页码')
  245. }
  246. })
  247. }
  248. //已选类型
  249. function onSelect(data) {
  250. $('.industryList ul li').click(function(){
  251. let index = $(this).index();
  252. $(this).addClass('active').siblings().removeClass('active');
  253. $('.objList div span').removeClass('active');
  254. $('.objList div').eq(index).addClass('active').siblings().removeClass('active');
  255. if(!index){
  256. $('.objList div').eq(index).find('span').addClass('active');
  257. }
  258. $('.productionType ol').html('<li class="active" data-id=" ">不限</li>')
  259. $('.preFirst').show();
  260. $('.preFirst').html($(this).text());
  261. $('.next').css('display', 'none')
  262. dataList.name='';
  263. dataList.topId='';
  264. dataList.secondId='';
  265. dataList.module=$(this).attr('data-module');
  266. loadDate();
  267. })
  268. $('.objList div span').on('click', function () {
  269. let secondTxt = [],
  270. scondHtml = [];
  271. $('.hot ul li').removeClass('active');
  272. $(this).parent('div').addClass('active').siblings().removeClass('active')
  273. $('.industryList ul li p').removeClass('active');
  274. $(this).addClass('active').siblings().removeClass('active')
  275. dataList.topId = $(this).attr('data-id');
  276. dataList.name = '';
  277. dataList.secondId = '';
  278. $('.next').css('display', 'none')
  279. data.map(item => {
  280. if(item.list&&(item.list).length){
  281. (item.list).map(atem=>{
  282. if (atem.topLevelId == dataList.topId) {
  283. secondTxt = atem.children
  284. }
  285. })
  286. }
  287. })
  288. secondTxt.map(item => {
  289. scondHtml.push(`
  290. <li data-id=${item.id}>${item.name}</li>
  291. `)
  292. })
  293. if (!dataList.topId) {
  294. dataList.topId = '';
  295. dataList.secondId = '';
  296. $('.preFirst').html('不限');
  297. $('.next').css('display', 'none')
  298. scondHtml = ['<li>不限</li>'];
  299. }
  300. $('.productionType ol').html(scondHtml);
  301. let proH = $('.productionType ol').height();
  302. if(proH>50){
  303. $('.productionType p').css({'height':proH,'line-height':proH+'px'})
  304. }
  305. let txt = $(this).text();
  306. $('.onSelect .preFirst').css('display', 'block').html(`
  307. <span>${txt}</span>
  308. `)
  309. loadDate();
  310. $('.productionType ol li').on('click', function () {
  311. dataList.name = '';
  312. dataList.topId = $('.industryList ul li.active').attr('data-id');
  313. $(this).addClass('active').siblings().removeClass('active');
  314. dataList.secondId = $(this).attr('data-id');
  315. if (!dataList.secondId) return;
  316. let txt = $(this).text();
  317. $('.onSelect .next').css('display', 'block').html(`
  318. <span>${txt}</span>
  319. `)
  320. loadDate();
  321. })
  322. });
  323. }
  324. //搜索
  325. function search() {
  326. $('.hot ul li').click(function () {
  327. $(this).addClass('active').siblings().removeClass('active');
  328. dataList.name = $(this).text();
  329. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  330. $('.industryList ul li').removeClass('active');
  331. $('.productionType ol li').removeClass('active')
  332. $('.demandSearch').val(dataList.name);
  333. $('.objList div span').removeClass('active');
  334. dataList.topId = '';
  335. dataList.secondId = '';
  336. dataList.module='';
  337. loadDate();
  338. });
  339. $('.searchBtn').click(function () {
  340. let val = $('.demandSearch').val();
  341. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  342. $('.industryList ul li').removeClass('active');
  343. $('.productionType ol li').removeClass('active');
  344. $('.objList div span').removeClass('active');
  345. dataList.name = val;
  346. dataList.topId = '';
  347. dataList.secondId = '';
  348. dataList.module='';
  349. loadDate();
  350. })
  351. }
  352. /* 提示 */
  353. //提示框渐隐函数
  354. function msg(txt) {
  355. if($('.smg').hasClass('active')){
  356. return ;
  357. }
  358. $('.smg').addClass('active');
  359. var lit = $('#msg').val(txt);
  360. setTimeout(function () {
  361. $('.smg').removeClass('active')
  362. $('#msg').val('');
  363. }, 2000)
  364. }
  365. })