/** * 选择行业 */ Vue.component('select-industry', { template: ` `, 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; } } });