serviceList.js 13 KB

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