/* * @Author: your name * @Date: 2021-03-05 09:44:53 * @LastEditTime: 2021-04-26 09:29:54 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \exclusive-cloud\manage\common\src\components\select-user\select-user.ts */ import {Component, Prop, Vue, Emit, Watch} from 'vue-property-decorator'; import Service from '../../assets/service/service' import Common from '../../assets/js/common' @Component export default class SelectUser extends Vue { /** * @value {email: '123@qq.com'} || '123@qq.com' */ @Prop({default: () => ''}) private value?: any; @Emit('userChange') userChange($event: any) {} private label: string = '全部'; private list: Array = ['全部', '自营客户', '代理商']; private billing: Array = []; private isBottomLoad: boolean = false; // 是否可以继续底部加载 private params: any = { emailLike: '', userType: 'customer', limitStart: 0, limitCount: 5 } /**默认值 */ private get billingValue() { if (typeof this.value === 'string' && this.value) { return {email: this.value}; } else if (typeof this.value === 'object') { return this.value; } return this.value; } private created() { // 接收传入默认值 this.params.emailLike = this.billingValue['email'] || ''; this.params.emailLike && this.getList(); } private getSearch(value: any){ this.params.emailLike = value this.params.limitStart = 0; this.getList(true); } /**用户类型回调 */ private labelChange($event: any) { this.params.userType = this.filterLabel($event); this.params.emailLike = ''; this.params.limitStart = 0; this.isBottomLoad = true; this.value = ''; this.getList(true); this.userChange({userID: ''}); } /**用户类型过滤 */ private filterLabel(type: string) { switch(type) { case '全部': return ''; case '自营客户': return 'efly'; case '代理商': return 'agent'; } } private selectHover($event: any) { if (this.billing.length === 0) { this.getList(); } } /**防抖函数 */ private inputDebounce: Function = Common.VueDebounce('selectInput', 400); /**搜索输入框回调 */ private selectInput($event: any) { this.params.emailLike = $event; this.params.limitStart = 0; this.isBottomLoad = true; this.getList(true); } private getList(reset: boolean = false) { Service.request('/user/query',this.params, 'token').then((res: any) => { if (+res.ret === 2) { if (reset) { this.billing = res.data.list; } else { this.billing = this.billing.concat(res.data.list); } this.isBottomLoad = this.billing.length < res.data.count; } else { this.billing = []; } }).catch(error => { // 啥也不做 }) } private scrollBottom() { if (this.isBottomLoad) { this.params.limitStart = this.billing.length; this.getList(); } } }