sendOutComp.vue
5.41 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<template>
<h-dialog ref="myDialog" :title="title" :isVisible="isVisible" @confirm="handleSubmit" @cancel="handleCancel">
<div class="formObj">
<div class="search-pop-input">
<van-field v-model="keyword" placeholder="搜索" left-icon="https://img02.glsx.com.cn/weapp/resource/saas/scrm/search-icon.png" @input="onSearch" />
</div>
<template v-if="shippingEntityList.length > 0">
<div class="lists-wrap">
<template v-for="(item, index) in shippingEntityList">
<div :class="['list', item.checked ? 'active' : '']" @click="handleCheck(index)" :key="index">
{{ item.shippingEntity }}
<img v-if="item.checked" src="@/assets/images/mark.png" alt="" class="icon-mark" />
</div>
</template>
</div>
</template>
<div v-else class="no-data">
<img src="@/assets/images/no-data.png" />
<span class="no-data-text">暂无数据</span>
</div>
</div>
</h-dialog>
</template>
<script>
import hDialog from './dialog'
import utils from '@/utils/util'
import purchaseApi from '@/api/purchase'
export default {
components: { hDialog },
data() {
return {
title: '发货主体选择',
keyword: '',
originalShippingEntityList: [],
shippingEntityList: [],
selectSendOutMerchantId: ''
}
},
props: {
isVisible: {
type: Boolean,
default: false
},
sendOutMerchantId: {
type: String,
default: ''
}
},
created() {
this.selectSendOutMerchantId = this.sendOutMerchantId
console.log('created', this.sendOutMerchantId)
this.selectShippingEntityInfoAll()
},
methods: {
onSearch(val) {
const debouncedSearch = utils.debounce(
val => {
this.handleSearch(val)
},
200,
true
)
// 调用防抖函数
debouncedSearch(val)
},
handleSearch(val) {
// 如果搜索值为空,显示全部数据
if (!val || val.trim() === '') {
this.shippingEntityList = this.originalShippingEntityList || this.shippingEntityList
return
}
// 进行模糊搜索,匹配 shippingEntity 字段
const filteredList = this.originalShippingEntityList.filter(item => {
return item.shippingEntity.toLowerCase().includes(val.toLowerCase())
})
// 更新列表数据
this.shippingEntityList = filteredList
if (this.shippingEntityList.length) {
this.handleFindIdAttribute()
}
},
async selectShippingEntityInfoAll() {
let result = await purchaseApi.selectShippingEntityInfoAll()
console.log(result)
if (result.code == 0) {
result.data.forEach(item => {
item.checked = false
})
this.shippingEntityList = result.data
this.originalShippingEntityList = [...this.shippingEntityList]
this.handleFindIdAttribute()
}
},
handleFindIdAttribute() {
this.shippingEntityList.forEach(item => {
item.checked = false
})
this.shippingEntityList.forEach(item => {
console.log(item.shippingEntityId == this.selectSendOutMerchantId,item.shippingEntityId,this.selectSendOutMerchantId)
if (item.shippingEntityId == this.selectSendOutMerchantId) {
item.checked = true
}
})
},
handleCheck(index) {
this.shippingEntityList.forEach(item => {
item.checked = false
})
this.shippingEntityList[index].checked = true
this.selectSendOutMerchantId = this.shippingEntityList[index].shippingEntityId
console.log(this.selectSendOutMerchantId)
},
handleSubmit() {
let data = this.originalShippingEntityList.find(item => item.shippingEntityId == this.selectSendOutMerchantId) || {}
this.$emit('submit', data)
// this.$refs.myDialog.stopLoading();
},
handleCancel() {
this.$emit('cancel')
}
}
}
</script>
<style lang="scss" scoped>
.formObj {
margin: 0 16px;
font-size: 14px;
.lists-wrap {
box-sizing: border-box;
overflow: scroll;
height: calc(100% - 52px);
.list {
display: inline-block;
height: 46px;
line-height: 46px;
color: #292d33;
font-size: 14px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: flex;
justify-content: space-between;
align-items: center;
border-top: 1px solid #eff0f2;
}
.active {
color: #347bff;
}
.icon-mark {
width: 16px;
height: 16px;
}
}
.search-pop-input {
margin: 8px 0;
position: relative;
z-index: 99;
width: 343px;
::v-deep(.van-cell) {
width: 100%;
background: #f2f3f5;
height: 36px;
border-radius: 253px;
}
::v-deep(.van-field__left-icon) {
position: absolute;
width: 16px;
height: 16px;
margin: 4px 6px 8px 12px;
z-index: 999;
.van-icon {
color: #999ea8;
}
}
::v-deep(.van-field__body) {
position: absolute;
width: 343px;
border-radius: 16px;
left: 0;
}
::v-deep(.van-field__control) {
padding-left: 33px;
font-size: 14px;
}
}
.no-data {
display: flex;
flex-direction: column;
align-items: center;
justify-items: center;
img {
width: 72px;
height: 72px;
}
.no-data-text {
color: #999ea8;
font-size: 12px;
margin-top: 16px;
}
}
}
</style>