adviserList.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * @author:liting
  3. * @update:2018/09/07
  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/adviserList.css';
  11. import 'js/public.js';
  12. "use strict";
  13. $(function () {
  14. var thePageNo = 1,
  15. thePageLength = 1,
  16. dataList = {},
  17. pageSize = 6;
  18. init();
  19. function init() {
  20. pages();
  21. inpFun();
  22. search();
  23. jump();
  24. };
  25. //一级界面跳转此页面
  26. function jump() {
  27. let hash = window.location.search;
  28. if (hash) {
  29. if (hash.indexOf('name') > -1 || hash.indexOf('topId') > -1 || hash.indexOf('secondId') > -1) {
  30. let newHash = hash.substr(1, hash.length)
  31. if (newHash.indexOf('name') > -1) {
  32. let names = newHash.split('=')
  33. dataList.name = decodeURIComponent(names[1])
  34. $('.demandSearch').val(dataList.name);
  35. }
  36. loadDate()
  37. }
  38. } else {
  39. dataList.name = "",
  40. loadDate();
  41. }
  42. }
  43. function loadDate(pageNo) {
  44. console.log(pageNo)
  45. $('.loading').show();
  46. $.ajax({
  47. method: "get",
  48. dataType: "json",
  49. url: globalConfig.context + "/api/portal/identity/consultantList",
  50. data: {
  51. pageNo: pageNo || 1,
  52. pageSize: pageSize,
  53. name: dataList.name,
  54. sortType:dataList.sortType
  55. },
  56. success: function (data) {
  57. var theArrs = [];
  58. if (data && data.error.length) {
  59. msg(data.error[0].message)
  60. };
  61. if (data.data && data.data.list.length) {
  62. let nub = data.data.list.length;
  63. for (let i = 0; i < nub; i++) {
  64. let thisdata = data.data.list[i],txtCont='';
  65. switch(thisdata.consultantType){
  66. case 0:
  67. txtCont='专利代理人';
  68. break;
  69. case 1:
  70. txtCont='专利顾问';
  71. break;
  72. case 2:
  73. txtCont='版权顾问';
  74. break;
  75. case 3:
  76. txtCont='商标顾问';
  77. break;
  78. default:
  79. txtCont="暂无";
  80. }
  81. theArrs.push(`
  82. <li>
  83. <div>
  84. <a href="${globalConfig.context}/portal/adviser/adviserDetail?id=${thisdata.uid}">
  85. ${thisdata.personPortraitUrl&&thisdata.personPortraitUrl!=null?'<img src="'+globalConfig.avatarHost+'/upload'+thisdata.personPortraitUrl+'"/>':''}
  86. <div class="txt" data-id=${thisdata.uid}>
  87. <div>
  88. <h4>${thisdata.username}<span>${txtCont}</span></h4>
  89. <p><span>好评率 ( ${thisdata.favorableRate} )</span><span class="nubCollect">${thisdata.countInterest}</span>${thisdata.interested?'<span class="heart active"></span>':'<span class="heart"></span>'}</p>
  90. </div>
  91. <p>${thisdata.introduction?thisdata.introduction:'暂无描述'}</p>
  92. </div>
  93. </a>
  94. </div>
  95. </li>
  96. `);
  97. };
  98. };
  99. $('.loading').hide().stop(true, true);
  100. $('.adviserList ul').empty();
  101. $('.adviserList ul').append(theArrs.join(''));
  102. $('.pagination_box').css('display', 'block');
  103. $('.inp').css('display', 'block');
  104. if (data.data.list.length === 0) {
  105. $('.adviserList ul').html("<div class='list_none'></div>");
  106. $('.pagination_box').css('display', 'none');
  107. $('.inp').css('display', 'none');
  108. };
  109. thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
  110. $('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
  111. var pageArr = [],
  112. firstNo = 1,
  113. endNo = 5;
  114. if (thePageNo > 3) {
  115. firstNo = thePageNo - 2;
  116. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  117. } else {
  118. endNo = Math.min(thePageLength, 5);
  119. };
  120. for (let i = firstNo; i <= endNo; i++) {
  121. if (i == thePageNo) {
  122. pageArr.push(
  123. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  124. );
  125. } else {
  126. pageArr.push(
  127. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  128. );
  129. }
  130. };
  131. $('.pageNumber').remove();
  132. $('.pagePre').after(pageArr.join(''));
  133. $('footer').show();
  134. colFun();
  135. }
  136. });
  137. }
  138. //f分页
  139. function pages() {
  140. $('.pagination').on('click', 'li', function (e) {
  141. e.preventDefault();
  142. if (this.className === 'pagePre') {
  143. if (thePageNo > 1) {
  144. thePageNo = 1;
  145. loadDate(thePageNo);
  146. }
  147. } else if (this.className === 'pageNext') {
  148. if (thePageNo < thePageLength) {
  149. thePageNo = thePageLength;
  150. loadDate(thePageNo);
  151. }
  152. } else {
  153. var nextPageNo = $(this).children()[0].text;
  154. if (thePageNo != nextPageNo) {
  155. $(this).siblings("li").removeClass("active");
  156. $(this).addClass("active");
  157. thePageNo = nextPageNo;
  158. loadDate(thePageNo);
  159. };
  160. };
  161. });
  162. }
  163. //输入跳转
  164. function inpFun() {
  165. $('.inp .btn').on('click', function () {
  166. let val = $(this).siblings().val();
  167. if (!isNaN(val) && val <= thePageLength && val > 0) {
  168. thePageNo = val;
  169. loadDate(thePageNo);
  170. } else {
  171. msg('请输入正确页码')
  172. }
  173. })
  174. }
  175. //搜索
  176. function search() {
  177. $('.searchBtn').click(function () {
  178. let val = $('.demandSearch').val();
  179. dataList.name = val;
  180. loadDate();
  181. })
  182. }
  183. /* 提示 */
  184. //提示框渐隐函数
  185. function msg(txt) {
  186. if ($('.smg').hasClass('active')) {
  187. return;
  188. }
  189. $('.smg').addClass('active');
  190. var lit = $('#msg').val(txt);
  191. setTimeout(function () {
  192. $('.smg').removeClass('active')
  193. $('#msg').val('');
  194. }, 2000)
  195. }
  196. //收藏
  197. function colFun(){
  198. $('.txt .heart').click(function (e) {
  199. let loginTxt=$('.head_login')[0];
  200. if(loginTxt&&($(loginTxt).text())=='登录'){
  201. window.location.hash='jump'
  202. msg('请先登录!')
  203. return false;
  204. };
  205. e.preventDefault();
  206. e.stopPropagation();
  207. let nub=parseInt($(this).siblings('.nubCollect').text()),
  208. heart = $(this),
  209. id=$(this).parents('.txt').attr('data-id');
  210. console.log(nub)
  211. if (heart.hasClass('active')) {
  212. $(this).removeClass('active')
  213. $(this).siblings('.nubCollect').text(nub-1);
  214. collectionApi(0,id,nub) //取消关注
  215. } else {
  216. $(this).addClass('active');
  217. $(this).siblings('.nubCollect').text(nub+1);
  218. collectionApi(1,id,nub) //关注
  219. }
  220. })
  221. }
  222. function collectionApi(index,ids,nub) {
  223. let url = index?'/api/user/portal/expertInterest':'/api/user/portal/expertCancelInterest';
  224. $.ajax({
  225. method: "post",
  226. dataType: "json",
  227. url: globalConfig.context + url,
  228. data: {
  229. id:ids
  230. },
  231. success: function (data) {
  232. if (data.error && data.error.length) {
  233. msg(data.error[0].message);
  234. }else{
  235. if(!index){
  236. $('#msg').val('取消关注')
  237. }else{
  238. $('#msg').val('关注成功,请至个人中心-我的关注查看.');
  239. }
  240. msg(index?'关注成功,请至个人中心-我的关注查看.':'取消关注');
  241. }
  242. }
  243. })
  244. }
  245. //排序调用接口
  246. sortFun();
  247. function sortFun(){
  248. $('.sort .relTime').click(function(){
  249. if($(this).hasClass('active')){
  250. $(this).removeClass('active');
  251. dataList.sortType='';
  252. thePageNo=1
  253. loadDate(thePageNo);
  254. }else{
  255. $('.colNumber').removeClass('active')
  256. $(this).addClass('active');
  257. dataList.sortType=0;
  258. thePageNo=1;
  259. loadDate(thePageNo);
  260. }
  261. })
  262. $('.sort .colNumber').click(function(){
  263. if($(this).hasClass('active')){
  264. $(this).removeClass('active');
  265. dataList.sortType='';
  266. thePageNo=1;
  267. loadDate(thePageNo);
  268. }else{
  269. $('.relTime').removeClass('active')
  270. $(this).addClass('active');
  271. dataList.sortType=1;
  272. thePageNo=1;
  273. loadDate(thePageNo);
  274. }
  275. })
  276. }
  277. })