orderTip.vue
1.78 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
<template>
<view class="orderTip" v-if="orderData" @click="handleLink">
<view class="btn">消息通知</view>
<view>{{ orderData.recentMsg }}</view>
<view>
{{ orderData.minutes === 0 ? formatMinutes(1) : formatMinutes(orderData.minutes) }}
<icon class="iconNext"></icon>
</view>
</view>
</template>
<script setup>
import { useStore } from "vuex";
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
dayjs.extend(duration)
function formatMinutes(minutes) {
const days = Math.floor(minutes / 1440) // 1天 = 1440分钟
const hours = Math.floor((minutes % 1440) / 60) // 剩余分钟中的小时
const mins = minutes % 60 // 剩余分钟
if (days > 0) {
return `${days}天${hours}小时${mins}分钟前`
} else if (hours > 0) {
return `${hours}小时${mins}分钟前`
} else {
return `${mins}分钟前`
}
}
const store = useStore(); //vuex获取、储存数据
// 获取父组件值、方法
const props = defineProps({
orderData: Object,
default: () => ({}),
});
// ------定义方法------
const handleLink = () => {
const type = props.orderData.contentType;
store.commit("user/setTaskStatus", -1);
if (type === 300) {
uni.redirectTo({
url: "/pages/news/index",
});
} else if (type === 301) {
uni.redirectTo({
url: "/pages/news/system?title=取件相关&type=301",
});
} else if (type === 302) {
uni.redirectTo({
url: "/pages/news/system?title=签收提醒&type=302",
});
} else if (type === 303) {
uni.redirectTo({
url: "/pages/news/system?title=快件取消&type=303",
});
} else {
uni.redirectTo({
url: "/pages/news/system?title=派件相关&type=304",
});
}
};
</script>
<style src="../index.scss" lang="scss"></style>