index.js 8.9 KB

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