GoodsSelect.vue
2.52 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
<template>
<div class="goods-select">
<RemoteSelect
ref="remoteSelect"
v-model="currentValue"
select-type="goods"
option-func-name="options"
:request-params="requestParams"
:remote="true"
:filterable="true"
:placeholder="placeholder"
:config="config"
:can-input="canInput"
remote-search-key="name"
@input="handleInput"
@select="handelSelect"
/>
<ElButton
v-if="canAdd"
type="primary"
class="add-button"
@click="add"
>
添加商品
</ElButton>
</div>
</template>
<script>
import RemoteSelect from '@/views/components/RemoteSelect'
import AddDialog from '@/views/goods/components/AddDialog'
export default {
components: {
RemoteSelect
},
props: {
value: {
type: [String, Number],
default: () => null
},
orderId: {
type: [String, Number],
default: undefined
},
placeholder: {
type: String,
default: '请选择'
},
canAdd: {
type: Boolean,
// eslint-disable-next-line vue/no-boolean-default
default: false
},
config: {
type: Object,
default: () => {
return {
key: 'id',
label: 'name',
value: 'id'
}
}
},
type: { // 'all': 查询所有,不传则查询是排除所有使用过的
type: String,
default: null
},
canInput: {
type: Boolean,
// eslint-disable-next-line vue/no-boolean-default
default: false
},
commodityIds: {
type: String,
default: null
}
},
data() {
return {
currentValue: null
}
},
computed: {
requestParams() {
return {
p: {
type: this.type,
order_id: this.orderId,
commodityIds: this.commodityIds
}
}
}
},
watch: {
value: {
immediate: true,
handler(val) {
this.currentValue = val
this.handleInput()
}
}
},
methods: {
add() {
AddDialog.show(this.addGoodsSuccess)
},
addGoodsSuccess({ id }) {
console.log('添加成功, id', id)
if (id) {
this.currentValue = id
}
this.handleInput()
this.$refs.remoteSelect.fetchData()
},
handleInput() {
this.$emit('input', this.currentValue)
},
handelSelect(option) {
this.$emit('select-goods', option)
}
}
}
</script>
<style scoped lang="scss">
.goods-select {
display: flex;
.add-button {
margin-left: 10px;
}
}
</style>