文件
mashangyoujiu/Public/Retail/common/js/select-industry.js

81 行
2.4 KiB
JavaScript
可执行文件

/**
* 选择行业
*/
Vue.component('select-industry', {
template: `<el-select v-model="industry_id"
:placeholder="placeholder"
:disabled="isDisabled"
size="small"
@change="changeIndustry"
clearable filterable>
<el-option v-for="item in dataList"
:value-key="item.id"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>`,
props: {
'industryId': {
type: String,
default: '',
},//选择的行业ID
'isDisabled': {
type: Boolean,
default: false,
},//是否禁止修改
'placeholder': {
type: String,
default: '选择行业'
},
'showCommon': {
type: Boolean,
default: false,
},//是否显示公共行业
},
data() {
return {
industry_id: '',//已选中的行业id
dataList: [],// 数据
};
},
methods: {
//切换行业
changeIndustry(val) {
this.$emit('update:industryId', val);
this.$emit('change', val);
},
//获取行业列表
getIndustryList() {
this.dataList = [];
$.ajax({
url: '/index.php/Retail/StoreIndustry/getIndustrySelect',
type: 'post',
success: (res) => {
if (res.status == 1) {
if (res.data.list.length) {
this.dataList = res.data.list;
this.$nextTick(() => {
if (this.showCommon) {
this.dataList.unshift({
id: '0',
name: '公共行业',
})
}
})
}
}
},
})
},
},
created() {
this.industry_id = this.industryId;
this.getIndustryList();
},
watch: {
industryId(n) {
this.industry_id = n;
}
}
});