demandList.js 14 KB

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