ts_aimz/pages/mine/mineAccount/mineMsgNotice/mineMsgNotice.js
2025-05-13 15:06:17 +08:00

201 lines
6.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/mine/mineAccount/mineMsgNotice/mineMsgNotice.js
import UserApi from '../../../../net/api/userApi'
const app = getApp()
const deviceInfo = wx.getDeviceInfo()
const screenInfo = wx.getWindowInfo();
const statusBarHeight = screenInfo.statusBarHeight; // 状态栏高度
const navBarHeight = deviceInfo.platform == 'IOS' ? 48 : 50; // 导航栏高度iOS 为 44pxAndroid 为 48px
const windowHeight = screenInfo.windowHeight - navBarHeight - statusBarHeight; //可用内容高度
const Cache = require('../../../../utils/storage')
Page({
/**
* 页面的初始数据
*/
data: {
currentStatus: '',
height: windowHeight,
onlyDelBtns: app.globalData.onlyDelBtns,
msgList: [], //订单列表
pageData: {
page: 1,
rows: 10,
isRead: '', //默认已读
}, //检索参数
loadingState: 'loading', //加载状态
listRefreshTrig: false, //list刷新状态
isLoadMore: false, //加载更多的状态
hasMore: true, //是否有更多数据
keywords: '', //搜索关键字
msgType: 'info',
msgHint: '',
msgShow: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '消息通知',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
this.doRefreshList()
},
//tab切换
doChangeStatus(e) {
const value = e.currentTarget.dataset.value
this.setData({
currentStatus: value
})
this.doRefreshList()
},
//下拉刷新
doRefreshList() {
const _self = this
_self.setData({
listRefreshTrig: true,
loadingState: 'loading',
hasMore: true,
'pageData.page': 1,
'pageData.isRead': _self.data.currentStatus,
isLoadMore: false
})
_self.doGetMineMsgNotice(true)
},
//加载更多
doLoadMore() {
//判断是否正在加载中 与是否存在更多数据
const _self = this
if (_self.data.isLoadMore || !_self.data.hasMore) {
return
}
_self.setData({
isLoadMore: true,
'pageData.page': ++_self.data.pageData.page,
'pageData.isRead': _self.data.currentStatus
})
_self.doGetMineMsgNotice(false)
},
//获取我的优惠卷
doGetMineMsgNotice(isRefresh) {
const _self = this
_self.setData({
msgList: isRefresh ? [] : _self.data.msgList,
loadingState: isRefresh ? 'loading' : ''
})
UserApi.doGetMineMsgNotice(_self.data.pageData)
.then(res => {
var status = 'success'
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
_self.setData({
loadingState: isRefresh ? status : '',
msgList: _self.data.msgList.concat(res.rows),
listRefreshTrig: false,
isLoadMore: false
})
_self.setData({
hasMore: _self.data.msgList.length < res.total
})
_self.showEditDel()
}, err => {
_self.setData({
loadingState: 'error',
listRefreshTrig: false,
isLoadMore: false,
hasMore: true
})
})
},
readItem(e) {
const item = e.currentTarget.dataset.value
const _self = this
if (item.isRead == 1) {
return
}
wx.showLoading({
title: '加载中...',
})
const ids = {
ids: [item.userMsgId]
}
UserApi.doReadMineMsgNotice(ids)
.then(res => {
wx.hideLoading()
_self.doRefreshList()
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgHint: err.msg ? err.msg : '读取失败,请稍后重试',
msgType: 'error',
msgShow: true
})
})
},
slideButtonTap(e) {
const item = e.currentTarget.dataset.value
const index = e.detail.index
if (index == 0) {
//显示删除
this.showDel(item)
}
},
showDel(item) {
const _self = this
wx.showModal({
title: '警告',
content: '确定要删除该消息吗?',
complete: (res) => {
if (res.confirm) {
_self.doDelMsg(item)
}
}
})
},
doDelMsg(item) {
const _self = this
wx.showLoading({
title: '删除中...',
})
UserApi.doDeleteMineMsgNotice(item.userMsgId)
.then(res => {
wx.hideLoading()
_self.setData({
msgHint: '删除成功',
msgType: 'success',
msgShow: true
})
_self.doRefreshList()
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgHint: err.msg ? err.msg : '删除失败,请稍后重试',
msgType: 'error',
msgShow: true
})
})
},
showEditDel() {
const _self = this
const isFirst = Cache.get('noticeFirst', '0')
if (isFirst == '0') {
const item = _self.selectComponent('#mp-slide-0')
if (item) {
item.setData({
show: true
})
Cache.set('noticeFirst', '1')
}
}
},
})