nalinv-mobile/components/dialog/input-select-dialog.vue

296 lines
7.1 KiB
Vue

<template>
<view>
<view
style=" display:flex;justify-content:flex-end; border:1px solid #dcdfe6;border-radius: 6rpx;border-radius: 4px;">
<u-input @blur="handleBlur" :focus="focus" style="float: left;" v-model="defaultValue" @confirm="submit"
:placeholder="inputPlaceholder"></u-input>
<u-icon style="float: right;" size="45rpx" name="arrow-right" @click="show = true"></u-icon>
</view>
<u-popup mode="bottom" :border-radius="0" :popup="false" v-model="show" :maskCloseAble="maskCloseAble"
:usePage="usePage" length="auto" :safeAreaInsetBottom="true" @close="popupClose" :z-index="uZIndex">
<view v-if="allowSearch" style="padding: 5px 10px;">
<u-search v-model="queryParam.searchText" @custom="search" @search="search" placeholder="">
</u-search>
</view>
<view>
<scroll-view v-if="list && list.length > 0" scroll-y="true" class="chen-scroll" @touchmove.stop.prevent
@scrolltolower="loadMore">
<block v-for="(item, index) in list" :key="index" style="scroll-snap-align:center">
<view @tap="itemClick(item)" class="u-action-sheet-item u-line-1 u-border-bottom"
style="padding: 10px;" :hover-stay-time="150">
<slot name="row" v-bind="item">
{{ item }}
</slot>
</view>
</block>
<view v-if="usePage===true" class="loadmore" @click="loadMore">
<u-loadmore :status="loadStatus"></u-loadmore>
</view>
</scroll-view>
<view v-else class="chen-scroll" style="scroll-snap-align:center;">
<text class="u-action-sheet-item u-line-1 u-border-bottom"
style="color: #909399;font-size: 24px">未检索到数据</text>
</view>
</view>
<view class="u-gab"></view>
<view @touchmove.stop.prevent class="u-actionsheet-cancel u-action-sheet-item" hover-class="u-hover-class"
:hover-stay-time="150" @tap="close">取消</view>
</u-popup>
</view>
</template>
<script>
/**
* value 输入框值
* beforeOpenFun 打开选择框之前的校验 return true/false
* getListData: 获取列表值
* inputSubmit: 输入框回车事件
* queryParam: 获取列表值时的参数
* inputPlaceholder: 输入框提示
* maskCloseAble: 点击遮罩是否可以关闭
* usePage: 是否分页
* allowSearch: 是否允许搜索
* doSelected: 点击某一列回调函数
*/
export default {
name: "input-select-dialog",
props: {
value: {
type: [String, Number],
default: ''
},
beforeOpenFun: Function,
getListData: Function,
queryParam: {
type: Object,
default () {
return {
current: 1,
size: 20
};
}
},
inputPlaceholder: {
type: String,
default: '请选择'
},
maskCloseAble: {
type: Boolean,
default: false
},
usePage: {
type: Boolean,
default: false
},
allowSearch: {
type: Boolean,
default: false
},
condition: {
type: String,
default: ''
},
},
data() {
return {
defaultValue: this.value,
show: false,
focus: false,
list: [],
loadStatus: 'loadmore',
}
},
watch: {
show(newValue, oldValue) {
if (newValue) {
this.queryParam.searchText = ""
if (this.usePage) {
this.queryParam.current = 1;
}
this.getData()
}
return false
},
value(newValue, oldValue) {
this.defaultValue = newValue
},
defaultValue(newValue, oldValue) {
this.$emit('update:value', newValue)
}
},
computed: {
uZIndex() {
return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
}
},
methods: {
loadMore() {
if (!this.usePage) {
return
}
this.loadStatus = "loading"
setTimeout(() => {
this.queryParam.current += 1
this.getPageData()
}, 100)
},
search(value) {
this.list = [];
if (this.usePage) {
this.queryParam.current = 1;
}
this.queryParam.searchText = value;
if (this.condition != '') {
this.queryParam[this.condition] = value;
}
this.getData();
},
getData() {
let vm = this
if (vm.usePage) {
vm.list = []
vm.getPageData()
} else {
vm.getNonePageData()
}
},
getPageData() {
let vm = this
let load = function() {
vm.getListData(vm.queryParam).then(function(res) {
if (!res.data.records || res.data.records.length == 0) {
vm.loadStatus = "nomore";
return;
}
vm.list = vm.list.concat(res.data.records);
vm.total = res.data.total;
vm.queryParam.current = res.data.current;
vm.queryParam.size = res.data.size;
vm.loadStatus = "loadmore";
vm.show = true
}).catch(function(e) {
console.log(e)
})
}
if (vm.beforeOpenFun) {
let flag = vm.beforeOpenFun()
if (flag) {
load()
} else {
vm.show = false
}
} else {
load()
}
},
//获取数据
getNonePageData() {
let vm = this
let load = function() {
if (vm.getListData) {
let fetch = vm.getListData(vm.queryParam)
fetch.then(function(resp) {
vm.list = resp.data
vm.show = true
}).catch(function(e) {
console.log(e)
})
}
}
if (vm.beforeOpenFun) {
let flag = vm.beforeOpenFun()
if (flag) {
load()
} else {
vm.show = false
}
} else {
load()
}
},
submit() {
this.$emit('inputSubmit');
},
// 点击取消按钮
close() {
this.popupClose();
},
// 弹窗关闭
popupClose() {
this.show = false
},
//点击列表 返回实体
itemClick(item) {
this.$emit('doSelected', item);
this.popupClose();
},
getFocus() {
let vm = this
vm.focus = false
setTimeout(() => {
vm.focus = true
}, 200)
},
handleBlur() {
this.focus = false
}
}
}
</script>
<style lang="scss" scoped>
@import "@/uview-ui/libs/css/style.components.scss";
/deep/ input :focus {
outline: none;
border-radius: 6rpx;
border-radius: 4px;
border: 1.6px solid #65a0fa;
}
.u-action-sheet-item {
@include vue-flex;
;
line-height: 1;
justify-content: center;
align-items: center;
font-size: 32rpx;
padding: 34rpx 0;
flex-direction: column;
}
.u-gab {
height: 12rpx;
background-color: rgb(234, 234, 236);
}
.u-actionsheet-cancel {
color: $u-main-color;
}
.chen-alter /deep/ .u-mode-center-box {
width: 90% !important;
box-sizing: border-box;
}
.chen-alter /deep/ .uni-scroll-view-content {
height: 900rpx;
box-sizing: border-box;
#chenuserform {
width: 90%;
margin: 90rpx auto 0 auto;
box-sizing: border-box;
.u-form-item--left {
flex: 0 0 170rpx !important;
}
}
}
/deep/ .chen-scroll {
height: 750rpx;
overflow: auto;
}
</style>