demandList.js 14 KB

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