demandList.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. endNo = 5;
  220. if (thePageNo > 3) {
  221. firstNo = thePageNo - 2;
  222. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  223. } else {
  224. endNo = Math.min(thePageLength, 5);
  225. };
  226. for (let i = firstNo; i <= endNo; i++) {
  227. if (i == thePageNo) {
  228. pageArr.push(
  229. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  230. );
  231. } else {
  232. pageArr.push(
  233. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  234. );
  235. }
  236. };
  237. $('.pageNumber').remove();
  238. $('.pagePre').after(pageArr.join(''));
  239. }
  240. });
  241. }
  242. //时间转换
  243. function formatDuring(mss) {
  244. var days = parseInt(mss / (1000 * 60 * 60 * 24));
  245. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  246. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  247. var seconds = (mss % (1000 * 60)) / 1000;
  248. return days ;
  249. }
  250. //f分页
  251. function pages() {
  252. $('.pagination').on('click', 'li', function (e) {
  253. e.preventDefault();
  254. if (this.className === 'pagePre') {
  255. if (thePageNo > 1) {
  256. thePageNo = 1;
  257. loadDate(thePageNo);
  258. }
  259. } else if (this.className === 'pageNext') {
  260. if (thePageNo < thePageLength) {
  261. thePageNo = thePageLength;
  262. loadDate(thePageNo);
  263. }
  264. } else {
  265. var nextPageNo = $(this).children()[0].text;
  266. if (thePageNo != nextPageNo) {
  267. $(this).siblings("li").removeClass("active");
  268. $(this).addClass("active");
  269. thePageNo = nextPageNo;
  270. loadDate(thePageNo);
  271. };
  272. };
  273. });
  274. }
  275. //输入跳转
  276. function inpFun() {
  277. $('.inp .btn').on('click', function () {
  278. let val = $(this).siblings().val();
  279. if (!isNaN(val) && val <=thePageLength && val > 0) {
  280. thePageNo = val;
  281. loadDate(thePageNo);
  282. }else{
  283. msg('请输入正确页码')
  284. }
  285. })
  286. }
  287. //已选类型
  288. function onSelect(data) {
  289. $('.industryList ul li').on('click', function () {
  290. $('.searchMain ol li').removeClass('active');
  291. $('.searchMain ol li').eq(0).addClass('active');
  292. let secondTxt = [],
  293. scondHtml = [];
  294. $(this).addClass('active').siblings().removeClass('active')
  295. dataList.topId = $(this).attr('data-id');
  296. dataList.name = '';
  297. dataList.secondId = '';
  298. $('.next').css('display', 'none')
  299. data.map(item => {
  300. if (item.id == dataList.topId) {
  301. secondTxt = item.children
  302. }
  303. })
  304. secondTxt.map(item => {
  305. scondHtml.push(`
  306. <li data-id=${item.id}>${item.name}</li>
  307. `)
  308. })
  309. if (!dataList.topId) {
  310. dataList.topId = '';
  311. dataList.secondId = '';
  312. $('.preFirst').html('不限');
  313. $('.next').css('display', 'none')
  314. scondHtml = ['<li>不限</li>'];
  315. }
  316. $('.productionType ol').html(scondHtml);
  317. heightFun();
  318. let txt = $(this).text();
  319. $('.onSelect .preFirst').css('display', 'block').html(`
  320. <span>${txt}</span>
  321. `)
  322. loadDate();
  323. proFun();
  324. });
  325. }
  326. function proFun(){
  327. $('.productionType ol li').on('click', function () {
  328. dataList.name = '';
  329. dataList.topId = $('.industryList ul li.active').attr('data-id');
  330. $(this).addClass('active').siblings().removeClass('active');
  331. dataList.secondId = $(this).attr('data-id');
  332. if (!dataList.secondId) return;
  333. let txt = $(this).text();
  334. $('.onSelect .next').css('display', 'block').html(`
  335. <span>${txt}</span>
  336. `)
  337. loadDate();
  338. })
  339. }
  340. $('.searchBtn').click(function () {
  341. let val = $('.demandSearch').val();
  342. $('.productionType ol').html(`<li data-id=''>不限</li>`);
  343. $('.industryList ul li').removeClass('active');
  344. $('.productionType ol li').removeClass('active')
  345. dataList.name = val;
  346. dataList.topId = '';
  347. dataList.secondId = '';
  348. loadDate();
  349. })
  350. /* 提示 */
  351. //提示框渐隐函数
  352. function msg(txt) {
  353. if($('.smg').hasClass('active')){
  354. return ;
  355. }
  356. $('.smg').addClass('active');
  357. var lit = $('#msg').val(txt);
  358. setTimeout(function () {
  359. $('.smg').removeClass('active')
  360. $('#msg').val('');
  361. }, 2000)
  362. }
  363. })