repository.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <view>
  3. <!-- 搜索 -->
  4. <u-search maxlength="20" @search="seek" bg-color="#fff" margin="15rpx auto" :input-style="{width: '20rpx'}"
  5. input-align="center" :animation="true" placeholder="搜索虫害或病害名称(按回车键或搜索进行查询)" shape="square" :show-action="false"
  6. v-model="keyword"></u-search>
  7. <!-- tab切换 -->
  8. <view class="inv-h-w">
  9. <view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="Inv=0">虫害</view>
  10. <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="Inv=1">病害</view>
  11. </view>
  12. <view v-if="searchShow">
  13. <view v-if="isShow">
  14. <!-- 虫害 -->
  15. <view class="" v-show="Inv == 0">
  16. <view class="repository_ul">
  17. <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in insectArr" :key="index">
  18. <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
  19. <view class="">
  20. {{ item.name }}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 病害 -->
  26. <view class="" v-show="Inv == 1">
  27. <view class="repository_ul">
  28. <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in plantArr" :key="index">
  29. <!-- <image :src="item.thumb" mode=""></image> -->
  30. <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
  31. <view class="">
  32. {{ item.name }}
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 暂无 -->
  39. <view class="notDataBox" v-else>
  40. <image :src="$imageURL_58003+'/bigservers/' + 'images/detail_11.png'" class="notDataBox_img" mode=""></image>
  41. </view>
  42. <!-- -->
  43. <view class="isOver" v-show="flag">
  44. ---- 我是有底线的 ----
  45. </view>
  46. </view>
  47. <!-- 搜索 -->
  48. <view class="searchBox" v-else>
  49. <!-- <image class="searchBox_img" :src="$imageURL_58003+'/bigservers/' + 'images/search.gif'" mode=""></image> -->
  50. <view v-if="isShow">
  51. <!-- 虫害 -->
  52. <view class="" v-show="Inv == 0">
  53. <view class="repository_ul">
  54. <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in insectArrA" :key="index">
  55. <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
  56. <view class="">
  57. {{ item.name }}
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 病害 -->
  63. <view class="" v-show="Inv == 1">
  64. <view class="repository_ul">
  65. <view class="repository_list" @click="defails(item.id)" v-for="(item, index) in plantArrA" :key="index">
  66. <!-- <image :src="item.thumb" mode=""></image> -->
  67. <u-image width="320rpx" height="230rpx" class="repository_listImg" :src="item.thumb"></u-image>
  68. <view class="">
  69. {{ item.name }}
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 暂无 -->
  76. <view class="notDataBox" v-else>
  77. <image :src="$imageURL_58003+'/bigservers/' + 'images/detail_11.png'" class="notDataBox_img" mode=""></image>
  78. </view>
  79. <!-- -->
  80. <view class="isOver" v-show="flag">
  81. ---- 我是有底线的 ----
  82. </view>
  83. </view>
  84. <!-- 返回顶部 -->
  85. <u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
  86. <!--loading-->
  87. <ourLoading v-show="loadingShow" isFullScreen active text="加载中..." />
  88. </view>
  89. </template>
  90. <script>
  91. export default {
  92. data() {
  93. return {
  94. searchShow: true, //搜索
  95. keyword: '', //搜索
  96. Inv: 0,
  97. insectArr: [],
  98. plantArr: [],
  99. insectArrA: [], //搜索
  100. plantArrA: [], //搜索
  101. dataNum: null, //列表总条数
  102. pageIndex: 1, //当前页数
  103. flag: false,
  104. numData: 10, //固定每页显示多少条
  105. pagination: null, //总页码
  106. scrollTop: 0, //返回顶部
  107. isShow: true, //暂无
  108. listLangth: null, //每次请求数据条数
  109. loadingShow: true, //加载
  110. listLength: null, //数据长度
  111. }
  112. },
  113. // 监听data中的变化
  114. watch: {
  115. Inv(val) {
  116. this.dataNum = null //清空
  117. this.scrollTop = 0
  118. this.pageIndex = 1 //清空
  119. this.pagination = null //清空
  120. this.insectArr = []
  121. this.plantArr = []
  122. this.insectArrA = []
  123. this.plantArrA = []
  124. this.listLength = null
  125. this.flag = false
  126. this.keyword = ''
  127. this.scrollTop = 0
  128. this.listData()
  129. uni.pageScrollTo({
  130. scrollTop: 0
  131. })
  132. },
  133. keyword(val) {
  134. if (val == '') {
  135. this.dataNum = null //清空
  136. this.pageIndex = 1 //清空
  137. this.pagination = null //清空
  138. this.listLength = null
  139. this.searchShow = true
  140. this.flag = false
  141. this.insectArrA = []
  142. this.plantArrA = []
  143. this.listData()
  144. } else if (val !== '') {
  145. this.dataNum = null //清空
  146. this.pageIndex = 1 //清空
  147. this.pagination = null //清空
  148. this.listLength = null
  149. }
  150. }
  151. },
  152. methods: {
  153. changeTab(Inv) {
  154. that.navIdx = Inv;
  155. },
  156. // 列表数据请求
  157. listData() {
  158. if (this.Inv == 0) {
  159. var ret = '2'
  160. } else if (this.Inv == 1) {
  161. var ret = '1'
  162. }
  163. let postData = ({
  164. ret: ret,
  165. page: this.pageIndex,
  166. });
  167. // console.log(this.pageIndex)
  168. let that = this;
  169. var pages = that.pageIndex
  170. uni.request({
  171. url: 'see_dase',
  172. data: postData,
  173. method: 'POST',
  174. header: {
  175. "Content-Type": "application/x-www-form-urlencoded"
  176. },
  177. dataType: 'json',
  178. success(res) {
  179. that.dataNum = res.data.num
  180. if (res.data.dat.length !== 0) {
  181. if (ret == '1') {
  182. if (postData.page == 1 && that.plantArr.length == 10 ) {
  183. } else {
  184. that.plantArr = [...that.plantArr, ...res.data.dat]
  185. }
  186. } else {
  187. // console.log(that.insectArr)
  188. if (postData.page == 1 && that.insectArr.length == 10) {
  189. } else {
  190. that.insectArr = [...that.insectArr, ...res.data.dat]
  191. }
  192. // console.log(that.insectArr)
  193. }
  194. // console.log(that.insectArr)
  195. that.isShow = true
  196. that.listLength = res.data.dat.length
  197. that.loadingShow = false
  198. } else {
  199. that.isShow = false
  200. }
  201. },
  202. fail(err) {
  203. console.log(err)
  204. },
  205. complete(com) {}
  206. })
  207. },
  208. // 点击进入详情
  209. defails(id) {
  210. uni.navigateTo({
  211. url: '/pages/details/details?id=' + id + '&signboard=1'
  212. })
  213. },
  214. // 搜索
  215. seek() {
  216. var that = this
  217. that.searchShow = false
  218. // 判断
  219. if (that.Inv == 0) {
  220. var ret = '2'
  221. } else if (that.Inv == 1) {
  222. var ret = '1'
  223. }
  224. uni.request({
  225. url: 'search',
  226. data: {
  227. name: that.keyword,
  228. ret, //1病 2虫
  229. page: that.pageIndex
  230. },
  231. method: 'POST',
  232. header: {
  233. "Content-Type": "application/x-www-form-urlencoded"
  234. },
  235. dataType: 'json',
  236. success(res) {
  237. that.dataNum = res.data.num
  238. if (res.data.dat.length !== 0) {
  239. if (ret == '1') {
  240. that.plantArrA = [...that.plantArrA, ...res.data.dat]
  241. } else {
  242. that.insectArrA = [...that.insectArrA, ...res.data.dat]
  243. }
  244. that.isShow = true
  245. that.listLength = res.data.dat.length
  246. that.loadingShow = false
  247. } else {
  248. that.isShow = false
  249. }
  250. },
  251. fail(err) {
  252. console.log(err)
  253. },
  254. complete(com) {
  255. that.searchShow = false
  256. }
  257. })
  258. },
  259. },
  260. // 初始化
  261. onLoad() {
  262. this.listData()
  263. },
  264. // 滚动到底翻页
  265. onReachBottom() {
  266. if (this.dataNum !== 0 || this.dataNum !== null) {
  267. if (this.pagination == null) {
  268. var a = this.dataNum
  269. var b = this.numData
  270. var c = a / b
  271. this.pagination = Math.ceil(c)
  272. }
  273. this.pagination--
  274. if (this.keyword !== '') {
  275. // 搜索数据
  276. if (this.listLength == 10) {
  277. if (this.pagination >= 1) {
  278. this.pageIndex++
  279. this.seek()
  280. } else {
  281. this.flag = true
  282. }
  283. } else if (this.listLength < 10) {
  284. this.flag = true
  285. }
  286. } else if (this.keyword == '') {
  287. // 列表数据
  288. if (this.listLength == 10) {
  289. if (this.pagination >= 1) {
  290. this.pageIndex++
  291. this.listData()
  292. } else {
  293. this.flag = true
  294. }
  295. } else if (this.listLength < 10) {
  296. this.flag = true
  297. }
  298. }
  299. } else {
  300. this.flag = true
  301. }
  302. },
  303. // 监听下拉动作
  304. onPullDownRefresh() {
  305. setTimeout(() => {
  306. // console.log(this.insectArrA)
  307. this.insectArr = [],
  308. this.plantArr = [],
  309. this.plantArrA = [],
  310. this.insectArrA = [],
  311. // console.log(this.insectArrA)
  312. this.pageIndex = 1
  313. this.pagination = null
  314. this.keyword = ''
  315. this.flag = false
  316. this.listData()
  317. uni.stopPullDownRefresh()
  318. }, 2000)
  319. },
  320. // 监听获取滚动条位置
  321. onPageScroll(e) {
  322. this.scrollTop = e.scrollTop;
  323. },
  324. }
  325. </script>
  326. <style lang="scss">
  327. // 搜索
  328. // uni-view,
  329. // uni-text {
  330. // width: 740rpx;
  331. // margin: 0 auto;
  332. // }
  333. // tab切换
  334. .inv-h-w {
  335. background-color: #FFFFFF;
  336. height: 100upx;
  337. display: flex;
  338. }
  339. .inv-h {
  340. font-size: 30upx;
  341. flex: 1;
  342. text-align: center;
  343. color: #C9C9C9;
  344. height: 100upx;
  345. line-height: 100upx;
  346. }
  347. .inv-h-se {
  348. color: #20c7a1;
  349. border-bottom: 4upx solid #20c7a1;
  350. }
  351. page {
  352. background-color: #f7f8fc;
  353. }
  354. // 内容
  355. .repository_ul {
  356. // border: 1px solid #000;
  357. display: flex;
  358. flex-wrap: wrap;
  359. justify-content: space-between;
  360. // width: 750rpx;
  361. margin: 15rpx 17rpx 15rpx 17rpx;
  362. .repository_list {
  363. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  364. width: 350rpx;
  365. padding: 10rpx 0 0 0;
  366. background: #fff;
  367. margin-bottom: 15rpx;
  368. border-radius: 5px;
  369. // image {
  370. // width: 320rpx;
  371. // height: 230rpx;
  372. // display: block;
  373. // margin: 0 auto;
  374. // }
  375. .repository_listImg {
  376. width: 320rpx;
  377. height: 230rpx;
  378. display: block;
  379. margin: 0 auto;
  380. }
  381. view {
  382. color: #5e5e5e;
  383. text-align: left;
  384. margin-left: 12rpx;
  385. padding: 5rpx 0 5rpx 0;
  386. }
  387. }
  388. }
  389. // .repository_ul:after {
  390. // content: "";
  391. // flex: auto;
  392. // }
  393. .isOver {
  394. width: 100%;
  395. height: 50px;
  396. line-height: 50px;
  397. text-align: center;
  398. // background: #fff;
  399. font-size: 28rpx;
  400. }
  401. // 暂无数据
  402. .notDataBox {
  403. .notDataBox_img {
  404. display: block;
  405. margin: 300rpx auto;
  406. width: 300rpx;
  407. height: 300rpx;
  408. }
  409. }
  410. // 搜索动画
  411. .searchBox {
  412. .searchBox_img {
  413. margin: 0 auto;
  414. display: block;
  415. width: 350rpx;
  416. height: 350rpx;
  417. }
  418. }
  419. </style>