index.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. sHeight: '100vh',
  18. policyPageIndex: 0,
  19. policyPageSize: 8,
  20. policyHasMore: true,
  21. policyUrl: 'api/financial/tPolicyInterpretation',
  22. unscramblePageIndex: 0,
  23. unscramblePageSize: 8,
  24. unscrambleHasMore: true,
  25. unscrambleUrl: 'api/financial/tPolicyDeclaration/select',
  26. state: 1,
  27. policyList: [],
  28. unscrambleList: [],
  29. active: 3,
  30. icon: {
  31. normal: '/pages/images/home.png',
  32. active: '/pages/images/home_fill.png',
  33. bankNormal: '/pages/images/duijie.png',
  34. bankActive: '/pages/images/duijie_fill.png',
  35. marketNormal: '/pages/images/recharge.png',
  36. marketActive: '/pages/images/recharge_fill.png',
  37. policyNormal: '/pages/images/news_hot.png',
  38. policyActive: '/pages/images/news_hot_fill.png',
  39. myNormal: '/pages/images/people.png',
  40. myActive: '/pages/images/people_fill.png'
  41. },
  42. },
  43. //滑动切换nihao
  44. swiperTab: function (e) {
  45. var that = this;
  46. that.setData({
  47. currentTab: e.detail.current
  48. });
  49. if (this.data.currentTab === 0) {
  50. let query = wx.createSelectorQuery();
  51. query.select('#policy').boundingClientRect(function (rect) {
  52. that.setData({
  53. sHeight: 105+180 * (that.data.policyList.length) + 'rpx'
  54. })
  55. }).exec();
  56. } else {
  57. let query = wx.createSelectorQuery();
  58. query.select('#unscramble').boundingClientRect(function (rect) {
  59. that.setData({
  60. sHeight: 105+180 * (that.data.unscrambleList.length) + 'rpx'
  61. })
  62. }).exec();
  63. }
  64. },
  65. //点击切换
  66. clickTab: function (e) {
  67. var that = this;
  68. if (this.data.currentTab === e.target.dataset.current) {
  69. return false;
  70. } else {
  71. that.setData({
  72. currentTab: e.target.dataset.current
  73. });
  74. if (this.data.currentTab === 0) {
  75. let query = wx.createSelectorQuery();
  76. query.select('#policy').boundingClientRect(function (rect) {
  77. that.setData({
  78. sHeight: 105+180 * (that.data.policyList.length) + 'rpx'
  79. })
  80. }).exec();
  81. } else {
  82. let query = wx.createSelectorQuery();
  83. query.select('#unscramble').boundingClientRect(function (rect) {
  84. that.setData({
  85. sHeight: 105+180 * (that.data.unscrambleList.length) + 'rpx'
  86. })
  87. }).exec();
  88. }
  89. }
  90. },
  91. //政策解读详情
  92. policyListDetail: function (e) {
  93. console.log(e.currentTarget.id)
  94. wx.navigateTo({
  95. url: '/pages/policyDetail/index?id=' + e.currentTarget.dataset.pid // 希望跳转过去的页面
  96. })
  97. },
  98. // 权威发布详情
  99. unscrambleListDetail: function (e) {
  100. wx.navigateTo({
  101. url: '/pages/unscrambleDetail/index?id=' + e.currentTarget.dataset.unid // 希望跳转过去的页面
  102. })
  103. },
  104. // 切换菜单
  105. onChange(event) {
  106. this.setData({
  107. active: event.detail
  108. });
  109. if (event.detail == 0) {
  110. wx.redirectTo({
  111. url: '/pages/home/index'
  112. })
  113. } else if (event.detail == 1) {
  114. wx.redirectTo({
  115. url: '/pages/bank/index'
  116. })
  117. } else if (event.detail == 2) {
  118. wx.redirectTo({
  119. url: '/pages/market/index'
  120. })
  121. } else if (event.detail == 3) {
  122. wx.redirectTo({
  123. url: '/pages/policy/index'
  124. })
  125. } else if (event.detail == 4) {
  126. wx.redirectTo({
  127. url: '/pages/my/index'
  128. })
  129. }
  130. },
  131. getDate(val, formatStr) {
  132. if (val) {
  133. return this.format(new Date(Number(val)), formatStr);
  134. }
  135. return '';
  136. },
  137. format(date, formatStr) {
  138. formatStr = formatStr.replace(/yyyy|YYYY/, date.getFullYear());
  139. formatStr = formatStr.replace(/MM/, (date.getMonth() + 1) > 9 ? (date.getMonth() + 1).toString() : '0' + (date.getMonth() + 1));
  140. formatStr = formatStr.replace(/dd|DD/, date.getDate() > 9 ? date.getDate().toString() : '0' + date.getDate());
  141. return formatStr;
  142. },
  143. loadMore: function () {
  144. if (this.data.currentTab === 0) {
  145. if (!this.data.policyHasMore) return;
  146. request.query({
  147. url: this.data.policyUrl,
  148. data: {
  149. skip: (++this.data.policyPageIndex - 1) * this.data.policyPageSize,
  150. limit: this.data.policyPageSize
  151. }
  152. }).then((res) => {
  153. let temp = res.data.data.map((item) => {
  154. if (item.image) {
  155. item.image = request.imageUrl + item.image
  156. }
  157. if (item.create_time) {
  158. item.create_time = this.getDate(item.create_time, 'yyyy.MM.dd')
  159. }
  160. return item;
  161. });
  162. let newList = this.data.policyList.concat(temp);
  163. let flag = this.data.policyPageIndex * this.data.policyPageSize < res.data.total;
  164. let query = wx.createSelectorQuery();
  165. let that = this;
  166. query.select('#policy').boundingClientRect(function (rect) {
  167. that.setData({
  168. sHeight: 105+180 * (newList.length) + 'rpx'
  169. })
  170. }).exec();
  171. this.setData({
  172. policyList: newList,
  173. policyHasMore: flag,
  174. });
  175. }).catch((err) => {
  176. });
  177. } else {
  178. if (!this.data.unscrambleHasMore) return;
  179. request.query({
  180. url: this.data.unscrambleUrl,
  181. data: {
  182. skip: (++this.data.unscramblePageIndex - 1) * this.data.unscramblePageSize,
  183. limit: this.data.unscramblePageSize,
  184. current_state: this.data.state
  185. }
  186. }).then((res) => {
  187. let temp = res.data.data.map((item) => {
  188. if (item.image) {
  189. item.image = request.imageUrl + item.image
  190. }
  191. return item;
  192. });
  193. let newList = this.data.unscrambleList.concat(temp);
  194. let flag = this.data.unscramblePageIndex * this.data.unscramblePageSize < res.data.total;
  195. let query = wx.createSelectorQuery();
  196. let that = this;
  197. query.select('#unscramble').boundingClientRect(function (rect) {
  198. that.setData({
  199. sHeight: 105+180 * (newList.length) + 'rpx'
  200. })
  201. }).exec();
  202. this.setData({
  203. unscrambleList: newList,
  204. unscrambleHasMore: flag,
  205. });
  206. }).catch((err) => {});
  207. }
  208. },
  209. loadPolicyFirst: function () {
  210. request.query({
  211. url: this.data.policyUrl,
  212. data: {
  213. skip: (++this.data.policyPageIndex - 1) * this.data.policyPageSize,
  214. limit: this.data.policyPageSize
  215. }
  216. }).then((res) => {
  217. let temp = res.data.data.map((item) => {
  218. if (item.image) {
  219. item.image = request.imageUrl + item.image
  220. }
  221. if (item.create_time) {
  222. item.create_time = this.getDate(item.create_time, 'yyyy.MM.dd')
  223. }
  224. return item;
  225. });
  226. let newList = this.data.policyList.concat(temp);
  227. let flag = this.data.policyPageIndex * this.data.policyPageSize < res.data.total;
  228. let query = wx.createSelectorQuery();
  229. let that = this;
  230. query.select('#policy').boundingClientRect(function (rect) {
  231. that.setData({
  232. sHeight: 105+180 * (newList.length) + 'rpx'
  233. })
  234. }).exec();
  235. this.setData({
  236. policyList: newList,
  237. policyHasMore: flag,
  238. });
  239. }).catch((err) => {});
  240. },
  241. loadUnscrambleFirst: function () {
  242. request.query({
  243. url: this.data.unscrambleUrl,
  244. data: {
  245. skip: (++this.data.unscramblePageIndex - 1) * this.data.unscramblePageSize,
  246. limit: this.data.unscramblePageSize,
  247. current_state: this.data.state
  248. }
  249. }).then((res) => {
  250. let temp = res.data.data.map((item) => {
  251. if (item.image) {
  252. item.image = request.imageUrl + item.image
  253. }
  254. return item;
  255. });
  256. let newList = this.data.unscrambleList.concat(temp);
  257. let flag = this.data.unscramblePageIndex * this.data.unscramblePageSize < res.data.total;
  258. this.setData({
  259. unscrambleList: newList,
  260. unscrambleHasMore: flag,
  261. });
  262. }).catch((err) => {});
  263. },
  264. loadMoreFirst: function () {
  265. this.loadPolicyFirst();
  266. this.loadUnscrambleFirst();
  267. },
  268. /**
  269. * 生命周期函数--监听页面加载
  270. */
  271. onLoad: function (options) {
  272. this.loadMoreFirst();
  273. },
  274. /**
  275. * 生命周期函数--监听页面初次渲染完成
  276. */
  277. onReady: function () {},
  278. /**
  279. * 生命周期函数--监听页面显示
  280. */
  281. onShow: function () {
  282. },
  283. /**
  284. * 生命周期函数--监听页面隐藏
  285. */
  286. onHide: function () {
  287. },
  288. /**
  289. * 生命周期函数--监听页面卸载
  290. */
  291. onUnload: function () {
  292. },
  293. /**
  294. * 页面相关事件处理函数--监听用户下拉动作
  295. */
  296. onPullDownRefresh: function () {
  297. if (this.data.currentTab === 0) {
  298. this.setData({
  299. policyList: [],
  300. policyPageIndex: 0,
  301. policyHasMore: true,
  302. });
  303. } else {
  304. this.setData({
  305. unscrambleList: [],
  306. unscramblePageIndex: 0,
  307. unscrambleHasMore: true,
  308. });
  309. }
  310. this.loadMore();
  311. wx.stopPullDownRefresh();
  312. },
  313. /**
  314. * 页面上拉触底事件的处理函数
  315. */
  316. onReachBottom: function () {
  317. this.loadMore();
  318. },
  319. /**
  320. * 用户点击右上角分享
  321. */
  322. onShareAppMessage: function () {
  323. }
  324. })