emis-app/components/tpx-select/tpx-select.vue

190 lines
4.0 KiB
Vue
Raw Normal View History

2023-12-18 16:30:33 +00:00
<template>
<view class="" style="position: relative;">
2024-01-30 03:09:14 +00:00
<view @click.stop="handleSelectSwitch">
2023-12-18 16:30:33 +00:00
<slot v-if="customInput"></slot>
2024-04-26 06:37:16 +00:00
<default-select-input v-if="!customInput" :placeholder="placeholder" :show="show" :list="filDataList" :value="value" :isWhite="isWhite" :customStyle="customStyle"></default-select-input>
2023-12-18 16:30:33 +00:00
</view>
<view v-if="mode == modeEnum.sheet">
2024-01-29 10:05:13 +00:00
<tpx-dialog :show="show" :title="placeholder" @onClose="handleSelectSwitch">
2024-04-26 10:32:18 +00:00
<view style="height: calc(60vh);">
<tpx-scroll-view :resObject="filResObject" :searchParam="searchParam" :getListFun="getListFun" size="sm" :showLoadedAll="false" @onListChange="onListChange">
<content-items :value="value" :list="filDataList" :minChecked="minChecked" :type="type"
@onChange="handleDataItemChange"
></content-items>
</tpx-scroll-view>
</view>
2023-12-18 16:30:33 +00:00
</tpx-dialog>
</view>
<view v-if="mode == modeEnum.drop && show" class="md-drop-cont">
2024-04-29 02:37:22 +00:00
<tpx-scroll-view :maxHeight="dropMaxHeight" :resObject="filResObject" :searchParam="searchParam" :getListFun="getListFun" size="sm" :showLoadedAll="false" @onListChange="onListChange">
2024-04-26 06:37:16 +00:00
<content-items :value="value" :list="filDataList" :minChecked="minChecked" :type="type"
@onChange="handleDataItemChange"
></content-items>
</tpx-scroll-view>
2023-12-18 16:30:33 +00:00
</view>
</view>
</template>
<script>
import ContentItems from "./content-items"
import DefaultSelectInput from "./default-select-input"
2024-04-26 06:37:16 +00:00
import { transListKeyTitle } from "@/common/util"
2024-04-29 06:51:51 +00:00
import { pageEventNames } from "@/common/enum"
2023-12-18 16:30:33 +00:00
const modeEnum = {
sheet: 'sheet',
drop: 'drop'
}
export default {
2024-04-26 06:37:16 +00:00
computed: {
filDataList() {
let list = (this.getListFun ? this.resObject.list : this.list) || []
if(this.transKeyVal) {
list = transListKeyTitle({ ...this.transKeyVal, list: list })
}
return list
},
filResObject() {
let res = this.getListFun ? this.resObject : { list: this.list, total: this.list.length }
return res
}
},
2023-12-18 16:30:33 +00:00
components: {
ContentItems, DefaultSelectInput
},
props: {
2024-01-29 10:05:13 +00:00
isWhite: {
default () {
return false
}
},
customStyle: {
default () {
return ''
}
},
2023-12-18 16:30:33 +00:00
customInput: {
default () {
return false
}
},
minChecked: {
default () {
return 1
}
},
type: {
default () {
return "single"
}
},
placeholder: {
default () {
2024-01-29 10:05:13 +00:00
return "请选择"
2023-12-18 16:30:33 +00:00
}
},
mode: {
default () {
return modeEnum.sheet
}
},
value: {
default () {
return ""
}
},
2024-04-29 02:37:22 +00:00
dropMaxHeight: {
default () {
2024-04-29 02:47:58 +00:00
return 400
2024-04-29 02:37:22 +00:00
}
},
2023-12-18 16:30:33 +00:00
list: {
default () {
return []
}
2024-04-26 06:37:16 +00:00
},
searchParam: {
default () {
return {}
}
},
getListFun: {
default () {
return null
}
},
resObject: {
default () {
return {
list: []
}
}
},
transKeyVal: {
default () {
return null
// {
// // valKey: '',
// // titleKey: ''
// }
}
2023-12-18 16:30:33 +00:00
}
},
data() {
return {
show: false,
modeEnum: Object.assign({}, modeEnum)
}
},
created() {
2024-04-29 06:51:51 +00:00
uni.$on(pageEventNames.globalClick, this.handleDocumentClick);
2023-12-18 16:30:33 +00:00
},
2024-01-30 03:09:14 +00:00
unmounted() {
2024-04-29 06:51:51 +00:00
uni.$off(pageEventNames.globalClick, this.handleDocumentClick);
2023-12-18 16:30:33 +00:00
},
methods: {
2024-01-30 03:09:14 +00:00
handleDocumentClick(){
this.show = false
},
2023-12-18 16:30:33 +00:00
handleSelectSwitch() {
// this.$emit('update:show', !this.show)
this.show = !this.show
},
handleDataItemChange(val) {
this.$emit('onChange', val)
this.$emit('update:value', val)
if(this.type == "single") {
this.handleSelectSwitch()
}
2024-04-26 06:37:16 +00:00
},
onListChange(val){
this.$emit('update:resObject', val)
2023-12-18 16:30:33 +00:00
}
}
}
</script>
<style scoped lang="scss">
.md-drop-cont{
position: absolute;
background-color: #fff;
border-radius: 10rpx;
border: 2rpx solid #ebeef5;;
top: calc(100% + 8px);
left: 0;
right: 0;
z-index: 10;
padding: 20rpx;
box-sizing: border-box;
border-radius: 6px;
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
}
</style>