search.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. noMoreShow:false,
  52. }
  53. },
  54. onLoad() {
  55. },
  56. methods: {
  57. goDetail(item){
  58. uni.navigateTo({
  59. url:'detail?id=' + item.ID
  60. })
  61. },
  62. back() {
  63. uni.navigateBack({
  64. })
  65. },
  66. search(val) {
  67. console.log(val);
  68. this.searchValue = val
  69. if (this.searchValue.length != 0) {
  70. this.page = 1
  71. this.getItemData()
  72. }
  73. else{
  74. this.itemArr=[];
  75. this.TotalSize=''
  76. this.noMoreShow = false
  77. }
  78. },
  79. getItemData() {
  80. uni.showLoading({
  81. title: '加载中'
  82. })
  83. let url = 'trainingOpenApi/searchPageData',
  84. params = {
  85. page: this.page,
  86. limit: 10,
  87. title: this.searchValue,
  88. }
  89. this.$http(url, params, 'GET').then(res => {
  90. uni.hideLoading();
  91. var data = res.data
  92. // 处理 undefined和null转为空白字符串
  93. for (const key in data) {
  94. data[key] = this.$praseStrEmpty(data[key])
  95. }
  96. this.TotalSize = data.TotalSize
  97. if (this.page == 1) {
  98. this.itemArr = data.Items
  99. } else {
  100. this.itemArr = this.itemArr.concat(data.Items)
  101. }
  102. if (data.Items.length < 10) {
  103. this.noMoreShow = true
  104. } else {
  105. this.noMoreShow = false
  106. }
  107. if (this.itemArr.length == 0) {
  108. this.noMoreShow = false
  109. }
  110. })
  111. },
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. .content {
  117. min-height: 100vh;
  118. background-color: #f4f5f7;
  119. padding-top: 88rpx;
  120. padding-bottom: 20rpx;
  121. }
  122. .nav {
  123. position: fixed;
  124. left: 0;
  125. top: 0;
  126. width: 100vw;
  127. height: 88rpx;
  128. background-color: #FFFFFF;
  129. display: flex;
  130. justify-content: space-between;
  131. align-items: center;
  132. z-index: 999;
  133. border-bottom: #eeeeee 2rpx solid;
  134. }
  135. .navTitle {
  136. font-size: 36rpx;
  137. font-weight: bold;
  138. color: #3c3c3c;
  139. }
  140. .leftView {
  141. width: 30%;
  142. }
  143. .rightView {
  144. width: 30%;
  145. display: flex;
  146. justify-content: flex-end;
  147. padding-right: 24rpx;
  148. }
  149. .rightImg {
  150. width: 40rpx;
  151. height: 40rpx;
  152. }
  153. .commend {
  154. position: fixed;
  155. left: 0;
  156. top: 90rpx;
  157. width: calc(100vw - 50rpx);
  158. background-color: #FFFFFF;
  159. padding: 0 25rpx 30rpx;
  160. z-index: 999;
  161. height: 180rpx;
  162. }
  163. .top {
  164. padding: 20rpx 0;
  165. text-align: left;
  166. font-size: 24rpx;
  167. color: #999999;
  168. }
  169. .itemBg {
  170. background-color: #FFFFFF;
  171. padding: 180rpx 25rpx 30rpx;
  172. }
  173. .twoItem {
  174. display: flex;
  175. background-color: #FFFFFF;
  176. padding: 30rpx 0;
  177. border-top: #eeeeee 2rpx solid;
  178. }
  179. .title {
  180. font-size: 28rpx;
  181. font-weight: bold;
  182. color: #3c3c3c;
  183. }
  184. .title2 {
  185. font-size: 24rpx;
  186. font-weight: bold;
  187. color: #999999;
  188. //超过固定行数 隐藏
  189. display: -webkit-box;
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. word-wrap: break-word;
  193. white-space: normal !important;
  194. -webkit-line-clamp: 3;
  195. -webkit-box-orient: vertical;
  196. margin: 14rpx 0;
  197. }
  198. .img2 {
  199. width: 240rpx;
  200. height: 160rpx;
  201. border-radius: 10rpx;
  202. }
  203. .rightItem {
  204. margin-left: 30rpx;
  205. width: calc(100vw - 300rpx);
  206. }
  207. .noMore {
  208. text-align: center;
  209. line-height: 50rpx;
  210. color: #999999;
  211. font-size: 28rpx;
  212. }
  213. </style>