123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <view class="container main">
- <view class="one" v-if="total>0">
- <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-view" @scrolltolower="toPage"
- @scroll="toScroll">
- <view class="list-scroll-view">
- <view class="list" v-for="(item, index) in list" :key="index">
- <view class="value">
- <view class="title">内容:</view>
- <view class="label"> <text :user-select="true">{{item.content||'暂无'}}</text> </view>
- </view>
- <view class="value">
- <view class="title">通知类型:</view>
- <view class="label">{{getDict(item.type,'type')||'暂无'}}</view>
- </view>
- <view class="value">
- <view class="title">是否已读:</view>
- <view class="label">{{getDict(item,'is_read')||'暂无'}}</view>
- </view>
- <view class="value">
- <view class="title">发送时间:</view>
- <view class="label">{{item.created_time||'暂无'}}</view>
- </view>
- <view class="bottom">
- <button v-if="getDict(item, 'is_read') == '未读'" class="button button_2" type="default"
- size="mini" @tap.stop="toRead(item)">已读</button>
- </view>
- </view>
- <view class="is_bottom" v-if="is_bottom">
- <text>{{config.bottom_title||'到底了!'}}</text>
- </view>
- </view>
- </scroll-view>
- </view>
- <o-empty v-else />
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- user: {},
- config: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 5,
- page: 0,
- // 数据是否触底
- is_bottom: false,
- scrollTop: 0,
- // 禁止滚动穿透
- show: false,
- readList: [],
- typeList: []
- }
- },
- onLoad: async function(e) {
- const that = this;
- await that.searchToken();
- await that.searchOther();
- await that.searchConfig();
- },
- onShow: async function() {
- const that = this;
- that.clearPage();
- await that.search();
- },
- onPullDownRefresh: async function() {
- const that = this;
- that.clearPage();
- await that.search();
- uni.stopPullDownRefresh();
- },
- methods: {
- // 禁止滚动穿透
- change(e) {
- const that = this;
- that.show = e.show
- },
- // 用户信息
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) {
- const user = that.$jwt(res);
- that.$set(that, `user`, user);
- }
- } catch (e) {}
- },
- searchConfig() {
- const that = this;
- try {
- const res = uni.getStorageSync('config');
- if (res) that.$set(that, `config`, res);
- } catch (e) {}
- },
- // 查询其他信息
- async searchOther() {
- const that = this;
- let res;
- // 查询类型
- res = await that.$api(`/dictData`, 'GET', {
- code: 'messageIsRead',
- is_use: '0',
- })
- if (res.errcode == '0') that.$set(that, `readList`, res.data);
- // 通知类型
- res = await that.$api(`/dictData`, 'GET', {
- code: 'messageType',
- is_use: '0',
- })
- if (res.errcode == '0') that.$set(that, `typeList`, res.data)
- },
- // 查询
- async search() {
- const that = this;
- let info = {
- skip: that.skip,
- limit: that.limit,
- 'to.user': that.user.id
- }
- const res = await that.$api(`/message`, 'GET', info)
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- that.$set(that, `list`, list)
- that.$set(that, `total`, res.total)
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- });
- }
- },
- // 处理字典表
- getDict(item, model) {
- if(item){
- const that = this;
- let res
- if (model == 'is_read') {
- //理论上,to中应该只有这个数据,但是还要处理
- const userid = that.user.id
- if (!userid) return
- const to = item.to || []
- const is_readData = to.find((f) => f.user === userid)
- if (!is_readData) return
- const is_read = is_readData.is_read || '0'
- res = that.readList.find((f) => f.value === is_read)
- } else if (model == 'type') res = that.typeList.find(i => i.value == item)
- if (res) return res.label
- else return '暂无'
- }
- },
- // 已读未读
- toRead(item) {
- const that = this;
- uni.showModal({
- title: '提示',
- content: '您确认已读该数据?',
- success: async function(res) {
- if (res.confirm) {
- const data = JSON.parse(JSON.stringify(item));
- const userid = that.user.id
- const to = data.to || []
- for (const val of to) {
- if (val.user == userid) val.is_read = '1'
- }
- const res = await that.$api(`/message/${item.id}`, 'POST', {
- id: item.id,
- to
- })
- if (res.errcode == '0') {
- uni.showToast({
- title: "已读成功!",
- icon: 'none'
- });
- that.clearPage();
- that.search();
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- });
- }
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- },
- // 分页
- toPage(e) {
- const that = this;
- let list = that.list;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.search();
- uni.hideLoading();
- } else that.$set(that, `is_bottom`, true)
- },
- toScroll(e) {
- const that = this;
- let up = that.scrollTop;
- let num = Math.sign(up - e.detail.scrollTop);
- if (num == 1) that.$set(that, `is_bottom`, false);
- // 检查滚动位置是否达到div显示的条件
- if (e.detail.scrollTop >= 300 && !that.showDiv) {
- that.showDiv = true;
- } else if (e.detail.scrollTop < 300 && that.showDiv) {
- that.showDiv = false;
- }
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 5)
- that.$set(that, `page`, 0)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- .one {
- position: relative;
- flex-grow: 1;
- background-color: var(--f1Color);
- .list {
- background-color: var(--mainColor);
- border-bottom: 1px solid var(--f5Color);
- margin: 2vw 2vw 0 2vw;
- border-radius: 4px;
- padding: 3vw;
- .value {
- display: flex;
- align-items: center;
- .title {
- min-width: 70px;
- font-size: var(--font14Size);
- font-weight: bold;
- }
- .label {
- font-size: var(--font12Size);
- color: var(--f85Color);
- }
- }
- .bottom {
- margin: 2vw 0 0 0;
- text-align: center;
- .button {
- color: var(--mainColor);
- font-size: var(--font14Size);
- border-radius: 2vw;
- }
- .button_1 {
- margin: 0 2vw 0 0;
- background-color: var(--f3CColor);
- }
- .button_2 {
- background-color: var(--fF0Color);
- }
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- .is_bottom {
- width: 100%;
- text-align: center;
- text {
- padding: 2vw 0;
- display: inline-block;
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- </style>
|