<template>
    <el-select
        v-model="valueSync"
        multiple
        filterable
        clearable
        remote
        reserve-keyword
        :disabled="disabled"
        :placeholder="$t('请输入订单号')"
        @focus="remoteMethod('')"
        :remote-method="remoteMethod"
        :loading="loading">
        <el-option
        v-for="(item) in list"
        :key="item.id"
        :label="item.orderNo"
        :value="item.orderId">
        </el-option>
    </el-select>
</template>
<script>
import {getOrderPage, getOrderList} from '@/api/ecw/order'

export default {
    props:{
        value: [Array],
        disabled: {
            type: Boolean,
            default: false
        }
    },
    data(){
        return {
            valueSync: [],
            list:[],
            loading: false
        }
    },
    watch:{
        valueSync(val){
            this.$emit('input', val)
        },
        value(val){
            this.valueSync = this.value
            this.init(val)
        }
    },
    created(){
        this.valueSync = this.value
        this.init(this.value)
    },
    methods:{
        init(val){
            if(val === null || val == undefined || val == '') return
            let params = {
                ids: val.toString()
            }
            getOrderList(params).then(res => {
                this.list = res.data
            })
        },
        remoteMethod(keyword){
            let params = {
                pageSize: 10,
            }
            params.orderNo = keyword
            this.loading = true
            getOrderPage(params)
                .then(res => this.list = res.data.list)
                .finally(() => this.loading = false)
        }
    }
}
</script>