negotiation-summary.js
4.1 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
const negotiationApi = require('../../api/negotiationDailyReport.js')
const { isApiSuccess } = require('../../utils/api-response.js')
import { buildNegotiationSummaryTables } from '../../form-engine/negotiation-summary-transform.js'
Component({
properties: {
reportDate: {
type: String,
value: ''
},
merchantId: {
type: String,
value: ''
},
sceneType: {
type: null,
value: 0
}
},
data: {
loading: false,
detailLoading: false,
loadComplete: false,
loadError: '',
staffList: [],
currentIndex: 0,
sections: [],
sectionNavIndex: [],
isFullEmptyView: false
},
observers: {
'reportDate, merchantId'(reportDate, merchantId) {
if (reportDate && merchantId) {
this.loadStaffList()
}
},
'loadComplete, loading, loadError, staffList'() {
this.syncFullEmptyView()
}
},
lifetimes: {
attached() {
const { reportDate, merchantId } = this.properties
if (reportDate && merchantId) {
this.loadStaffList()
}
}
},
methods: {
/** 无员工空态:整页居中,需 --empty 绝对定位布局 */
syncFullEmptyView() {
const { loadComplete, loading, loadError, staffList } = this.data
const isFullEmptyView =
loadComplete && !loading && !loadError && !staffList.length
if (this.data.isFullEmptyView !== isFullEmptyView) {
this.setData({ isFullEmptyView })
}
},
reload() {
this.loadStaffList()
},
onBack() {
this.triggerEvent('close')
},
onStaffTabTap(e) {
const index = Number(e.currentTarget.dataset.index)
if (Number.isNaN(index) || index === this.data.currentIndex) return
this.setData({ currentIndex: index })
this.loadStaffDetail(this.data.staffList[index])
},
onSectionNav(e) {
const sectionIndex = Number(e.currentTarget.dataset.sectionIndex)
const direction = Number(e.detail?.direction)
if (Number.isNaN(sectionIndex) || !direction) return
const sections = this.data.sections || []
const section = sections[sectionIndex]
const rowTotal = section?.recordRows?.length || 0
if (!rowTotal) return
const nav = [...(this.data.sectionNavIndex || [])]
const current = nav[sectionIndex] ?? 0
const next = current + direction
if (next < 0 || next >= rowTotal) return
nav[sectionIndex] = next
this.setData({ sectionNavIndex: nav })
},
async loadStaffList() {
const { reportDate, merchantId, sceneType } = this.properties
if (!reportDate || !merchantId) return
this.setData({
loading: true,
loadComplete: false,
loadError: '',
staffList: [],
sections: [],
sectionNavIndex: [],
currentIndex: 0
})
try {
const res = await negotiationApi.fetchDiscussionStaffList({
merchantId,
reportDate,
sceneType
})
if (!isApiSuccess(res.code)) {
this.setData({
loadError: res.message || '加载失败',
loadComplete: true
})
return
}
const staffList = res.data || []
this.setData({
staffList,
loadComplete: true
})
if (staffList.length) {
await this.loadStaffDetail(staffList[0])
}
} catch (error) {
console.error(error)
this.setData({
loadError: '加载失败',
loadComplete: true
})
} finally {
this.setData({ loading: false })
}
},
async loadStaffDetail(staff = {}) {
const { reportDate, merchantId, sceneType } = this.properties
if (!staff.staffUuid || !reportDate || !merchantId) {
this.setData({ sections: [], sectionNavIndex: [] })
return
}
this.setData({ detailLoading: true })
try {
const res = await negotiationApi.fetchReportDetail({
merchantId,
staffUuid: staff.staffUuid,
reportDate,
sceneType
})
if (!isApiSuccess(res.code) || !res.data) {
this.setData({ sections: [], sectionNavIndex: [] })
return
}
const jsonContent = res.data.jsonContent || ''
const sections = buildNegotiationSummaryTables(jsonContent)
this.setData({
sections,
sectionNavIndex: sections.map(() => 0)
})
} catch (error) {
console.error(error)
this.setData({ sections: [], sectionNavIndex: [] })
} finally {
this.setData({ detailLoading: false })
}
}
}
})