123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- const request = require('../../utils/request.js');
- // pages/policyDetail/index.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- nvabarData: {
- showCapsule: 1, //是否显示左上角图标,消息中心 1表示显示 0表示不显示
- showBack: 0, //返回
- title: '政策信息', //导航栏 中间的标题
- // 此页面 页面内容距最顶部的距离
- height: app.globalData.height * 2 + 20,
- },
- currentTab: 0,
- sHeight: '100vh',
- policyPageIndex: 0,
- policyPageSize: 8,
- policyHasMore: true,
- policyUrl: 'api/financial/tPolicyInterpretation',
- unscramblePageIndex: 0,
- unscramblePageSize: 8,
- unscrambleHasMore: true,
- unscrambleUrl: 'api/financial/tPolicyDeclaration/select',
- state: 1,
- policyList: [],
- unscrambleList: [],
- active: 3,
- icon: {
- normal: '/pages/images/home.png',
- active: '/pages/images/home_fill.png',
- bankNormal: '/pages/images/duijie.png',
- bankActive: '/pages/images/duijie_fill.png',
- marketNormal: '/pages/images/recharge.png',
- marketActive: '/pages/images/recharge_fill.png',
- policyNormal: '/pages/images/news_hot.png',
- policyActive: '/pages/images/news_hot_fill.png',
- myNormal: '/pages/images/people.png',
- myActive: '/pages/images/people_fill.png'
- },
- },
- //滑动切换nihao
- swiperTab: function (e) {
- var that = this;
- that.setData({
- currentTab: e.detail.current
- });
- if (this.data.currentTab === 0) {
- let query = wx.createSelectorQuery();
- query.select('#policy').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (that.data.policyList.length) + 'rpx'
- })
- }).exec();
- } else {
- let query = wx.createSelectorQuery();
- query.select('#unscramble').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (that.data.unscrambleList.length) + 'rpx'
- })
- }).exec();
- }
- },
- //点击切换
- clickTab: function (e) {
- var that = this;
- if (this.data.currentTab === e.target.dataset.current) {
- return false;
- } else {
- that.setData({
- currentTab: e.target.dataset.current
- });
- if (this.data.currentTab === 0) {
- let query = wx.createSelectorQuery();
- query.select('#policy').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (that.data.policyList.length) + 'rpx'
- })
- }).exec();
- } else {
- let query = wx.createSelectorQuery();
- query.select('#unscramble').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (that.data.unscrambleList.length) + 'rpx'
- })
- }).exec();
- }
- }
- },
- //政策解读详情
- policyListDetail: function (e) {
- console.log(e.currentTarget.id)
- wx.navigateTo({
- url: '/pages/policyDetail/index?id=' + e.currentTarget.dataset.pid // 希望跳转过去的页面
- })
- },
- // 权威发布详情
- unscrambleListDetail: function (e) {
- wx.navigateTo({
- url: '/pages/unscrambleDetail/index?id=' + e.currentTarget.dataset.unid // 希望跳转过去的页面
- })
- },
- // 切换菜单
- onChange(event) {
- this.setData({
- active: event.detail
- });
- if (event.detail == 0) {
- wx.redirectTo({
- url: '/pages/home/index'
- })
- } else if (event.detail == 1) {
- wx.redirectTo({
- url: '/pages/bank/index'
- })
- } else if (event.detail == 2) {
- wx.redirectTo({
- url: '/pages/market/index'
- })
- } else if (event.detail == 3) {
- wx.redirectTo({
- url: '/pages/policy/index'
- })
- } else if (event.detail == 4) {
- wx.redirectTo({
- url: '/pages/my/index'
- })
- }
- },
- getDate(val, formatStr) {
- if (val) {
- return this.format(new Date(Number(val)), formatStr);
- }
- return '';
- },
- format(date, formatStr) {
- formatStr = formatStr.replace(/yyyy|YYYY/, date.getFullYear());
- formatStr = formatStr.replace(/MM/, (date.getMonth() + 1) > 9 ? (date.getMonth() + 1).toString() : '0' + (date.getMonth() + 1));
- formatStr = formatStr.replace(/dd|DD/, date.getDate() > 9 ? date.getDate().toString() : '0' + date.getDate());
- return formatStr;
- },
- loadMore: function () {
- if (this.data.currentTab === 0) {
- if (!this.data.policyHasMore) return;
- request.query({
- url: this.data.policyUrl,
- data: {
- skip: (++this.data.policyPageIndex - 1) * this.data.policyPageSize,
- limit: this.data.policyPageSize
- }
- }).then((res) => {
- let temp = res.data.data.map((item) => {
- if (item.image) {
- item.image = request.imageUrl + item.image
- }
- if (item.create_time) {
- item.create_time = this.getDate(item.create_time, 'yyyy.MM.dd')
- }
- return item;
- });
- let newList = this.data.policyList.concat(temp);
- let flag = this.data.policyPageIndex * this.data.policyPageSize < res.data.total;
- let query = wx.createSelectorQuery();
- let that = this;
- query.select('#policy').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (newList.length) + 'rpx'
- })
- }).exec();
- this.setData({
- policyList: newList,
- policyHasMore: flag,
- });
- }).catch((err) => {
- });
- } else {
- if (!this.data.unscrambleHasMore) return;
- request.query({
- url: this.data.unscrambleUrl,
- data: {
- skip: (++this.data.unscramblePageIndex - 1) * this.data.unscramblePageSize,
- limit: this.data.unscramblePageSize,
- current_state: this.data.state
- }
- }).then((res) => {
- let temp = res.data.data.map((item) => {
- if (item.image) {
- item.image = request.imageUrl + item.image
- }
- return item;
- });
- let newList = this.data.unscrambleList.concat(temp);
- let flag = this.data.unscramblePageIndex * this.data.unscramblePageSize < res.data.total;
- let query = wx.createSelectorQuery();
- let that = this;
- query.select('#unscramble').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (newList.length) + 'rpx'
- })
- }).exec();
- this.setData({
- unscrambleList: newList,
- unscrambleHasMore: flag,
- });
- }).catch((err) => {});
- }
- },
- loadPolicyFirst: function () {
- request.query({
- url: this.data.policyUrl,
- data: {
- skip: (++this.data.policyPageIndex - 1) * this.data.policyPageSize,
- limit: this.data.policyPageSize
- }
- }).then((res) => {
- let temp = res.data.data.map((item) => {
- if (item.image) {
- item.image = request.imageUrl + item.image
- }
- if (item.create_time) {
- item.create_time = this.getDate(item.create_time, 'yyyy.MM.dd')
- }
- return item;
- });
- let newList = this.data.policyList.concat(temp);
- let flag = this.data.policyPageIndex * this.data.policyPageSize < res.data.total;
- let query = wx.createSelectorQuery();
- let that = this;
- query.select('#policy').boundingClientRect(function (rect) {
- that.setData({
- sHeight: 105+180 * (newList.length) + 'rpx'
- })
- }).exec();
- this.setData({
- policyList: newList,
- policyHasMore: flag,
- });
- }).catch((err) => {});
- },
- loadUnscrambleFirst: function () {
- request.query({
- url: this.data.unscrambleUrl,
- data: {
- skip: (++this.data.unscramblePageIndex - 1) * this.data.unscramblePageSize,
- limit: this.data.unscramblePageSize,
- current_state: this.data.state
- }
- }).then((res) => {
- let temp = res.data.data.map((item) => {
- if (item.image) {
- item.image = request.imageUrl + item.image
- }
- return item;
- });
- let newList = this.data.unscrambleList.concat(temp);
- let flag = this.data.unscramblePageIndex * this.data.unscramblePageSize < res.data.total;
- this.setData({
- unscrambleList: newList,
- unscrambleHasMore: flag,
- });
- }).catch((err) => {});
- },
- loadMoreFirst: function () {
- this.loadPolicyFirst();
- this.loadUnscrambleFirst();
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.loadMoreFirst();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- if (this.data.currentTab === 0) {
- this.setData({
- policyList: [],
- policyPageIndex: 0,
- policyHasMore: true,
- });
- } else {
- this.setData({
- unscrambleList: [],
- unscramblePageIndex: 0,
- unscrambleHasMore: true,
- });
- }
- this.loadMore();
- wx.stopPullDownRefresh();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.loadMore();
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|