/** * 选择系统代理商 */ Vue.component('select-agent', { template: ` `, props: { 'agentId': { type: String, default: '', },//选择的代理商ID 'agentName': { type: String, default: '', },//选择的代理商名称 'isDisabled': { type: Boolean, default: false, },//是否禁止修改 'placeholder': { type: String, default: '选择代理商' }, 'size': { type: String, default: 'small', }, 'showStatus': { type: Boolean, default: false, },//是否显示代理商状态 }, data() { return { agent: { id: '', name: '', },//已选中代理商 dataList: [],// 数据 }; }, methods: { //切换代理商 changeAgent(val) { this.$emit('update:agentId', this.agent.id); this.$emit('update:agentName', this.agent.name); this.$emit('change', val); }, //获取代理商列表 getAgentList(callback) { this.dataList = []; this.sendRequest('Admin/Agent/getChooseAgent', { success: (res) => { if (res.status == 1) { this.dataList = res.data; typeof callback == "function" && callback(); } }, }) }, unitAgent(id, name) { if (!id && !name) { return { id: '', name: '', } } if (id && name) { return { id: id, name: name, } } for (let i in this.dataList) { if (this.dataList[i].id == id || this.dataList[i].name == name) { return { id: this.dataList[i].id, name: this.dataList[i].name, } } } return { id: '', name: '', }; } }, created() { this.getAgentList(() => { this.agent = this.unitAgent(this.agentId, this.agentName); }); }, watch: { agentId(n) { if (this.agent.id != n) { this.agent = this.unitAgent(this.agentId, this.agentName); } }, agentName(n) { if (this.agent.name != n) { this.agent = this.unitAgent(this.agentId, this.agentName); } } } });