Browse Source

no message

feature/v1.2
xpz2018 5 years ago
parent
commit
305df50cd8
4 changed files with 26 additions and 48 deletions
  1. 6
      app.js
  2. 50
      pages/message/index/index.js
  3. 1
      pages/message/index/index.wxml
  4. 17
      pages/message/notification/index.js

6
app.js

@ -5,12 +5,14 @@ App({
version: 152, version: 152,
xAppId: '503258978847953926', xAppId: '503258978847953926',
userInfo: null, userInfo: null,
msgIdList: [],
//----------------------------------------------globalData-------------------------------------- //----------------------------------------------globalData--------------------------------------
globalData: { globalData: {
token: null, token: null,
agenting: 1, agenting: 1,
keyboardHeight: 0, keyboardHeight: 0,
isIos: false
isIos: false,
msgIdList: [],
msgNumber: 0
} }
}) })

50
pages/message/index/index.js

@ -1,4 +1,4 @@
// import { getCategoryList, getProductList } from "../../api/mall"
import { getMessageList } from "../../../api/saas"
const event = require('../../../utils/event') const event = require('../../../utils/event')
const util = require('../../../utils/util') const util = require('../../../utils/util')
const app = getApp() const app = getApp()
@ -13,21 +13,18 @@ Component({
*/ */
data: { data: {
height: app.globalData.safeFragmentHeight - 100, height: app.globalData.safeFragmentHeight - 100,
CustomBar: app.globalData.CustomBar,
userInfo: null, userInfo: null,
firstShow: false, firstShow: false,
tabIndex: 0,
tabList: [],
loading: false, loading: false,
requesting: false, requesting: false,
finished: false, finished: false,
top: 0, top: 0,
orderList: [], orderList: [],
form: { categoryId: '', pageNum: 1, pageSize: 10 }
form: { productType: 'ZTB_FACTORY', pageNum: 1, pageSize: 10 }
}, },
lifetimes: { lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () { attached: function () {
this.setData({ height: app.globalData.safeFragmentHeight - 100 })
event.on('EventMessage', this, this.onEvent) event.on('EventMessage', this, this.onEvent)
}, },
detached: function () { detached: function () {
@ -39,32 +36,17 @@ Component({
if (this.data.firstShow) { if (this.data.firstShow) {
return return
} }
this.setData({ height: app.globalData.safeFragmentHeight - 100, CustomBar: app.globalData.CustomBar })
// this.fetchCategoryList()
// this.fetchList()
this.fetchList()
this.data.firstShow = true this.data.firstShow = true
}, },
onEvent: function (message) { onEvent: function (message) {
if (message.what == 888) { if (message.what == 888) {
this.setData({ userInfo: app.accountInfo }) this.setData({ userInfo: app.accountInfo })
} }
},
fetchCategoryList: function(){
getCategoryList().then(result => {
this.setData({ tabList: [{id: '', name: '全部'}].concat(result.data) })
})
},
onTabChange: function ({detail}) {
if (this.data.tabIndex == Number(detail.index)) {
return
}
this.setData({ tabIndex: detail.index})
this.data.form.categoryId = this.data.tabList[this.data.tabIndex].id
this.onRefreshList()
}, },
onRefreshList: function () { onRefreshList: function () {
// this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false })
// this.fetchList()
this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false })
this.fetchList()
}, },
fetchList: function () { fetchList: function () {
if (this.data.requesting || this.data.finished) { if (this.data.requesting || this.data.finished) {
@ -75,35 +57,21 @@ Component({
} else { } else {
this.setData({ requesting: true }) this.setData({ requesting: true })
} }
getProductList(this.data.form).then(result => {
getMessageList(this.data.form).then(result => {
if (result.data.records.length) { if (result.data.records.length) {
var respList = result.data.records var respList = result.data.records
let nowList = `orderList[${this.data.orderList.length}]` let nowList = `orderList[${this.data.orderList.length}]`
var num = this.data.form.pageNum var num = this.data.form.pageNum
var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total
if(this.data.form.pageNum == 1){ if(this.data.form.pageNum == 1){
this.setData({
[nowList]: respList,
['form.pageNum']: (num + 1),
top: 0,
finished,
requesting: false,
loading: false
})
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false })
} else { } else {
this.setData({
[nowList]: respList,
['form.pageNum']: (num + 1),
finished,
requesting: false,
loading: false
})
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
} }
} else { } else {
this.setData({ finished: true, requesting: false, loading: false }) this.setData({ finished: true, requesting: false, loading: false })
} }
}).catch(err => { }).catch(err => {
//异常回调
this.setData({ requesting: false, loading: false }) this.setData({ requesting: false, loading: false })
util.showToast(err) util.showToast(err)
}) })

1
pages/message/index/index.wxml

@ -4,7 +4,6 @@
</cu-custom> </cu-custom>
<refresh-view bind:refresh="onRefreshList" height="{{height}}" triggered="{{requesting}}" scrollTop="{{top}}" bind:scrolltolower="fetchList"> <refresh-view bind:refresh="onRefreshList" height="{{height}}" triggered="{{requesting}}" scrollTop="{{top}}" bind:scrolltolower="fetchList">
<!-- <van-search disabled shape="round" placeholder="请输入要搜索的商品" bindtap="searchList"/> -->
<view class="list-empty" style="height:{{height}}rpx" wx:if="{{!orderList.length}}"> <view class="list-empty" style="height:{{height}}rpx" wx:if="{{!orderList.length}}">
<view style="margin-bottom:24px" wx:if="{{loading}}"> <view style="margin-bottom:24px" wx:if="{{loading}}">
<van-loading type="spinner" size="32" /> <van-loading type="spinner" size="32" />

17
pages/message/notification/index.js

@ -12,12 +12,12 @@ Component({
StatusBar: app.globalData.StatusBar, StatusBar: app.globalData.StatusBar,
CustomBar: app.globalData.CustomBar, CustomBar: app.globalData.CustomBar,
notice: false, notice: false,
message: null
message: null,
numb: 0
}, },
lifetimes: { lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () { attached: function () {
this.setData({ StatusBar: app.globalData.StatusBar || 40, CustomBar: app.globalData.CustomBar || (app.globalData.isIos ? 64 : 60), })
this.setData({ StatusBar: app.globalData.StatusBar, CustomBar: app.globalData.CustomBar })
} }
}, },
methods: { methods: {
@ -25,6 +25,15 @@ Component({
if(this.data.notice){ if(this.data.notice){
return return
} }
var index = app.globalData.msgIdList.indexOf(message.id)
if(index >= 0){
app.globalData.msgNumber += 1
if(app.globalData.msgNumber >= 60){
app.globalData.msgIdList.splice(index, 1);
}
return
}
app.globalData.msgNumber = 0
this.setData({ notice: true, message }) this.setData({ notice: true, message })
}, },
submit: function(e){ submit: function(e){
@ -32,7 +41,7 @@ Component({
return return
} }
if(util.isEmpty(e.currentTarget.id)){ if(util.isEmpty(e.currentTarget.id)){
app.globalData.msgIdList.push(this.data.message.id)
this.setData({ notice: false }) this.setData({ notice: false })
return return
} }

Loading…
Cancel
Save