serviceList.js 13 KB

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