xszp.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. new Vue({
  2. el: '#xszp',
  3. data() {
  4. return {
  5. userInfo: {},
  6. worksList: [],
  7. ks_id: '',
  8. ks_name:'',
  9. cur_page: '1',
  10. total_page:0,
  11. isOver:false
  12. }
  13. },
  14. methods: {
  15. getZpList() {
  16. let data = {
  17. api: 'json',
  18. token: this.userInfo.token,
  19. ks_id: this.ks_id,
  20. page: this.cur_page,
  21. limit: '10'
  22. }
  23. const requestURL = 'https://tyyxopenapi.txhlwxx.com/ysgc/zp/index';
  24. axios({
  25. method: 'POST',
  26. url: requestURL,
  27. data: Qs.stringify(data),
  28. headers: {
  29. "Content-Type": 'application/x-www-form-urlencoded;charset=UTF-8'
  30. }
  31. }).then(res => {
  32. if (res.data.code == 1) {
  33. this.ks_name = res.data.template.ks_name;
  34. this.worksList = res.data.data.page_data;
  35. this.cur_page = res.data.data.page_now;
  36. this.total_page = res.data.data.total_page;
  37. }
  38. })
  39. },
  40. list_scroll() {
  41. $(window).on("resize scroll", ()=> {
  42. var windowHeight = $(window).height();//当前窗口的高度
  43. var scrollTop = $(window).scrollTop();//当前滚动条从上往下滚动的距离
  44. var docHeight = $(document).height(); //当前文档的高度
  45. //当 滚动条距底部的距离 + 滚动条滚动的距离 >= 文档的高度 - 窗口的高度
  46. //换句话说:(滚动条滚动的距离 + 窗口的高度 = 文档的高度) 这个是基本的公式
  47. if (scrollTop + windowHeight >= docHeight) {
  48. if (this.cur_page < this.total_page) {
  49. this.cur_page ++;
  50. let data = {
  51. api: 'json',
  52. token: this.userInfo.token,
  53. ks_id: this.ks_id,
  54. page: this.cur_page,
  55. limit: '10'
  56. }
  57. const requestURL = 'https://tyyxopenapi.txhlwxx.com/ysgc/zp/index';
  58. axios({
  59. method: 'POST',
  60. url: requestURL,
  61. data: Qs.stringify(data),
  62. headers: {
  63. "Content-Type": 'application/x-www-form-urlencoded;charset=UTF-8'
  64. }
  65. }).then(res => {
  66. if (res.data.code == 1) {
  67. this.ks_name = res.data.template.ks_name;
  68. this.worksList = this.worksList.concat(res.data.data.page_data);
  69. this.cur_page = res.data.data.page_now;
  70. this.total_page = res.data.data.total_page;
  71. this.isOver = false;
  72. }
  73. })
  74. } else {
  75. this.isOver = true;
  76. }
  77. }
  78. });
  79. },
  80. },
  81. mounted() {
  82. if (localStorage.getItem('userInfo')) {
  83. this.userInfo = JSON.parse(localStorage.getItem('userInfo'));
  84. }
  85. if (location.search.includes('ks_id')) {
  86. this.ks_id = location.search.substring(7);
  87. this.getZpList();
  88. this.list_scroll();
  89. }
  90. }
  91. })