achievementList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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" style="display:${thisdata.pictureUrl!=null?'block':'none'}">
  178. <img src="${globalConfig.avatarHost + '/upload'+thisdata.pictureUrl}" alt="">
  179. <span style="display:${news>7?'none':'block'}"></span>
  180. </div>
  181. <div class="img achievemrntImg" style="display:${thisdata.pictureUrl!=null?'none':'block'}">
  182. <img src="${thisdata.pictureUrl}" alt="">
  183. <span style="display:${news>7?'none':'block'}"></span>
  184. </div>
  185. <div class="txtIntroduce">
  186. <div class="txts">
  187. <h5 title="${thisdata.name}">${thisdata.name}</h5>
  188. <p><span>${thisdata.dataCategoryS?thisdata.dataCategoryS:'实用技术'}</span><span style="display:${thisdata.isHot&&thisdata.isHot!='null'?'block':'none'}" class="hotImg"></span></p>
  189. </div>
  190. <div class="hr"></div>
  191. <div class="btnTxt">
  192. <span class="float-left" style="display:${thisdata.fieldAS!=null?'block':'none'}">${thisdata.fieldAS}</span>
  193. </div>
  194. </div>
  195. </a>
  196. </li>`);
  197. };
  198. };
  199. $('.loading').hide().stop(true,true);
  200. $('.achievementHot .hotList').empty();
  201. $('.achievementHot .hotList').append(theArrs.join(''));
  202. $('.pagination_box').css('display', 'block');
  203. $('.inp').css('display', 'block');
  204. if (data.data.list.length === 0) {
  205. $('.achievementHot .hotList').html("<div class='list_none'></div>");
  206. $('.pagination_box').css('display', 'none')
  207. $('.inp').css('display', 'none');
  208. };
  209. thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
  210. $('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
  211. var pageArr = [],
  212. firstNo = 1,
  213. endNo = 5;
  214. if (thePageNo > 3) {
  215. firstNo = thePageNo - 2;
  216. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  217. } else {
  218. endNo = Math.min(thePageLength, 5);
  219. };
  220. for (let i = firstNo; i <= endNo; i++) {
  221. if (i == thePageNo) {
  222. pageArr.push(
  223. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  224. );
  225. } else {
  226. pageArr.push(
  227. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  228. );
  229. }
  230. };
  231. $('.pageNumber').remove();
  232. $('.pagePre').after(pageArr.join(''));
  233. }
  234. });
  235. }
  236. //时间转换
  237. function formatDuring(mss) {
  238. var days = parseInt(mss / (1000 * 60 * 60 * 24));
  239. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  240. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  241. var seconds = (mss % (1000 * 60)) / 1000;
  242. return days ;
  243. }
  244. //f分页
  245. function pages() {
  246. $('.pagination').on('click', 'li', function (e) {
  247. e.preventDefault();
  248. if (this.className === 'pagePre') {
  249. if (thePageNo > 1) {
  250. thePageNo = 1;
  251. loadDate(thePageNo);
  252. }
  253. } else if (this.className === 'pageNext') {
  254. if (thePageNo < thePageLength) {
  255. thePageNo = thePageLength;
  256. loadDate(thePageNo);
  257. }
  258. } else {
  259. var nextPageNo = $(this).children()[0].text;
  260. if (thePageNo != nextPageNo) {
  261. $(this).siblings("li").removeClass("active");
  262. $(this).addClass("active");
  263. thePageNo = nextPageNo;
  264. loadDate(thePageNo);
  265. };
  266. };
  267. });
  268. }
  269. //输入跳转
  270. function inpFun() {
  271. $('.inp .btn').on('click', function () {
  272. let val = $(this).siblings().val();
  273. if (!isNaN(val) && val <= thePageLength && val > 0) {
  274. thePageNo = val;
  275. loadDate(thePageNo);
  276. }else{
  277. msg('请输入正确页码')
  278. }
  279. })
  280. }
  281. //已选类型
  282. function onSelect(data) {
  283. $('.industryList ul li').on('click', function () {
  284. $('.searchMain ol li').removeClass('active');
  285. $('.searchMain ol li').eq(0).addClass('active');
  286. let secondTxt = [],
  287. scondHtml = [];
  288. $(this).addClass('active').siblings().removeClass('active')
  289. dataList.topId = $(this).attr('data-id');
  290. dataList.name = '';
  291. dataList.secondId = '';
  292. $('.next').css('display', 'none')
  293. data.map(item => {
  294. if (item.id == dataList.topId) {
  295. secondTxt = item.children
  296. }
  297. })
  298. secondTxt.map(item => {
  299. scondHtml.push(`
  300. <li data-id=${item.id}>${item.name}</li>
  301. `)
  302. })
  303. if (!dataList.topId) {
  304. dataList.topId = '';
  305. dataList.secondId = '';
  306. $('.preFirst').html('不限');
  307. $('.next').css('display', 'none')
  308. scondHtml = ['<li>不限</li>'];
  309. }
  310. $('.productionType ol').html(scondHtml);
  311. heightFun();
  312. let txt = $(this).text();
  313. $('.onSelect .preFirst').css('display', 'block').html(`
  314. <span>${txt}</span>
  315. `)
  316. loadDate();
  317. proFun();
  318. });
  319. }
  320. function proFun(){
  321. $('.productionType ol li').on('click', function () {
  322. dataList.name = '';
  323. dataList.topId = $('.industryList ul li.active').attr('data-id');
  324. $(this).addClass('active').siblings().removeClass('active');
  325. dataList.secondId = $(this).attr('data-id');
  326. if (!dataList.secondId) return;
  327. let txt = $(this).text();
  328. $('.onSelect .next').css('display', 'block').html(`
  329. <span>${txt}</span>
  330. `)
  331. loadDate();
  332. })
  333. }
  334. $('.searchBtn').click(function () {
  335. let val = $('.demandSearch').val();
  336. if (val) {
  337. dataList.name = val;
  338. dataList.topId = '';
  339. dataList.secondId = '';
  340. loadDate();
  341. }
  342. })
  343. /* 提示 */
  344. //提示框渐隐函数
  345. function msg(txt) {
  346. $('.smg').addClass('active');
  347. var lit = $('#msg').val(txt);
  348. setTimeout(function () {
  349. $('.smg').removeClass('active');
  350. $('#msg').val('');
  351. }, 2000)
  352. }
  353. })