serviceList.js 13 KB

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