138 行
4.8 KiB
JavaScript
可执行文件
138 行
4.8 KiB
JavaScript
可执行文件
/**
|
|
* 选择品牌
|
|
*/
|
|
Vue.component('select-goods-brand', {
|
|
template: `<el-select v-model="brand_id"
|
|
:placeholder="placeholder"
|
|
filterable clearable
|
|
ref="brandLabel"
|
|
class="small-input"
|
|
allow-create
|
|
default-first-option
|
|
@change="changeBrand">
|
|
<el-option v-for="item in dataList"
|
|
:key="item.id"
|
|
:label="item.name"
|
|
:value="item.id">
|
|
</el-option>
|
|
</el-select>`,
|
|
props: {
|
|
'brandId': {
|
|
type: String,
|
|
default: '',
|
|
},//选择的品牌ID
|
|
'brandName': {
|
|
type: String,
|
|
default: '',
|
|
},//选择的品牌名称
|
|
'isDisabled': {
|
|
type: Boolean,
|
|
default: false,
|
|
},//是否禁止修改
|
|
'placeholder': {
|
|
type: String,
|
|
default: '商品品牌(可直接新增)'
|
|
},
|
|
'size': {
|
|
type: String,
|
|
default: 'small',
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
brand_id: '',//已选中品牌ID
|
|
dataList: [],// 数据
|
|
};
|
|
},
|
|
methods: {
|
|
//切换品牌
|
|
changeBrand(val) {
|
|
this.$nextTick(() => {
|
|
if (this.$refs.brandLabel.createdLabel) {
|
|
this.$confirm("确认添加到品牌库吗?", "温馨提示", {
|
|
confirmButtonText: '添加',
|
|
cancelButtonText: '取消',
|
|
type: 'info'
|
|
}).then(() => {
|
|
this.sendRequest('Retail/GoodsBrand/goodsBrandAdd', {
|
|
data: {
|
|
name: val
|
|
},
|
|
success: (res) => {
|
|
if (res.status == 1) {
|
|
this.$message.success(res.message);
|
|
let obj = {
|
|
id: res.data.id,
|
|
name: val,
|
|
};
|
|
this.dataList.unshift(obj);
|
|
this.$refs.brandLabel.createdLabel = null;
|
|
this.$nextTick(() => {
|
|
this.brand_id = res.data.id;
|
|
this.callback();
|
|
});
|
|
}
|
|
}
|
|
})
|
|
}).catch(() => {
|
|
this.$refs.brandLabel.createdLabel = null;
|
|
this.brand_id = '';
|
|
this.callback();
|
|
})
|
|
}else{
|
|
this.callback();
|
|
}
|
|
})
|
|
},
|
|
callback() {
|
|
this.$emit('update:brandId', this.brand_id);
|
|
this.$emit('change', this.brand_id);
|
|
},
|
|
//获取品牌列表
|
|
getBrandList() {
|
|
this.dataList = [];
|
|
this.sendRequest('Retail/GoodsBrand/getSelectBrand', {
|
|
success: (res) => {
|
|
if (res.status == 1) {
|
|
this.dataList = res.data;
|
|
this.$nextTick(() => {
|
|
if (this.brandName) {
|
|
let flag = false;
|
|
for (let i = 0; i < this.dataList.length; i++) {
|
|
if (this.dataList[i].name == this.brandName) {
|
|
this.brand_id = this.dataList[i].id;
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!flag) {
|
|
this.$refs.brandLabel.createdLabel = this.brandName;
|
|
this.changeBrand(this.brandName);
|
|
}
|
|
} else {
|
|
this.$nextTick(() => {
|
|
this.$refs.brandLabel.createdLabel = null;
|
|
})
|
|
}
|
|
})
|
|
}
|
|
},
|
|
})
|
|
},
|
|
},
|
|
created() {
|
|
this.brand_id = this.brandId;
|
|
this.getBrandList();
|
|
},
|
|
watch: {
|
|
brandId(n) {
|
|
this.brand_id = n;
|
|
},
|
|
brandName(n) {
|
|
if (n != '' && n) {
|
|
this.getBrandList();
|
|
}
|
|
}
|
|
|
|
}
|
|
}); |