首先看一下页面效果:

<template>
<view class="page">
<b-nav-bar title="公司多维图" class="title">
<template slot="left">
<view @click="goBack" class="iconfont icon-zuofanhui nBack ml15"></view>
</template>
</b-nav-bar>
<view class="companyIpt">
<u-search placeholder="请输入上市公司代码或简称" :show-action="false" searchIconColor="#999999" searchIconSize="24"
shape="round" bgColor="#F1F2F4" maxlength="10" placeholderColor="#C0C0C0" v-model="serchVal"
@change="searchCompany" ref="searchIpt"></u-search>
</view>
<view class="serchImg" v-if="showBottomImg"></view>
<view class="noDataBox" v-if="indexList.length == 0 && !showBottomImg">
<view class="noDataImg"></view>
<view class="noDataText">
暂无搜索记录~
</view>
</view>
<u-list @scrolltolower="scrolltolower" class="uList" v-if="indexList.length != 0 && !showBottomImg">
<u-list-item v-for="(item, index) in indexList" :key="index" class="uCellItem">
<u-cell v-html="item.cellText || `${item.title}(${item.code})`" class="uCellStyle" @click="toCompanyPage(item, index)"></u-cell>
</u-list-item>
</u-list>
</view>
</template>

<script>
import { // 接口文件
queryCompanyList
} from "@/api/company.js"
export default {
data() {
return {
wh: 0, // 当前设备可用的高度
scrollTop: 0,
token: '',
account: '',
serchVal: '', // 搜索框值
indexList: [], // 列表数据
cellText: '', // 搜索高亮显示的数据
timer: null, // 定时器
showBottomImg: true
}
},
onLoad(e) {
if (e.token) {
this.token = e.token
sessionStorage.setItem('token', e.token)
}
},
methods: {
goBack() {
this.nativeBack()
},
nativeBack() {
uni.getSystemInfo({
success(res) {
if (res.platform == 'ios') { //iOS返回APP
window.webkit.messageHandlers.backUp.postMessage('123');
} else { //安卓返回APP
if (window.ytyJsApi) {
window.ytyJsApi.backUp()
} else {
uni.showToast({
title: 'window.ytyJsApi.backUp() is null',
icon: "none"
});
}
}
}
})
},

// 验证输入框不能输入表情符
validParams() {
let iconRule = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig
if (iconRule.test(this.serchVal) == true) {
uni.$u.toast('不能输入表情符')
return false
}
return true
},

// 搜索
searchCompany() {
if (this.timer) {
clearTimeout(this.timer);
}
if (this.serchVal.trim() != '' && this.validParams()) {
this.timer = setTimeout(() => {
let params = {
company: this.serchVal.trim()
}
let _this = this
queryCompanyList(params).then(res => {

if (res.code == 0) {
this.indexList = []
this.showBottomImg = false
// 遍历所有对话文本内容
for (let i = 0; i < res.data.length; i++) {
this.cellText = `${res.data[i].title}(${res.data[i].code})`
let item = res.data || {}
// 当对话内容中有包含搜索框中的字符串时(不区分大小写)
var oRegExp = new RegExp('('+this.serchVal.trim()+')',"ig");
this.cellText = this.cellText.replace(oRegExp,`<font style='color:#3849B4;'>$1</font>`
)
//替换所有搜索找到的关键字 更换颜色
this.indexList.push({
cellText: this.cellText,
...item
})
}

} else {
uni.$u.toast(res.msg)
}
})
}, 500)
} else {
this.indexList = []
this.showBottomImg = true
}
},
// 查看公司详情页面跳转
toCompanyPage(item, index) {
let objValues = Object.values(item) // 获取对象值
objValues.forEach((res1, index1) => {
if (index1 == index) {
uni.navigateTo({
url: `/pages/look-company/companyDetail/companyDetail?title=${res1.title}&code=${res1.code}`
})
}
})
},
// 列表下滑
scrolltolower() {
this.loadmore()
},
// 列表加载更多
loadmore() {
for (let i = 0; i < 30; i++) {
this.indexList.push({
url: this.urls[uni.$u.random(0, this.urls.length - 1)]
})
}
}
},
}
</script>

<style lang="scss" scoped>
.page {
width: 100%;
background: #ffffff;

.title {
font-size: 32rpx;
text-align: center;
border-bottom: 1px solid #DCDEE3;

.nBack {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
}

.companyIpt {
width: 690rpx;
height: 66rpx;
line-height: 66rpx;
margin: 20rpx auto 20rpx;
}

.uList {
width: 690rpx;
margin: 0rpx auto;
color: #666666;
font-size: 28rpx;
font-family: PingFang SC;
font-weight: bold;
.uCellItem {
padding: 30rpx 24rpx;
border-bottom: 1px solid #DCDEE3;
}

.uCellStyle {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: bold;
color: #666666;
}
}
.noDataBox {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
.noDataImg {
width: 320rpx;
height: 268rpx;
background-image: url('./../../../static/images/noData.png');
background-size: 100% 100%;
}
.noDataText {
color: #666666;
font-size: 26rpx;
margin-top: 53rpx;
text-align: center;
}
}

.serchImg {
width: 586rpx;
height: 482rpx;
background-image: url('../../../static/images/serch.png');
background-size: 100% 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
}
/deep/ .u-image {
width: 320rpx;
height: 268rpx;
}
/deep/ .u-search__content__input--placeholder {
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 500;
}

/deep/ uni-view,
uni-scroll-view,
uni-swiper-item {
display: block;
}
</style>

最新文章

  1. delegate、notification、KVO场景差别
  2. Java Runtime.availableProcessors()方法
  3. Android课程---视图组件之开关按钮
  4. 算法总结—深度优先搜索DFS
  5. Csharp日常笔记
  6. C#中的二进制序列化和Json序列化
  7. Uniconnection 连 mysql 有时会断线的
  8. angular Jsonp的坑
  9. 服务器返回webview字符串,用该字符串填满整个屏幕,不可缩放
  10. bzoj4476 [Jsoi2015]送礼物
  11. 队列模式&amp;主题模式
  12. Springboot 事务处理常见坑点
  13. python--第十四天总结(js)
  14. 二叉搜索树与双向链表(python)
  15. Centos7 MongoDB-3.4
  16. mybatis学习之路----mysql批量新增数据
  17. Java:The hierarchy of the type is inconsistent错误
  18. UNIX域套接字——UNIX domain socket(DGRAM)
  19. IntelliJ Idea 2018 注册码
  20. package html to native application

热门文章

  1. 2022-11-22学习内容-Client端代码编写-数据删除
  2. ucocIII野火
  3. IDEA使用fastjson1时maven引入依赖没报错,但是用不了JSONObject工具类
  4. 把userId:12323 直接拿到12323
  5. 真实世界的算法_pdf
  6. 服务器5M带宽下载速计算
  7. 综合java admin后台记录
  8. java的Stream
  9. NVI手法实现Template Method设计模式
  10. kibana7.6.2内网windows系统下编译打包部署