| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- <template>
- <view>
- <!-- 搜索 -->
- <u-search maxlength="20" @search="seek" bg-color="#fff" margin="15rpx auto" :input-style="{width: '20rpx'}"
- input-align="center" :animation="true" placeholder="搜索虫害或病害名称(按回车键或搜索进行查询)" shape="square" :show-action="false"
- v-model="keyword"></u-search>
- <!-- tab切换 -->
- <view class="inv-h-w">
- <view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="Inv=0">虫害</view>
- <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="Inv=1">病害</view>
- </view>
- <view v-if="searchShow">
- <view v-if="isShow">
- <!-- 虫害 -->
- <view class="" v-show="Inv == 0">
- <view class="repository_ul">
- <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in insectArr" :key="index">
- <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
- <view class="">
- {{ item.name }}
- </view>
- </view>
- </view>
- </view>
- <!-- 病害 -->
- <view class="" v-show="Inv == 1">
- <view class="repository_ul">
- <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in plantArr" :key="index">
- <!-- <image :src="item.thumb" mode=""></image> -->
- <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
- <view class="">
- {{ item.name }}
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 暂无 -->
- <view class="notDataBox" v-else>
- <image :src="$imageHost+'/bigservers/' + 'images/detail_11.png'" class="notDataBox_img" mode=""></image>
- </view>
- <!-- -->
- <view class="isOver" v-show="flag">
- ---- 我是有底线的 ----
- </view>
- </view>
- <!-- 搜索 -->
- <view class="searchBox" v-else>
- <!-- <image class="searchBox_img" :src="$imageHost+'/bigservers/' + 'images/search.gif'" mode=""></image> -->
- <view v-if="isShow">
- <!-- 虫害 -->
- <view class="" v-show="Inv == 0">
- <view class="repository_ul">
- <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in insectArrA" :key="index">
- <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
- <view class="">
- {{ item.name }}
- </view>
- </view>
- </view>
- </view>
- <!-- 病害 -->
- <view class="" v-show="Inv == 1">
- <view class="repository_ul">
- <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in plantArrA" :key="index">
- <!-- <image :src="item.thumb" mode=""></image> -->
- <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
- <view class="">
- {{ item.name }}
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 暂无 -->
- <view class="notDataBox" v-else>
- <image :src="$imageHost+'/bigservers/' + 'images/detail_11.png'" class="notDataBox_img" mode=""></image>
- </view>
- <!-- -->
- <view class="isOver" v-show="flag">
- ---- 我是有底线的 ----
- </view>
- </view>
- <!-- 返回顶部 -->
- <u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
- <!--loading-->
- <ourLoading v-show="loadingShow" isFullScreen active text="加载中..." />
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- searchShow: true, //搜索
- keyword: '', //搜索
- Inv: 0,
- insectArr: [],
- plantArr: [],
- insectArrA: [], //搜索
- plantArrA: [], //搜索
- dataNum: null, //列表总条数
- pageIndex: 1, //当前页数
- flag: false,
- numData: 10, //固定每页显示多少条
- pagination: null, //总页码
- scrollTop: 0, //返回顶部
- isShow: true, //暂无
- listLangth: null, //每次请求数据条数
- loadingShow: true, //加载
- listLength: null, //数据长度
- }
- },
- // 监听data中的变化
- watch: {
- Inv(val) {
- this.dataNum = null //清空
- this.scrollTop = 0
- this.pageIndex = 1 //清空
- this.pagination = null //清空
- this.insectArr = []
- this.plantArr = []
- this.insectArrA = []
- this.plantArrA = []
- this.listLength = null
- this.flag = false
- this.keyword = ''
- this.scrollTop = 0
- this.listData()
- uni.pageScrollTo({
- scrollTop: 0
- })
- },
- keyword(val) {
- if (val == '') {
- this.dataNum = null //清空
- this.pageIndex = 1 //清空
- this.pagination = null //清空
- this.listLength = null
- this.searchShow = true
- this.flag = false
- this.insectArrA = []
- this.plantArrA = []
- this.listData()
- } else if (val !== '') {
- this.dataNum = null //清空
- this.pageIndex = 1 //清空
- this.pagination = null //清空
- this.listLength = null
- }
- }
- },
- methods: {
- changeTab(Inv) {
- that.navIdx = Inv;
- },
- // 列表数据请求
- listData() {
- if (this.Inv == 0) {
- var ret = '2'
- } else if (this.Inv == 1) {
- var ret = '1'
- }
- let postData = ({
- ret: ret,
- page: this.pageIndex,
- });
- // console.log(this.pageIndex)
- let that = this;
- var pages = that.pageIndex
- uni.request({
- url: 'see_dase',
- data: postData,
- method: 'POST',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- dataType: 'json',
- success(res) {
- that.dataNum = res.data.num
- if (res.data.dat.length !== 0) {
- if (ret == '1') {
- if (postData.page == 1 && that.plantArr.length == 10 ) {
-
- } else {
- that.plantArr = [...that.plantArr, ...res.data.dat]
- }
- } else {
- // console.log(that.insectArr)
- if (postData.page == 1 && that.insectArr.length == 10) {
- } else {
- that.insectArr = [...that.insectArr, ...res.data.dat]
- }
- // console.log(that.insectArr)
- }
- // console.log(that.insectArr)
- that.isShow = true
- that.listLength = res.data.dat.length
- that.loadingShow = false
- } else {
- that.isShow = false
- }
- },
- fail(err) {
- console.log(err)
- },
- complete(com) {}
- })
- },
- // 点击进入详情
- defails(id) {
- uni.navigateTo({
- url: '/pages/details/details?id=' + id + '&signboard=1'
- })
- },
- // 搜索
- seek() {
- var that = this
- that.searchShow = false
- // 判断
- if (that.Inv == 0) {
- var ret = '2'
- } else if (that.Inv == 1) {
- var ret = '1'
- }
- uni.request({
- url: 'search',
- data: {
- name: that.keyword,
- ret, //1病 2虫
- page: that.pageIndex
- },
- method: 'POST',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- dataType: 'json',
- success(res) {
- that.dataNum = res.data.num
- if (res.data.dat.length !== 0) {
- if (ret == '1') {
- that.plantArrA = [...that.plantArrA, ...res.data.dat]
- } else {
- that.insectArrA = [...that.insectArrA, ...res.data.dat]
- }
- that.isShow = true
- that.listLength = res.data.dat.length
- that.loadingShow = false
- } else {
- that.isShow = false
- }
- },
- fail(err) {
- console.log(err)
- },
- complete(com) {
- that.searchShow = false
- }
- })
- },
- },
- // 初始化
- onLoad() {
- this.listData()
- },
- // 滚动到底翻页
- onReachBottom() {
- if (this.dataNum !== 0 || this.dataNum !== null) {
- if (this.pagination == null) {
- var a = this.dataNum
- var b = this.numData
- var c = a / b
- this.pagination = Math.ceil(c)
- }
- this.pagination--
- if (this.keyword !== '') {
- // 搜索数据
- if (this.listLength == 10) {
- if (this.pagination >= 1) {
- this.pageIndex++
- this.seek()
- } else {
- this.flag = true
- }
- } else if (this.listLength < 10) {
- this.flag = true
- }
- } else if (this.keyword == '') {
- // 列表数据
- if (this.listLength == 10) {
- if (this.pagination >= 1) {
- this.pageIndex++
- this.listData()
- } else {
- this.flag = true
- }
- } else if (this.listLength < 10) {
- this.flag = true
- }
- }
- } else {
- this.flag = true
- }
- },
- // 监听下拉动作
- onPullDownRefresh() {
- setTimeout(() => {
- // console.log(this.insectArrA)
- this.insectArr = [],
- this.plantArr = [],
- this.plantArrA = [],
- this.insectArrA = [],
- // console.log(this.insectArrA)
- this.pageIndex = 1
- this.pagination = null
- this.keyword = ''
- this.flag = false
- this.listData()
- uni.stopPullDownRefresh()
- }, 2000)
- },
- // 监听获取滚动条位置
- onPageScroll(e) {
- this.scrollTop = e.scrollTop;
- },
- }
- </script>
- <style lang="scss">
- // 搜索
- // uni-view,
- // uni-text {
- // width: 740rpx;
- // margin: 0 auto;
- // }
- // tab切换
- .inv-h-w {
- background-color: #FFFFFF;
- height: 100upx;
- display: flex;
- }
- .inv-h {
- font-size: 30upx;
- flex: 1;
- text-align: center;
- color: #C9C9C9;
- height: 100upx;
- line-height: 100upx;
- }
- .inv-h-se {
- color: #20c7a1;
- border-bottom: 4upx solid #20c7a1;
- }
- page {
- background-color: #f7f8fc;
- }
- // 内容
- .repository_ul {
- // border: 1px solid #000;
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- // width: 750rpx;
- margin: 15rpx 17rpx 15rpx 17rpx;
- .repository_list {
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
- width: 350rpx;
- padding: 10rpx 0 0 0;
- background: #fff;
- margin-bottom: 15rpx;
- border-radius: 5px;
- // image {
- // width: 320rpx;
- // height: 230rpx;
- // display: block;
- // margin: 0 auto;
- // }
- .repository_listImg {
- width: 320rpx;
- height: 230rpx;
- display: block;
- margin: 0 auto;
- }
- view {
- color: #5e5e5e;
- text-align: left;
- margin-left: 12rpx;
- padding: 5rpx 0 5rpx 0;
- }
- }
- }
- // .repository_ul:after {
- // content: "";
- // flex: auto;
- // }
- .isOver {
- width: 100%;
- height: 50px;
- line-height: 50px;
- text-align: center;
- // background: #fff;
- font-size: 28rpx;
- }
- // 暂无数据
- .notDataBox {
- .notDataBox_img {
- display: block;
- margin: 300rpx auto;
- width: 300rpx;
- height: 300rpx;
- }
- }
- // 搜索动画
- .searchBox {
- .searchBox_img {
- margin: 0 auto;
- display: block;
- width: 350rpx;
- height: 350rpx;
- }
- }
- </style>
|