demandList.js 15 KB

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