4747 <div class =" flex-c" v-if =" item.desc" v-html =" item.desc" ></div >
4848 </div >
4949 </el-option >
50+ <el-option v-if =" attrs.paginate && loadMore && options.length" :value =" undefined" >
51+ <div @click.stop =' paginateData($event)' >
52+ <i class =" el-icon-loading" ></i >
53+ <span >加载更多</span >
54+ </div >
55+ </el-option >
5056 </el-select >
5157</template >
5258<script >
@@ -60,23 +66,61 @@ export default {
6066 },
6167 data () {
6268 return {
63- options: this .attrs .options
69+ options: this .attrs .options ,
70+ extUrlParams: this .attrs .extUrlParams ,
71+ query: null ,
72+ loadMore: true ,
73+ meta: {
74+ page: 1 ,
75+ per_page: this .attrs .paginate
76+ }
6477 };
6578 },
6679 model: {
6780 prop: " value" ,
6881 event : " change"
6982 },
83+ computed: {
84+ depend () {
85+ return _ .pick (this .form_data , this .attrs .depend );
86+ }
87+ },
7088 methods: {
7189 onChange (value ) {
72- this .$emit (" change" , value);
90+ let resValue = value
91+ if (typeof value === ' object' ){
92+ // 排除value = 0
93+ resValue = value .filter (e => e !== undefined )
94+ }else if (value === undefined ){
95+ resValue = null
96+ }
97+ this .$emit (" change" , resValue);
7398 },
7499 remoteMethod (query ) {
100+ this .query = query
101+ this .meta .page = 1
75102 this .$http
76- .get (this .attrs .remoteUrl , { params: { query: query } })
103+ .get (this .attrs .remoteUrl , { params: { ... this . meta , query: query, depend : this . depend , extUrlParams : this . extUrlParams } })
77104 .then (res => {
78105 this .options = res .data ;
106+ this .meta .page ++
107+ this .loadMore = true
79108 });
109+ },
110+ paginateData (event ) {
111+ this .$http
112+ .get (this .attrs .remoteUrl , { params: { ... this .meta , query: this .query , depend: this .depend , extUrlParams: this .extUrlParams } })
113+ .then (res => {
114+ if (res .data .length ) {
115+ this .options .push (... res .data )
116+ }
117+ if (this .meta .page < res .meta .to ){
118+ this .meta .page = res .meta .to
119+ this .loadMore = true
120+ }else {
121+ this .loadMore = false
122+ }
123+ })
80124 }
81125 }
82126};
0 commit comments