search-customer.vue
4.45 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
<template>
<Page name="search-customer">
<template #header>
<search-bar v-model="searchForm.name" placeholder="请输入搜索关键词" auto @confirm="onSearch" />
</template>
<template #content>
<List ref="list" v-model="list" :api="searchAPI" :addOption='!appId && addOption'>
<template v-for="(item, index) in list">
<zui-cell :key="index" @click="onSelect(item, index)">
<template #title>
<text>{{ item.name || item.customerName }}</text>
<view class="ml" v-if="mode === 'collect' && item.parentCustomerName" style="display: inline-flex">
<zui-tag type="ghost" color="#8c8c8c">{{ item.parentCustomerName }}</zui-tag>
</view>
</template>
<template #right>
<view class="collect" v-if="mode === 'collect'" hover-class="active" hover-start-time="50" hover-stay-time="70">
<zui-icon :name="item.collectFlag ? 'favorite' : 'favoriteoutline'"></zui-icon>
<text>{{ `${item.collectFlag ? '已' : ''}收藏` }}</text>
</view>
<zui-tag v-else-if="['collect', 'select'].indexOf(mode) > -1 && item.parentCustomerName" type="ghost" color="#8c8c8c">
<text>{{ item.parentCustomerName }}</text>
</zui-tag>
</template>
</zui-cell>
</template>
</List>
</template>
</Page>
</template>
<script>
export default {
data() {
return {
searchForm: {
name: null,
topCustomerFlag: false
},
list: [],
mode: 'search',
appId: '',
}
},
onLoad(option) {
if (option.mode) this.mode = option.mode;
if (option.appId) this.appId = option.appId || '';
if (option.mode === 'collect') {
uni.setNavigationBarTitle({ title: '收藏客户' });
} else if (option.mode === 'select') {
uni.setNavigationBarTitle({ title: '选择客户' });
}
if (option.topCustomerFlag !== '') {
this.searchForm.topCustomerFlag = option.topCustomerFlag;
}
},
methods: {
searchAPI(params) {
if (this.appId) {
return uni.$u.api.filter.getBelongCustomer({...params, ...this.searchForm, appId: this.appId});
}
return uni.$u.api.filter.getCommonSelect({ ...params, ...this.searchForm });
},
addOption(list){
let obj = {
code: '',
name: '不限',
};
let hash = {};
let options = [obj, ...list].reduce((result, item) => {
let hashKey = `${item.code}` || '_empty';
if (!hash[hashKey]) {
hash[hashKey] = true;
if (item.name) {
result.push(item);
}
}
return result; // 返回结果数组
}, []);
this.$emit('input', options);
},
onSelect(item, index) {
const $params = this.$params;
if ($params.mode === 'select') {
uni.$emit('select-customer', item.name == '不限' && !item.code ? { code: '', name: '' } : item);
uni.navigateBack();
} else if ($params.mode === 'collect') {
if (item.collectFlag === true) {
uni.showModal({
title: '提示',
content: '确定要取消收藏此客户吗?',
confirmButtonText: '确定',
cancelButtonText: '取消',
success: (res) => {
if (res.confirm) {
this.$request.post({
url: '/customerCollect/cancelCustomerCollect',
data: { customerCode: item.code }
}).then(() => {
uni.showToast({ title: '已取消收藏', icon: 'none' });
this.$set(this.list, index, { ...this.list[index], collectFlag: false });
});
}
}
});
} else {
this.$request.post({
url: '/customerCollect/addCustomerCollect',
data: [item.code]
}).then(() => {
uni.showToast({ title: '收藏成功', icon: 'none' });
this.$set(this.list, index, { ...this.list[index], collectFlag: true });
});
}
}
}
}
}
</script>
<style lang="scss">
.page-search-customer {
.collect {
display: flex;
align-items: center;
color: $color-text-minor;
.zui-icon {
font-size: $font-lg;
color: $color-red;
padding: 0 $padding-sm;
}
&.active {
.zui-icon {
color: lighten($color-red, 15);
}
}
font-size: $font-md;
}
}
</style>