index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. const request = require('../../utils/request.js');
  2. // pages/policyDetail/index.js
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. nvabarData: {
  10. showCapsule: 1, //是否显示左上角图标,消息中心 1表示显示 0表示不显示
  11. showBack: 0, //返回
  12. title: '政策信息', //导航栏 中间的标题
  13. // 此页面 页面内容距最顶部的距离
  14. height: app.globalData.height * 2 + 20,
  15. },
  16. currentTab: 0,
  17. policyPageIndex: 0,
  18. policyPageSize: 6,
  19. policyHasMore: true,
  20. policyUrl: 'api/financial/tPolicyInterpretation/select',
  21. unscramblePageIndex: 0,
  22. unscramblePageSize: 6,
  23. unscrambleHasMore: true,
  24. unscrambleUrl: 'api/financial/tPolicyDeclaration/select',
  25. state: 1,
  26. policyList: [],
  27. unscrambleList: [],
  28. active: 3,
  29. icon: {
  30. normal: '/pages/images/home.png',
  31. active: '/pages/images/home_fill.png',
  32. bankNormal: '/pages/images/duijie.png',
  33. bankActive: '/pages/images/duijie_fill.png',
  34. marketNormal: '/pages/images/recharge.png',
  35. marketActive: '/pages/images/recharge_fill.png',
  36. policyNormal: '/pages/images/news_hot.png',
  37. policyActive: '/pages/images/news_hot_fill.png',
  38. myNormal: '/pages/images/people.png',
  39. myActive: '/pages/images/people_fill.png'
  40. },
  41. },
  42. //滑动切换nihao
  43. swiperTab: function (e) {
  44. var that = this;
  45. that.setData({
  46. currentTab: e.detail.current
  47. });
  48. },
  49. policyListDetail: function (e) {
  50. console.log(e.currentTarget.id)
  51. wx.navigateTo({
  52. url: '/pages/policyDetail/index?id=' + e.currentTarget.dataset.pid // 希望跳转过去的页面
  53. })
  54. },
  55. /*// 无id,模拟数据跳转
  56. policyListDetail: function () {
  57. wx.navigateTo({
  58. url: '/pages/policyDetail/index'
  59. })
  60. },*/
  61. unscrambleListDetail: function (e) {
  62. wx.navigateTo({
  63. url: '/pages/unscrambleDetail/index?id=' + e.currentTarget.dataset.unid // 希望跳转过去的页面
  64. })
  65. },
  66. /*// 无id,模拟数据跳转
  67. unscrambleListDetail: function () {
  68. wx.navigateTo({
  69. url: '/pages/unscrambleDetail/index'
  70. })
  71. },*/
  72. //点击切换
  73. clickTab: function (e) {
  74. var that = this;
  75. if (this.data.currentTab === e.target.dataset.current) {
  76. return false;
  77. } else {
  78. that.setData({
  79. currentTab: e.target.dataset.current
  80. })
  81. }
  82. },
  83. // 切换菜单
  84. onChange(event) {
  85. this.setData({
  86. active: event.detail
  87. });
  88. if (event.detail == 0) {
  89. wx.navigateTo({
  90. url: '/pages/home/index'
  91. })
  92. } else if (event.detail == 1) {
  93. wx.navigateTo({
  94. url: '/pages/bank/index'
  95. })
  96. } else if (event.detail == 2) {
  97. wx.navigateTo({
  98. url: '/pages/market/index'
  99. })
  100. } else if (event.detail == 3) {
  101. wx.navigateTo({
  102. url: '/pages/policy/index'
  103. })
  104. } else if (event.detail == 4) {
  105. wx.navigateTo({
  106. url: '/pages/my/index'
  107. })
  108. }
  109. },
  110. loadMore: function () {
  111. if(this.data.currentTab === 0){
  112. if (!this.data.policyHasMore) return;
  113. request.query({
  114. url: this.data.policyUrl,
  115. data: {
  116. skip: (++this.data.policyPageIndex - 1) * this.data.policyPageSize,
  117. limit: this.data.policyPageSize,
  118. publish_state: this.data.state
  119. }
  120. }).then((res) => {
  121. let temp = res.data.data.map((item) => {
  122. if (item.image) {
  123. item.image = request.imageUrl + item.image
  124. }
  125. return item;
  126. });
  127. console.log(res);
  128. let newList = this.data.policyList.concat(temp);
  129. console.log(newList);
  130. console.log(res.data.total);
  131. let flag = this.data.policyPageIndex * this.data.policyPageSize < res.data.total;
  132. this.setData({
  133. policyList: newList,
  134. policyHasMore: flag,
  135. });
  136. }).catch((err) => {
  137. console.log(err);
  138. });
  139. }else {
  140. if (!this.data.unscrambleHasMore) return;
  141. request.query({
  142. url: this.data.unscrambleUrl,
  143. data: {
  144. skip: (++this.data.unscramblePageIndex - 1) * this.data.unscramblePageSize,
  145. limit: this.data.unscramblePageSize,
  146. current_state: this.data.state
  147. }
  148. }).then((res) => {
  149. let temp = res.data.data.map((item) => {
  150. if (item.image) {
  151. item.image = request.imageUrl + item.image
  152. }
  153. return item;
  154. });
  155. console.log(res);
  156. let newList = this.data.unscrambleList.concat(temp);
  157. console.log(newList);
  158. console.log(res.data.total);
  159. let flag = this.data.unscramblePageIndex * this.data.unscramblePageSize < res.data.total;
  160. this.setData({
  161. unscrambleList: newList,
  162. unscrambleHasMore: flag,
  163. });
  164. }).catch((err) => {
  165. console.log(err);
  166. });
  167. }
  168. },
  169. loadPolicyFirst: function () {
  170. request.query({
  171. url: this.data.policyUrl,
  172. data: {
  173. skip: (++this.data.policyPageIndex - 1) * this.data.policyPageSize,
  174. limit: this.data.policyPageSize,
  175. publish_state: this.data.state
  176. }
  177. }).then((res) => {
  178. let temp = res.data.data.map((item) => {
  179. if (item.image) {
  180. item.image = request.imageUrl + item.image
  181. }
  182. return item;
  183. });
  184. console.log(res);
  185. let newList = this.data.policyList.concat(temp);
  186. console.log(newList);
  187. console.log(res.data.total);
  188. let flag = this.data.policyPageIndex * this.data.policyPageSize < res.data.total;
  189. this.setData({
  190. policyList: newList,
  191. policyHasMore: flag,
  192. });
  193. }).catch((err) => {
  194. console.log(err);
  195. });
  196. },
  197. loadUnscrambleFirst: function () {
  198. request.query({
  199. url: this.data.unscrambleUrl,
  200. data: {
  201. skip: (++this.data.unscramblePageIndex - 1) * this.data.unscramblePageSize,
  202. limit: this.data.unscramblePageSize,
  203. current_state: this.data.state
  204. }
  205. }).then((res) => {
  206. let temp = res.data.data.map((item) => {
  207. if (item.image) {
  208. item.image = request.imageUrl + item.image
  209. }
  210. return item;
  211. });
  212. console.log(res);
  213. let newList = this.data.unscrambleList.concat(temp);
  214. console.log(newList);
  215. console.log(res.data.total);
  216. let flag = this.data.unscramblePageIndex * this.data.unscramblePageSize < res.data.total;
  217. this.setData({
  218. unscrambleList: newList,
  219. unscrambleHasMore: flag,
  220. });
  221. }).catch((err) => {
  222. console.log(err);
  223. });
  224. },
  225. loadMoreFirst: function () {
  226. this.loadPolicyFirst();
  227. this.loadUnscrambleFirst();
  228. },
  229. /**
  230. * 生命周期函数--监听页面加载
  231. */
  232. onLoad: function (options) {
  233. this.loadMoreFirst();
  234. },
  235. /**
  236. * 生命周期函数--监听页面初次渲染完成
  237. */
  238. onReady: function () {
  239. },
  240. /**
  241. * 生命周期函数--监听页面显示
  242. */
  243. onShow: function () {
  244. },
  245. /**
  246. * 生命周期函数--监听页面隐藏
  247. */
  248. onHide: function () {
  249. },
  250. /**
  251. * 生命周期函数--监听页面卸载
  252. */
  253. onUnload: function () {
  254. },
  255. /**
  256. * 页面相关事件处理函数--监听用户下拉动作
  257. */
  258. onPullDownRefresh: function () {
  259. console.log("下拉事件");
  260. if(this.data.currentTab === 0){
  261. this.setData({
  262. policyList:[],
  263. policyPageIndex:0,
  264. policyHasMore:true,
  265. });
  266. }else {
  267. this.setData({
  268. unscrambleList:[],
  269. unscramblePageIndex:0,
  270. unscrambleHasMore:true,
  271. });
  272. }
  273. this.loadMore();
  274. wx.stopPullDownRefresh();
  275. },
  276. /**
  277. * 页面上拉触底事件的处理函数
  278. */
  279. onReachBottom: function () {
  280. this.loadMore();
  281. },
  282. /**
  283. * 用户点击右上角分享
  284. */
  285. onShareAppMessage: function () {
  286. }
  287. })