detail.vue
4.61 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<template>
<view class="page">
<scroll-view class="scroll" scroll-y>
<view class="detail-page">
<view class="section">
<text class="row company">{{ safeText(form.peerName) }}</text>
<view class="row"><text class="label">同行品种</text><text class="value">{{ safeText(form.peerProductName) }}</text></view>
<view class="row"><text class="label">同行报价</text><text class="value">{{ safeText(form.peerPrice) }}</text></view>
<view class="row"><text class="label">创建人</text><text class="value">{{ safeText(form.createBy) }}</text></view>
<view class="row"><text class="label">创建时间</text><text class="value">{{ formatDateTime(form.createTime) }}</text></view>
</view>
</view>
</scroll-view>
<detail-buttons :buttons="displayButtons" @click="handleButtonClick" />
</view>
</template>
<script>
import DetailButtons from '@/components/detail-buttons/index.vue'
import { salesmanQuotationPeerGetApi, salesmanQuotationPeerDeleteApi } from '@/api/procure-manage/salesmanQuotationPeer.js'
export default {
name: 'PeerInfoDetail',
components: { DetailButtons },
data() {
return {
id: '',
loading: false,
form: {},
buttons: [
{ text: '编辑', visible: true, variant: 'outline', event: 'edit' },
{ text: '删除', visible: true, variant: 'danger', event: 'delete' }
]
}
},
computed: {
displayButtons() {
const isToday = this.isToday(this.form.createTime);
return [
{ ...this.buttons[0], visible: isToday && this.$auth.hasPermi('procure-manage:peer-info:modify') },
{ ...this.buttons[1], visible: isToday && this.$auth.hasPermi('procure-manage:peer-info:delete') }
]
}
},
onShow() {
const options = (this.$route && this.$route.query) ? this.$route.query : {}
const id = options && options.id ? String(options.id) : ''
if (id && id !== this.id) {
this.id = id
}
if (this.id) this.loadDetail()
},
methods: {
isToday(dateStr) {
if (!dateStr) return false;
const date = new Date(dateStr);
const today = new Date();
return (
date.getFullYear() === today.getFullYear() &&
date.getMonth() === today.getMonth() &&
date.getDate() === today.getDate()
);
},
safeText(v) {
const s = v == null ? '' : String(v)
return s.trim() ? s : ''
},
formatDateTime(v) {
const s = v == null ? '' : String(v).trim()
if (!s) return '-'
if (s.length >= 16) return s.slice(0, 16)
if (s.length >= 10) return s.slice(0, 10)
return s
},
handleButtonClick(btn) {
if (!btn || btn.disabled) return
const e = btn.event || ''
if (e === 'edit') return this.onEdit()
if (e === 'delete') return this.onDelete()
},
onEdit() {
uni.navigateTo({ url: '/pages/peer-info/modify?id=' + this.id })
},
onDelete() {
const id = this.id || (this.form && this.form.id) || ''
if (!id) return
uni.showModal({
title: '系统提示',
content: '是否确定删除该同行信息?',
confirmText: '确定',
cancelText: '取消',
success: (res) => {
if (res && res.confirm) {
salesmanQuotationPeerDeleteApi(id).then(() => {
uni.showToast({ title: '已删除', icon: 'none' })
try { uni.setStorageSync('PEER_INFO_LIST_NEED_REFRESH', '1') } catch (e) {}
setTimeout(() => { uni.redirectTo({ url: '/pages/peer-info/index' }) }, 300)
}).catch((e) => {
uni.showToast({ title: (e && e.msg) || '删除失败', icon: 'none' })
})
}
}
})
},
async loadDetail() {
this.loading = true
try {
const res = await salesmanQuotationPeerGetApi(this.id)
this.form = (res && res.data) ? res.data : {}
} catch (e) {
this.form = {}
uni.showToast({ title: '详情加载失败', icon: 'none' })
} finally {
this.loading = false
}
}
}
}
</script>
<style lang="scss" scoped>
.page {
display: flex;
flex-direction: column;
height: 100%;
}
.scroll {
flex: 1;
padding: 8rpx 0 144rpx;
}
.detail-page {
background: #f3f3f3;
}
.section {
padding: 32rpx;
background: #fff;
margin-bottom: 20rpx;
}
.row {
display: flex;
margin-bottom: 28rpx;
&:last-child {
margin-bottom: 0;
}
&.company {
font-size: 36rpx;
font-weight: 600;
color: rgba(0, 0, 0, 0.9);
padding-top: 8rpx;
line-height: 50rpx;
margin-bottom: 28rpx;
}
.label {
max-width: 420rpx;
margin-right: 20rpx;
line-height: 32rpx;
font-size: 28rpx;
color: rgba(0, 0, 0, 0.6);
}
.value {
flex: 1;
line-height: 32rpx;
font-size: 28rpx;
color: rgba(0, 0, 0, 0.9);
text-align: right;
word-break: break-all;
&.pre {
white-space: pre-wrap;
}
}
}
</style>