collect.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view>
  3. <!-- tab切换 -->
  4. <view class="inv-h-w">
  5. <view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="Inv=0">虫害</view>
  6. <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="Inv=1">病害</view>
  7. </view>
  8. <view class="" v-if="isShow">
  9. <!-- 虫害 -->
  10. <view class="plant_ul" v-show="Inv == 0">
  11. <view class="plant_li" v-for="(item, index) in insectArr">
  12. <u-image shape="square" border-radius="10" width="250rpx" height="200rpx" class="plant_li_img" :src="item.img"></u-image>
  13. <view class="">
  14. <view class="plant_liBox">
  15. <view class="plant_liBox_top">{{ item.name }}</view>
  16. <view class="plant_liBox_center">所属作物:{{ item.host == "" ? '暂未收录' : item.host }}</view>
  17. <view class="plant_liBox_bottom">收藏日期:{{ item.time }}</view>
  18. </view>
  19. <view class="plant_btmHandle">
  20. <view class="plant_btmHandle_cancel" @click="noCollect(index, item.id)">
  21. <image :src="$imageURL_58003+'/bigservers/' + 'images/starA.png'" mode="" class="plant_btmHandle_cancelImg"></image>
  22. <text class="plant_btmHandle_cancelTxt">取消收藏</text>
  23. </view>
  24. <view class="plant_btmHandle_record" @click="defail(item.id)">
  25. <image :src="$imageURL_58003+'/bigservers/' + 'images/detail_8.png'" class="plant_btmHandle_recordImg" mode=""></image>
  26. <text class="plant_btmHandle_recordTxt">查看详情</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 病害 -->
  33. <view class="plant_ul" v-show="Inv == 1">
  34. <view class="plant_li" v-for="(item, index) in plantArr">
  35. <u-image shape="square" border-radius="10" width="250rpx" height="200rpx" class="plant_li_img" :src="item.img"></u-image>
  36. <view>
  37. <view class="plant_liBox">
  38. <view class="plant_liBox_top">{{ item.name }}</view>
  39. <view class="plant_liBox_center">所属作物:{{ item.host == "" ? '暂未收录' : item.host }}</view>
  40. <view class="plant_liBox_bottom">收藏日期:{{ item.time }}</view>
  41. </view>
  42. <view class="plant_btmHandle">
  43. <view class="plant_btmHandle_cancel" @click="noCollect(index, item.id)">
  44. <image :src="$imageURL_58003+'/bigservers/' + 'images/starA.png'" mode="" class="plant_btmHandle_cancelImg"></image>
  45. <text class="plant_btmHandle_cancelTxt">取消收藏</text>
  46. </view>
  47. <view class="plant_btmHandle_record" @click="defail(item.id)">
  48. <image :src="$imageURL_58003+'/bigservers/' + 'images/detail_8.png'" class="plant_btmHandle_recordImg" mode=""></image>
  49. <text class="plant_btmHandle_recordTxt">查看详情</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 暂无 -->
  57. <view class="notDataBox" v-else>
  58. <image :src="$imageURL_58003+'/bigservers/' + 'images/detail_11.png'" class="notDataBox_img" mode=""></image>
  59. </view>
  60. <!-- 返回顶部 -->
  61. <u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
  62. <!-- 弹框提示 -->
  63. <u-top-tips ref="uTips"></u-top-tips>
  64. <view class="isOver" v-if="flag">
  65. ---- 我是有底线的 ----
  66. </view>
  67. <!--loading-->
  68. <ourLoading v-show="loadingShow" isFullScreen active text="加载中..." />
  69. </view>
  70. </template>
  71. <script>
  72. export default {
  73. data() {
  74. return {
  75. Inv: 0,
  76. scrollTop: 0, //返回顶部
  77. insectArr: [], //病虫害列表
  78. plantArr: [],
  79. isShow: true,
  80. dataNum: null, //列表总条数
  81. pageIndex: 1, //当前页数
  82. pagination: null, //总页码
  83. numData: 10, //固定每页显示多少条
  84. listLangth: null, //每次请求数据条数
  85. flag: false,
  86. loadingShow: true, //加载
  87. }
  88. },
  89. watch: {
  90. Inv(val) {
  91. this.dataNum = null //清空
  92. console.log(this.pageIndex)
  93. this.pageIndex = 1 //清空
  94. this.pagination = null //清空
  95. this.listLength = null
  96. this.flag = false
  97. if (val == 0) {
  98. //虫害
  99. this.listData(2)
  100. this.insectArr = []
  101. } else {
  102. //病害
  103. this.listData(1)
  104. this.plantArr = []
  105. }
  106. },
  107. insectArr(val) {
  108. console.log(val)
  109. if (val.length == 0) {
  110. this.isShow = false
  111. }
  112. },
  113. plantArr(val) {
  114. if (val.length == 0) {
  115. this.isShow = false
  116. }
  117. },
  118. },
  119. methods: {
  120. changeTab(Inv) {
  121. that.navIdx = Inv;
  122. },
  123. // 列表数据
  124. listData(numDat) {
  125. var that = this
  126. uni.request({
  127. url: 'user_collect',
  128. method: 'get',
  129. data: {
  130. page: this.pageIndex,
  131. ret: numDat
  132. },
  133. header: {
  134. "Content-Type": "application/x-www-form-urlencoded"
  135. },
  136. dataType: 'json',
  137. success(res) {
  138. if (res.data.code !== "10011") {
  139. that.dataNum = res.data.nums
  140. if (numDat == '1') {
  141. that.plantArr = [...that.plantArr, ...res.data.dat]
  142. var arrayData = that.plantArr
  143. } else {
  144. that.insectArr = [...that.insectArr, ...res.data.dat]
  145. var arrayData = that.insectArr
  146. }
  147. // that.insectArr = res.data.dat
  148. for (var i = 0; i < arrayData.length; i++) {
  149. let Adata = new Array();
  150. Adata = arrayData[i].img_urls.split("#");
  151. arrayData[i].img = Adata[0]
  152. }
  153. that.isShow = true
  154. that.listLength = res.data.dat.length
  155. } else {
  156. that.isShow = false
  157. }
  158. that.loadingShow = false
  159. },
  160. fail(err) {
  161. console.log(err)
  162. that.loadingShow = false
  163. },
  164. complete(com) {
  165. // console.log(com)
  166. }
  167. })
  168. },
  169. defail(id) {
  170. uni.navigateTo({
  171. url: '/pages/details/details?id=' + id + '&signboard=1'
  172. })
  173. },
  174. noCollect(index, id) {
  175. var that = this
  176. let postData = ({
  177. id: id,
  178. ret: 'move'
  179. })
  180. uni.request({
  181. url: 'user_collect',
  182. method: 'post',
  183. data: postData,
  184. header: {
  185. "Content-Type": "application/x-www-form-urlencoded"
  186. },
  187. success(res) {
  188. if (res.data.code == 200) {
  189. that.$refs.uTips.show({
  190. title: '取消收藏成功',
  191. type: 'success',
  192. duration: '1500'
  193. })
  194. if (that.Inv == 0) {
  195. //虫害
  196. that.insectArr.splice(index, 1)
  197. } else {
  198. that.plantArr.splice(index, 1)
  199. }
  200. }
  201. },
  202. fail(err) {
  203. that.$refs.uTips.show({
  204. title: '取消收藏失败',
  205. type: 'error',
  206. duration: '1500'
  207. })
  208. }
  209. })
  210. },
  211. },
  212. onLoad() {
  213. this.listData(2)
  214. },
  215. // 滚动到底翻页
  216. onReachBottom() {
  217. if (this.dataNum !== 0 || this.dataNum !== null) {
  218. if (this.pagination == null) {
  219. var a = this.dataNum
  220. var b = this.numData
  221. var c = a / b
  222. this.pagination = Math.ceil(c)
  223. }
  224. this.pagination--
  225. // if (this.pagination !== 0) {
  226. // this.pageIndex++
  227. // console.log(this.pageIndex)
  228. // if (this.Inv == 0) {
  229. // this.listData(2)
  230. // } else if (this.Inv == 1) {
  231. // this.listData(1)
  232. // }
  233. // } else {
  234. // this.flag = true
  235. // }
  236. if (this.listLength == 10) {
  237. console.log(this.listLength + '_______每次获取到数据的长度-true______')
  238. if (this.pagination >= 1) {
  239. console.log(this.pagination + '_______总页码-true______')
  240. this.pageIndex++
  241. if (this.Inv == 0) {
  242. console.log('_______虫害-true______')
  243. this.listData('2')
  244. } else if (this.Inv == 1) {
  245. console.log('_______病害-false______')
  246. this.listData('1')
  247. }
  248. } else {
  249. console.log(this.pagination + '_______总页码-false______')
  250. this.flag = true
  251. }
  252. } else if (this.listLength < 10) {
  253. console.log(this.listLength + '_______每次获取到数据的长度-false______')
  254. this.flag = true
  255. }
  256. } else {
  257. this.flag = false
  258. }
  259. },
  260. // 监听下拉动作
  261. onPullDownRefresh() {
  262. setTimeout(() => {
  263. this.insectArr = []
  264. this.plantArr = []
  265. if (this.Inv == 0) {
  266. this.listData('2')
  267. } else if (this.Inv == 1) {
  268. this.listData('1')
  269. }
  270. uni.stopPullDownRefresh()
  271. },2000)
  272. },
  273. // 监听获取滚动条位置
  274. onPageScroll(e) {
  275. this.scrollTop = e.scrollTop;
  276. },
  277. }
  278. </script>
  279. <style lang="scss">
  280. // tab切换
  281. page {
  282. background-color: #f7f8fc;
  283. }
  284. .inv-h-w {
  285. background-color: #FFFFFF;
  286. height: 100upx;
  287. display: flex;
  288. }
  289. .inv-h {
  290. font-size: 30upx;
  291. flex: 1;
  292. text-align: center;
  293. color: #C9C9C9;
  294. height: 100upx;
  295. line-height: 100upx;
  296. }
  297. .inv-h-se {
  298. color: #20c7a1;
  299. border-bottom: 4upx solid #20c7a1;
  300. }
  301. // 内容列表
  302. .plant_ul {
  303. .plant_li {
  304. border-radius: 6px;
  305. background: #fff;
  306. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  307. display: flex;
  308. width: 720rpx;
  309. margin: 15rpx auto;
  310. padding: 15rpx 20rpx 15rpx 20rpx;
  311. .plant_li_img {
  312. width: 250rpx;
  313. height: 200rpx;
  314. border-radius: 5px;
  315. }
  316. .plant_liBox {
  317. // border: 1px solid #007AFF;
  318. padding: 5rpx 0 15rpx 0;
  319. margin: 0 0 0 35rpx;
  320. .plant_liBox_top {
  321. font-weight: 550;
  322. font-size: 17px;
  323. margin-bottom: 10rpx;
  324. }
  325. .plant_liBox_center {
  326. color: #9d9d9d;
  327. font-size: 12px;
  328. margin-bottom: 10rpx;
  329. width: 350rpx;
  330. height: 50rpx;
  331. white-space: nowrap;
  332. text-overflow: ellipsis;
  333. overflow: hidden;
  334. }
  335. .plant_liBox_bottom {
  336. color: #9d9d9d;
  337. font-size: 12px;
  338. }
  339. }
  340. // 取消收藏and查看详情
  341. .plant_btmHandle {
  342. border-top: 1px solid #f2f2f2;
  343. padding: 5rpx 0 15rpx 0;
  344. margin: 0 0 0 35rpx;
  345. display: flex;
  346. justify-content: center;
  347. .plant_btmHandle_cancel {
  348. border-right: 1px solid #f2f2f2;
  349. padding: 0 20rpx 0 0;
  350. margin: 10rpx 0 0 0;
  351. .plant_btmHandle_cancelImg {
  352. width: 35rpx;
  353. height: 35rpx;
  354. margin: -5rpx 0 0 0;
  355. vertical-align: middle;
  356. }
  357. .plant_btmHandle_cancelTxt {
  358. color: #999999;
  359. font-size: 13px;
  360. margin: 0 0 0 5rpx;
  361. }
  362. }
  363. .plant_btmHandle_record {
  364. padding: 0 0 0 20rpx;
  365. margin: 10rpx 0 0 0;
  366. .plant_btmHandle_recordImg {
  367. width: 30rpx;
  368. height: 30rpx;
  369. margin: -5rpx 0 0 0;
  370. vertical-align: middle;
  371. }
  372. .plant_btmHandle_recordTxt {
  373. color: #999999;
  374. font-size: 13px;
  375. margin: 0 0 0 5rpx;
  376. }
  377. }
  378. }
  379. }
  380. }
  381. // 暂无数据
  382. .notDataBox {
  383. .notDataBox_img {
  384. display: block;
  385. margin: 300rpx auto;
  386. width: 300rpx;
  387. height: 300rpx;
  388. }
  389. }
  390. .isOver {
  391. width: 100%;
  392. height: 50px;
  393. line-height: 50px;
  394. text-align: center;
  395. // background: #fff;
  396. font-size: 28rpx;
  397. }
  398. </style>