123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- // pointExchange/index.js
- const app = getApp();
- import util from '../utils/util.js'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- appAssetsUrl:app.appAssetsUrl,
- tools:[{
- text:'积分任务'
- },{
- text:'积分中心'
- },{
- text:'我的兑换'
- }],
- typeList: [],
- typeListIndex: 0,
- nameListEle: [],
- totalScore: '--',//总积分
- itemData:{
- id:'',
- needScore: '--'
- },
- nodata: util.nodata(),
- params: {
- pageNum: 1,
- pageSize: 10,
- type: ''
- },
- total:{
- currPage: 0,
- totalPage: 0
- },
- noMore:false,
- listData:[],
- navScrollWidth: 0,
- statusBarHeight: 0,
- statusBarMH: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.height();
- this.loadData();
- this.getTypeList();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- //获得popup组件
- this.popup = this.selectComponent("#popup");
- this.popup2 = this.selectComponent("#popup2");
- this.popup3 = this.selectComponent("#popup3");
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.loadData();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- // 自定义高度处理
- height() {
- const { platform, statusBarHeight } = wx.getSystemInfoSync()
- let height = statusBarHeight + 4 //ios 24px
- let mH = statusBarHeight + 4
- if (platform.toLowerCase() == "android") {
- height += 4 //android 28px
- mH += 4
- }
- height = height + 38
- // 胶囊高度 32px 下边框6px height 状态栏高度
- this.setData({
- statusBarHeight: height + 'px',
- statusBarMH: mH + 'px'
- })
- },
- switchType(e) {
- let index = e.currentTarget.dataset.index;
- this.setData({
- typeListIndex: index
- })
- this.scroll(index);
- this.loadList(true);
- },
- back(){
- wx.navigateBack();
- },
- toDatail(e){
- wx.navigateTo({
- url: `/pointExchange/pages/detail/detail?id=${e.currentTarget.dataset.id}&totalScore=${this.data.totalScore}`
- })
- },
- goTool(e){
- let index = e.currentTarget.dataset.index;
- if(index == 0){
- wx.navigateTo({
- url:'/pointExchange/pages/task/task'
- })
- }else if(index == 1){
- wx.navigateTo({
- url:`/pointExchange/pages/center/center?totalScore=${this.data.totalScore}`
- })
- }else if(index == 2){
- wx.navigateTo({
- url:'/pointExchange/pages/my/my'
- })
- }
- },
- getTypeList(){
- let that = this;
- app._post_form('productType/list', '', null,
- function(res) {
- if (res.code == 0) {
- that.setData({
- typeList: res.data
- })
- wx.nextTick(() => {
- let query = wx.createSelectorQuery();
- query.selectAll('.nameitem').boundingClientRect().exec(function (res) {
- let nameListEle = [];
- for(let i in res[0]){
- nameListEle.push(res[0][i].width*1);
- }
- that.setData({
- nameListEle
- })
- })
- })
- that.loadList(true);
- }
- })
- },
- scroll(index){
- let that = this;
- let leftNum = 0;
- if(index>0){
- for(let i in that.data.nameListEle){
- if(i<index){
- leftNum += that.data.nameListEle[i];
- leftNum += (20 / 750 * wx.getSystemInfoSync().windowWidth)
- }
- }
- }
- that.setData({
- navScrollWidth: leftNum
- })
- },
- loadData() {
- let that = this;
- app._post_form('scoreStu/totalScore', '', {
- stuId: util.getUserId()
- },
- function(res) {
- if (res.code == 0) {
- that.setData({
- totalScore: res.data
- })
- }
- })
- },
- bindscrolltolower(){
- this.loadList();
- },
- loadList(isRefresh) {
- let that = this;
- if (!isRefresh && this.data.noMore) {
- wx.showToast({
- title: '没有更多了~',
- icon: 'none'
- })
- return false;
- }
- this.setData({
- listData: isRefresh ? [] : this.data.listData,
- noMore: isRefresh ? false : this.data.noMore,
- params: {
- ...this.data.params,
- pageNum: isRefresh?1:this.data.params.pageNum+1,
- type: this.data.typeList[this.data.typeListIndex].id
- }
- })
- wx.showLoading({
- title: '努力加载中...',
- })
- app._post_form('product/page', '', this.data.params,
- function(res) {
- if (res.code == 0) {
- if(res.page.list.length>0 && that.data.listData.length>0 && res.page.list[0].id == that.data.listData[0].id){
- return ;
- }
- let listData = that.data.listData;
- listData.push(...res.page.list);
- that.setData({
- listData,
- currPage: res.page.currPage,
- totalPage: res.page.totalPage,
- noMore: res.page.totalPage == res.page.currPage
- })
- }
- })
- },
- //弹窗
- showPopup(e) {
- this[e.currentTarget.dataset.name].showPopup();
- this.setData({
- itemData:{
- ...this.data.itemData,
- id: e.currentTarget.dataset.id,
- needScore: e.currentTarget.dataset.needscore
- }
- })
- },
- //取消事件
- _error(e) {
- this[e.currentTarget.dataset.name].hidePopup();
- },
- useCoupon(e) {
- this.popup.hidePopup();
- let that = this;
- wx.showLoading({
- title: '提交中...',
- })
- app._post_form('product/exchange', "", {
- pId: this.data.itemData.id,
- stuId: util.getUserId()
- }, function(res) {
- if (res.code === 0) {
- that.loadData();
- that.popup2.showPopup();
- }
- })
- },
- toPointExchangeByMe(){
- this.popup2.hidePopup();
- wx.navigateTo({
- url:'/pointExchange/pages/my/my'
- })
- }
- })
|