detail.vue
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
<view class="main">
<view class="toptitle">
<view class="toptitle_left" @click="ht">
<u-icon name="arrow-left" color="#fff" size="20"></u-icon>
</view>
<view class="toptitle_title">信息推送详情</view>
</view>
<view class="box" style="margin: 20rpx;padding-top: 10px;">
<view class="box_item" style="margin-bottom: -10px;">
<view class="f1">{{ info.bt || '-' }}</view>
</view>
<view class="box_item" style="display: flex;flex-direction: column;align-items: flex-start;">
<view class="f2" style="color:#969696;margin-bottom: 10px;">{{ info.fl || '-' }} · {{ formatTime(info.tssj) }}</view>
<view class="f2" v-html="info.nr"></view>
</view>
</view>
</view>
</template>
<script>
export default {
data(){
return {
info: {},
base_url: 'https://hhjj.antissoft.com'
}
},
onLoad(options){
const cached = uni.getStorageSync('xxts_item');
let id = options.id;
if(!id && cached){
try{ id = JSON.parse(cached).ff || JSON.parse(cached).ID || JSON.parse(cached).F_Id }catch(e){}
}
this.fetchDetail(id);
this.xgxxwyd(cached);
},
methods:{
// 已读消息
xgxxwyd(data){
if (!data) {
console.warn('xgxxwyd: data is empty');
return;
}
try {
var info = JSON.parse(data);
console.log("更新前 info:", info);
// 只更新必要字段,避免覆盖其他数据
const updateData = {
ff: info.ff || info.ID || info.F_Id,
sfyd: '是',
ydsj: new Date().toISOString() // 设置阅读时间
};
console.log("更新数据:", updateData);
this.API.xgxxwyd(updateData).then(res=>{
console.log("已读更新成功", res);
}).catch(err => {
console.error("已读更新失败:", err);
});
} catch(e) {
console.error("解析消息数据失败:", e, data);
}
},
ht(){
uni.navigateBack({ delta: 1 });
},
formatTime(ts){
if(!ts) return '';
const d = new Date(ts);
const Y = d.getFullYear();
const M = String(d.getMonth()+1).padStart(2,'0');
const D = String(d.getDate()).padStart(2,'0');
const h = String(d.getHours()).padStart(2,'0');
const m = String(d.getMinutes()).padStart(2,'0');
const s = String(d.getSeconds()).padStart(2,'0');
return `${Y}-${M}-${D} ${h}:${m}:${s}`;
},
fetchDetail(id){
if(!id){
uni.showToast({ icon:'none', title:'缺少消息ID' });
return;
}
const user = uni.getStorageSync('userinfo') || {};
const n = user.id || 1763367257;
this.API.xxtsjlxq({ id, n }).then(res=>{
if(res && res.code === 200){
this.info = res.data || {};
}else{
this.info = {};
}
}).catch(()=>{
this.info = {};
})
}
}
}
</script>
<style scoped lang="scss">
@import 'detail.scss';
</style>