achievementList.js 14 KB

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