Files
property-manager-side/wuye-manager-uniapp/pageSubPack/instrument/checkouthouse.vue

229 lines
5.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="page_container checkouthouse_box flex flex-col">
<view class="search_box">
<view
@click="handleClick"
class="search_view flex-center"
v-if="!queryParmas.keyword.trim() && Searching"
>
<uni-icons type="search" size="34rpx" color="rgba(0,0,0,0.26)"></uni-icons>
<text>请输入关键字进行搜索</text>
</view>
<uni-easyinput
@blur="handleInput"
@change="handleSearch"
:focus="true"
ref="inputRef"
v-model="queryParmas.keyword"
v-else
/>
</view>
<view class="search_list flex-1 flex">
<scroll-view lower-threshold="160" scroll-y="true" @scrolltolower="scrolltolower">
<radio-group @change="radioChange">
<label v-for="(item, index) in searchlist" :key="index">
<view
class="search_item flex flex-between"
:class="{
active: checkoutHouseid === item.houseId
}"
>
<view class="flex items-center flex-1">
<!-- checkout -->
<radio color="#4d5dfa" :value="item.houseId" />
<!-- housename -->
<text class="address">{{ item.addressCn ?? item.addressHyphen }}</text>
</view>
<!-- username -->
<view class="username">{{ item.residentName }}</view>
</view>
</label>
</radio-group>
</scroll-view>
</view>
<view class="action_btn" @tap="handleSelecthouse">
<text>确 认</text>
</view>
</view>
<!-- 滚动 高度如何计算? -->
</template>
<script setup>
import { ref, getCurrentInstance, onMounted } from 'vue'
import { getVillageHouseList_keyword } from '@/api/common.js'
const Searching = ref(true)
const queryParmas = ref({
keyword: '',
pageNum: 1,
pageSize: 10
})
/** 点击时切换到input,并聚焦 */
function handleClick() {
Searching.value = false
}
/** 判断 失去焦点时 切换回 view */
function handleInput() {
if (queryParmas.value.keyword.trim()) {
Searching.value = true
}
}
const checkoutHouseid = ref(null)
const checkoutHouseInfo = ref(null)
/** 选择房屋,返回id*/
function radioChange(res) {
checkoutHouseid.value = res.detail.value
const find = searchlist.value.find(item => item.houseId === res.detail.value)
if (find) {
checkoutHouseInfo.value = find
}
}
// -0---------------------------------------
const searchlist = ref([])
const isLoading = ref(false) // 加载锁
const hasMore = ref(true) // 是否还有更多数据
const total = ref(0)
function scrolltolower() {
// 必须加这两个判断!
if (isLoading.value || !hasMore.value) {
return
}
queryParmas.value.pageNum += 1
getlist()
}
function getlist() {
// 1. 如果正在加载或没有更多数据,直接返回
if (isLoading.value || !hasMore.value) return
// 2. 开启锁
isLoading.value = true
uni.showLoading({
title: '加载中',
mask: true
})
getVillageHouseList_keyword(queryParmas.value, queryParmas.value.keyword)
.then(res => {
// 追加数据(正确方式)
searchlist.value = [...searchlist.value, ...res.rows]
// 判断是否还有更多
hasMore.value = searchlist.value.length < total.value
})
.finally(() => {
isLoading.value = false
uni.hideLoading()
})
}
getlist()
// 重置list
function resetList() {
searchlist.value = []
queryParmas.value.pageNum = 1
hasMore.value = true
getlist()
}
// Search
function handleSearch() {
queryParmas.value.pageNum = 1
queryParmas.value.pageSize = 10
searchlist.value = []
getlist()
}
// ----------------------------------------
let eventChannel = null
// 必须在 onMounted 里获取
onMounted(() => {
const instance = getCurrentInstance().proxy
if (instance && instance.getOpenerEventChannel) {
eventChannel = instance.getOpenerEventChannel()
}
})
function handleSelecthouse() {
if (!eventChannel) return
eventChannel.emit('backData', {
Houseid: checkoutHouseid.value,
HouseName: checkoutHouseInfo.value.addressCn ?? checkoutHouseInfo.value.addressHyphen
})
// 3. 返回上一页
uni.navigateBack()
}
</script>
<style scoped lang="scss">
.checkouthouse_box {
background: #f9f9f9;
.search_box {
height: 80rpx;
.search_view {
height: 80rpx;
line-height: 80rpx;
background: #f3f3f3;
border-radius: 8rpx;
font-weight: 400;
font-size: 32rpx;
color: rgba(0, 0, 0, 0.26);
line-height: 48rpx;
text-align: center;
}
}
.search_list {
height: 100%;
margin-top: 20rpx;
box-sizing: border-box;
overflow: hidden;
.search_item {
height: 116rpx;
margin-bottom: 20rpx;
background-color: #ffffff;
box-sizing: border-box;
padding: 40rpx;
padding-right: 0;
&:deep(radio) {
transform: scale(0.68);
}
.address {
margin-left: 20rpx;
font-weight: 550;
font-size: 32rpx;
color: #222222;
line-height: 40rpx;
}
.username {
font-weight: 550;
font-size: 32rpx;
color: #222222;
line-height: 40rpx;
width: 180rpx;
text-align: left;
}
&.active {
background: #f5faff;
border: 1rpx solid #4d5dfa;
}
}
}
.action_btn {
width: 670rpx;
height: 80rpx;
font-weight: 400;
font-size: 28rpx;
color: #ffffff;
line-height: 80rpx;
text-align: center;
margin-top: 20rpx;
background: #4d5dfa;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
}
</style>