index.vue
5.19 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
<template>
<view class="customer-box">
<view class="tips flex">
<view class="today flex">
<view class="sprite-icon icon-customer-sop-1"></view>
今日活动({{ toDay }})
</view>
<view class="text">根据SOP策略生成营销活动,请及时推送客户</view>
</view>
<view class="tabs-box flex">
<template v-for="(tab, index) in tabs">
<view :class="['tab flex', { active: index === tabIndex }]" :key="index" @click="changeTab(index)">
<view
:class="['sprite-icon', index === tabIndex ? `icon-customer-sop-${index + 2}-a` : `icon-customer-sop-${index + 2}`]">
</view>
{{ tab }}
</view>
</template>
</view>
<view class="customer-content">
<Table :type="tabIndex" @openPopup="openPopup" @loadMore="loadMore" :list="tableData" ref="table" />
</view>
<CustomerPopup ref="customerPopup" />
</view>
</template>
<script type='text/ecmascript-6'>
import dayjs from 'dayjs';
import Table from './components/Table'
import CustomerPopup from './components/CustomerPopup'
export default {
name: 'CustomerOpportunities',
components: { Table, CustomerPopup },
inject: ['userInfo'],
props: {
show: Boolean
},
data() {
return {
tabIndex: 0,
tabs: ['待执行推送客户(0)', '近7日已推送客户(0)'],
toDay: dayjs().format('MM-DD'),
total: 0,
pageNum: 1,
pageSize: 10,
tableData: []
}
},
watch: {
show: {
handler(val) {
if (val) {
this.getTodaySopTaskCustomerPage()
this.getLastWeekSopTaskCustomerPage(false)
} else {
this.tabs = this.$options.data.call(this).tabs
this.tabIndex = 0
this.initRequestParams()
}
},
immediate: true,
deep: true
}
},
computed: {
},
mounted() {
},
methods: {
tableRef() {
return this.$refs.table || null
},
initRequestParams() {
this.pageNum = 1
this.pageSize = 10
this.tableData = []
if (this.tableRef()) {
this.tableRef().loadComplete = false
this.tableRef().noMore = false
}
uni.hideLoading()
},
/**
* 切换标签
* @param {number} index
*/
changeTab(index) {
if (index == this.tabIndex) return
this.tabIndex = index
this.initRequestParams()
if (index == 0) this.getTodaySopTaskCustomerPage()
else this.getLastWeekSopTaskCustomerPage()
},
openPopup(data) {
this.$refs.customerPopup.open(data)
},
loadMore() {
let { total, pageSize, pageNum, tabIndex } = this
if (Math.ceil(total / pageSize) > pageNum) {
this.pageNum += 1
if (tabIndex == 0) this.getTodaySopTaskCustomerPage()
else this.getLastWeekSopTaskCustomerPage()
} else this.tableRef().noMore = true
},
async getTodaySopTaskCustomerPage() {
try {
uni.showLoading({ title: '加载中...', mask: true })
let { shopMerchantId: merchantId } = this.userInfo,
{ pageNum, pageSize, tableData } = this,
{ list, total } = await uni.$api.customerApi.getTodaySopTaskCustomerPage({ merchantId, pageNum, pageSize })
uni.hideLoading()
this.tableData = [...tableData, ...list]
this.tableRef().loadComplete = true
this.total = total
this.$set(this.tabs, 0, `待执行推送客户(${total})`)
} catch (error) {
this.tableRef() && (this.tableRef().loadComplete = true)
}
},
async getLastWeekSopTaskCustomerPage(assignment = true) {
try {
if (assignment) uni.showLoading({ title: '加载中...', mask: true })
let { shopMerchantId: merchantId } = this.userInfo,
{ pageNum, pageSize, tableData } = this,
{ list, total } = await uni.$api.customerApi.getLastWeekSopTaskCustomerPage({ merchantId, pageNum, pageSize })
if (assignment) {
this.tableData = [...tableData, ...list]
this.tableRef().loadComplete = true
this.total = total
uni.hideLoading()
}
this.$set(this.tabs, 1, `近7日已推送客户(${total})`)
} catch (error) {
this.tableRef() && (this.tableRef().loadComplete = true)
}
}
}
}
</script>
<style scoped lang='scss'>
.customer-box {
width: 100%;
height: 100%;
padding: toRpx(32) toRpx(40) 0;
box-sizing: border-box;
.sprite-icon {
margin-right: toRpx(8);
}
.tips {
height: toRpx(64);
background: #2C66F70D;
padding: 0 toRpx(24);
font-size: toRpx(26);
color: #6C6F75;
border-radius: toRpx(20);
.today{
line-height: toRpx(38);
}
.text {
margin-left: auto;
}
}
.tabs-box {
display: flex;
margin: toRpx(28) 0;
gap: toRpx(28);
.tab {
line-height: toRpx(64);
height: toRpx(64);
padding: 0 toRpx(32);
border-radius: toRpx(16);
background: #F2F2F2;
font-size: toRpx(28);
color: #292D33;
justify-content: center;
transition: all 0.2s ease-in-out;
}
.tab.active {
background: #2C66F71A;
color: #2C66F7;
}
}
.customer-content {
height: calc(100% - #{toRpx(184)});
}
}
</style>