referraCountEdit.js
4.8 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
182
183
184
185
186
187
188
189
190
191
192
193
194
// packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit.js
import api from '../../../api'
Page({
/**
* 页面的初始数据
*/
data: {
routerParams: {},
detailInfo: {},
loading: false,
/** 本次草稿/提交的业务场景
* 1-精品升级(轻改);2-会员权益(广联权益);3-单延保;
* 用于存草稿/提交后,仅更新当前的场景值
*/
editCurScene: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
routerParams: JSON.parse(options.info)
});
// 提交状态:0-未提交 1-已提交
wx.setNavigationBarTitle({
title: (this.data.routerParams.submitStatus == 0 && this.data.routerParams.updateFlag == 1) ? '编辑门店引荐数' : '查看门店引荐数'
})
this.getDetail();
},
defaultFillVal(data) {
data.sceneTypeEffectiveReferrals.forEach(item => {
// updateFlag 是否可编辑:0-不可编辑,1-可编辑(优先级最高)
// status状态:0-未提交,1-草稿,2-已提交
if (item.status == 0 && data.updateFlag == 1) {
if (item.effectiveReferralCountDTOS && item.effectiveReferralCountDTOS.length) {
item.effectiveReferralCountDTOS.forEach(k => {
k.effectiveReferralCount = (k.deliveryCount || 0) + ''
})
}
}
})
return data || {}
},
dealEditedVal(data) {
let { editCurScene, detailInfo } = this.data
console.log(detailInfo)
// updateFlag 是否可编辑:0-不可编辑,1-可编辑(优先级最高)
// status状态:0-未提交,1-草稿,2-已提交
if (data.updateFlag == 1) {
detailInfo.sceneTypeEffectiveReferrals.forEach((item, idx) => {
let obj = data.sceneTypeEffectiveReferrals.find(k => k.sceneType == item.sceneType)
if (editCurScene == item.sceneType || obj.status == 2) {
detailInfo.sceneTypeEffectiveReferrals[idx] = obj
}
})
} else {
detailInfo = data
}
return detailInfo || {}
},
// Simulate fetching data from backend
getDetail() {
let { merchantId, reviewMonth } = this.data.routerParams
let { editCurScene } = this.data
const params = {
merchantId,
reviewMonth
}
api.getReferralDetail(params).then(res => {
let { code, data, message } = res;
if (code == 0) {
let list = editCurScene != null ? this.dealEditedVal(data) : this.defaultFillVal(data)
this.setData({
detailInfo: list,
editCurScene: null
})
}
})
},
handleEditChange(e) {
const { detailInfo } = this.data
const updatedItem = e.detail;
const idx = detailInfo.sceneTypeEffectiveReferrals.findIndex(item => item.sceneType == updatedItem.sceneType)
detailInfo.sceneTypeEffectiveReferrals[idx] = updatedItem
this.setData({
detailInfo
})
},
// Handle Save Draft
onDraft(e) {
const updatedItem = e.detail;
console.log('Save Draft:', updatedItem);
this.updateLocalList('draft', updatedItem);
},
// Handle Submit
onSubmitItem(e) {
const updatedItem = e.detail;
console.log('Submit Item:', updatedItem);
this.updateLocalList('submit', updatedItem);
},
/** typeStatus: 草稿(draft),提交(submit) */
updateLocalList(typeStatus, updatedItem) {
let { loading } = this.data
if (loading) {
return
}
// const targetItem = updatedItem.sceneTypeEffectiveReferrals;
// const index = list.findIndex(item => item.sceneType === updatedItem.sceneType);
const tipsObj = {
'draft': '数据保存成功,未提交复核。',
'submit': '有效引荐数提交成功。',
}
const params = {
// 1-草稿,2-已提交
...updatedItem,
status: typeStatus == 'submit' ? 2 : 1
}
console.log(params, 'params---')
wx.$util.showLoading()
this.setData({
loading: true,
editCurScene: updatedItem.sceneType || null
})
api.referralSubmit(params).then(res => {
let { code, data, message } = res
wx.$util.showToast(code == '0' ? `${tipsObj[typeStatus]}` : message);
this.getDetail()
}).finally(() => {
wx.hideLoading();
this.setData({
loading: false
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})