select-search-brand.vue
1.78 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
<template>
<Select
v-model="brandId"
@on-change="selectChange"
filterable
remote
:remote-method="queryBrands"
:loading="loading"
clearable>
<Option v-for="option in optionList" :value="option.id" :key="option.id">{{option.text}}</Option>
</Select>
</template>
<script>
import _ from 'lodash';
import BrandService from 'services/product/brand-service';
export default {
name: 'select-search-brand',
props: {
value: {
type: [Number, String],
default: 0
}
},
created() {
this.brandService = new BrandService();
},
data() {
return {
brandId: this.value,
loading: false,
optionList: []
};
},
watch: {
value(val) {
this.brandId = val || '';
}
},
methods: {
queryBrands(query) {
if (query) {
this.loading = true;
this.brandService.getBrandNames({
nameOrId: query
}).then((res) => {
this.loading = false;
this.optionList = res.data;
}, () => {
this.loading = false;
});
} else {
this.optionList = [];
}
},
selectChange(brandId) {
this.$emit('input', brandId);
this.$emit('change', _.find(this.optionList, {brandId}));
}
}
};
</script>
<style lang="scss" scoped>
.field-label {
line-height: 32px;
}
</style>