search.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="content">
  3. <!-- 导航 -->
  4. <view class="nav">
  5. <view class="leftView" @click="back">
  6. <image src="../../static/mobile/backBtn.png" mode=""
  7. style="width: 22rpx; height: 40rpx; padding-left: 24rpx;"></image>
  8. </view>
  9. <view class="navTitle">搜索</view>
  10. <view class="rightView">
  11. </view>
  12. </view>
  13. <!-- content -->
  14. <view class="commend">
  15. <!-- 搜索 -->
  16. <view class="searchBoxBg">
  17. <searchBox placeholder="请输入搜索内容" @search='search($event)'></searchBox>
  18. </view>
  19. <view class="top">为你找到“{{searchValue}}”相关结果共{{TotalSize}}条</view>
  20. </view>
  21. <!-- item -->
  22. <view class="itemBg">
  23. <view v-for="(item,index) in itemArr" :key="index" class="twoItem" @click="goDetail(item)">
  24. <image :src="item.LogoImg" mode="" class="img2"></image>
  25. <view class="rightItem">
  26. <view class="title">{{item.Title}}</view>
  27. <view class="title2">{{item.Comment}}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 上拉 加载更多 -->
  32. <view class="noMore" v-if="noMoreShow">没有更多数据</view>
  33. <!-- 无数据空白页 -->
  34. <nodata v-if="itemArr.length==0"></nodata>
  35. </view>
  36. </template>
  37. <script>
  38. import searchBox from '@/components/searchBox/searchBox.vue'
  39. import nodata from '../../components/nodata/nodata.vue'
  40. export default {
  41. components: {
  42. searchBox,
  43. nodata
  44. },
  45. data() {
  46. return {
  47. searchValue: '',
  48. page:1,
  49. itemArr: [],
  50. TotalSize:'',
  51. }
  52. },
  53. onLoad() {
  54. },
  55. methods: {
  56. goDetail(item){
  57. uni.navigateTo({
  58. url:'detail?id=' + item.ID
  59. })
  60. },
  61. back() {
  62. uni.navigateBack({
  63. })
  64. },
  65. search(val) {
  66. // console.log(val);
  67. this.searchValue = val
  68. this.page = 1
  69. this.getItemData()
  70. },
  71. getItemData() {
  72. uni.showLoading({
  73. title: '加载中'
  74. })
  75. let url = 'trainingOpenApi/searchPageData',
  76. params = {
  77. page: this.page,
  78. limit: 10,
  79. title: this.searchValue,
  80. }
  81. this.$http(url, params, 'GET').then(res => {
  82. uni.hideLoading();
  83. var data = res.data
  84. // 处理 undefined和null转为空白字符串
  85. for (const key in data) {
  86. data[key] = this.$praseStrEmpty(data[key])
  87. }
  88. this.TotalSize = data.TotalSize
  89. if (this.page == 1) {
  90. this.itemArr = data.Items
  91. } else {
  92. this.itemArr = this.itemArr.concat(data.Items)
  93. }
  94. if (data.Items.length < 10) {
  95. this.noMoreShow = true
  96. } else {
  97. this.noMoreShow = false
  98. }
  99. if (this.itemArr.length == 0) {
  100. this.noMoreShow = false
  101. }
  102. })
  103. },
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .content {
  109. min-height: 100vh;
  110. background-color: #f4f5f7;
  111. padding-top: 88rpx;
  112. padding-bottom: 20rpx;
  113. }
  114. .nav {
  115. position: fixed;
  116. left: 0;
  117. top: 0;
  118. width: 100vw;
  119. height: 88rpx;
  120. background-color: #FFFFFF;
  121. display: flex;
  122. justify-content: space-between;
  123. align-items: center;
  124. z-index: 999;
  125. border-bottom: #eeeeee 2rpx solid;
  126. }
  127. .navTitle {
  128. font-size: 36rpx;
  129. font-weight: bold;
  130. color: #3c3c3c;
  131. }
  132. .leftView {
  133. width: 30%;
  134. }
  135. .rightView {
  136. width: 30%;
  137. display: flex;
  138. justify-content: flex-end;
  139. padding-right: 24rpx;
  140. }
  141. .rightImg {
  142. width: 40rpx;
  143. height: 40rpx;
  144. }
  145. .commend {
  146. position: fixed;
  147. left: 0;
  148. top: 90rpx;
  149. width: calc(100vw - 50rpx);
  150. background-color: #FFFFFF;
  151. padding: 0 25rpx 30rpx;
  152. z-index: 999;
  153. height: 180rpx;
  154. }
  155. .top {
  156. padding: 20rpx 0;
  157. text-align: left;
  158. font-size: 24rpx;
  159. color: #999999;
  160. }
  161. .itemBg {
  162. background-color: #FFFFFF;
  163. padding: 180rpx 25rpx 30rpx;
  164. }
  165. .twoItem {
  166. display: flex;
  167. background-color: #FFFFFF;
  168. padding: 30rpx 0;
  169. border-top: #eeeeee 2rpx solid;
  170. }
  171. .title {
  172. font-size: 28rpx;
  173. font-weight: bold;
  174. color: #3c3c3c;
  175. }
  176. .title2 {
  177. font-size: 24rpx;
  178. font-weight: bold;
  179. color: #999999;
  180. /* 隐藏文字显示 ...不换行 */
  181. overflow: hidden;
  182. text-overflow: ellipsis;
  183. white-space: nowrap;
  184. margin: 14rpx 0;
  185. }
  186. .img2 {
  187. width: 240rpx;
  188. height: 160rpx;
  189. border-radius: 10rpx;
  190. }
  191. .rightItem {
  192. margin-left: 30rpx;
  193. }
  194. .noMore {
  195. text-align: center;
  196. line-height: 50rpx;
  197. color: #999999;
  198. font-size: 28rpx;
  199. }
  200. </style>