search.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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" v-if="itemArr.length!=0">为你找到“{{searchValue}}”相关结果共{{TotalSize}}条</view>
  20. <!-- </view> -->
  21. <!-- item -->
  22. <view class="itemBg">
  23. <view v-for="(item,index) in itemArr" :key="index" :class="{line:index>0}" 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 && isFirst == false" style="padding-top: 30%;"></nodata>
  35. <view class="gotop" @click="gotoTop">
  36. <image src="../../static/pcimg/btn_top@2x.png" mode="" class="gotopImg"></image>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import searchBox from '@/components/searchBox/searchBox.vue'
  42. import nodata from '../../components/nodata/nodata.vue'
  43. export default {
  44. components: {
  45. searchBox,
  46. nodata
  47. },
  48. data() {
  49. return {
  50. searchValue: '',
  51. page: 1,
  52. itemArr: [],
  53. TotalSize: '',
  54. noMoreShow: false,
  55. isFirst:true,
  56. }
  57. },
  58. onLoad() {
  59. },
  60. methods: {
  61. gotoTop() {
  62. uni.pageScrollTo({
  63. scrollTop: 0,
  64. duration: 300
  65. });
  66. },
  67. goDetail(item) {
  68. uni.navigateTo({
  69. url: 'detail?id=' + item.ID
  70. })
  71. },
  72. back() {
  73. uni.navigateBack({
  74. })
  75. },
  76. search(val) {
  77. console.log(val);
  78. this.isFirst = false
  79. this.searchValue = val
  80. if (this.searchValue.length != 0) {
  81. this.page = 1
  82. this.getItemData()
  83. } else {
  84. this.itemArr = [];
  85. this.TotalSize = ''
  86. this.noMoreShow = false
  87. }
  88. },
  89. getItemData() {
  90. uni.showLoading({
  91. title: '加载中'
  92. })
  93. let url = 'trainingOpenApiV2/searchPageData',
  94. params = {
  95. page: this.page,
  96. limit: 10,
  97. title: this.searchValue,
  98. }
  99. this.$http(url, params, 'GET').then(res => {
  100. uni.hideLoading();
  101. var data = res.data
  102. // 处理 undefined和null转为空白字符串
  103. for (const key in data) {
  104. data[key] = this.$praseStrEmpty(data[key])
  105. }
  106. this.TotalSize = data.TotalSize
  107. if (this.page == 1) {
  108. this.itemArr = data.Items
  109. } else {
  110. this.itemArr = this.itemArr.concat(data.Items)
  111. }
  112. if (data.Items.length < 10) {
  113. this.noMoreShow = true
  114. } else {
  115. this.noMoreShow = false
  116. }
  117. if (this.itemArr.length == 0) {
  118. this.noMoreShow = false
  119. }
  120. })
  121. },
  122. }
  123. }
  124. </script>
  125. <style scoped>
  126. .content {
  127. min-height: 100vh;
  128. background-color: #FFFFFF;
  129. padding-top: 88rpx;
  130. padding-bottom: 20rpx;
  131. }
  132. .nav {
  133. position: fixed;
  134. left: 0;
  135. top: 0;
  136. width: 100vw;
  137. height: 88rpx;
  138. background-color: #FFFFFF;
  139. display: flex;
  140. justify-content: space-between;
  141. align-items: center;
  142. z-index: 999;
  143. border-bottom: #eeeeee 2rpx solid;
  144. }
  145. .navTitle {
  146. font-size: 36rpx;
  147. font-weight: bold;
  148. color: #3c3c3c;
  149. }
  150. .leftView {
  151. width: 30%;
  152. }
  153. .rightView {
  154. width: 30%;
  155. display: flex;
  156. justify-content: flex-end;
  157. padding-right: 24rpx;
  158. }
  159. .rightImg {
  160. width: 40rpx;
  161. height: 40rpx;
  162. }
  163. .searchBoxBg {
  164. position: fixed;
  165. left: 0;
  166. top: 88rpx;
  167. width: calc(100vw - 50rpx);
  168. background-color: #FFFFFF;
  169. padding: 0 24rpx;
  170. z-index: 999;
  171. }
  172. .top {
  173. padding: 130rpx 24rpx 0;
  174. text-align: left;
  175. font-size: 24rpx;
  176. color: #999999;
  177. background-color: #FFFFFF;
  178. }
  179. .itemBg {
  180. background-color: #FFFFFF;
  181. padding: 0 30rpx;
  182. }
  183. .twoItem {
  184. display: flex;
  185. background-color: #FFFFFF;
  186. padding: 30rpx 0;
  187. }
  188. .line{
  189. border-top: #eeeeee 2rpx solid;
  190. }
  191. .title {
  192. font-size: 28rpx;
  193. font-weight: bold;
  194. color: #3c3c3c;
  195. /* 隐藏文字显示 ...不换行 */
  196. overflow: hidden;
  197. text-overflow: ellipsis;
  198. white-space: nowrap;
  199. }
  200. .title2 {
  201. font-size: 24rpx;
  202. color: #999999;
  203. //超过固定行数 隐藏
  204. display: -webkit-box;
  205. overflow: hidden;
  206. text-overflow: ellipsis;
  207. word-wrap: break-word;
  208. white-space: normal !important;
  209. -webkit-line-clamp: 3;
  210. -webkit-box-orient: vertical;
  211. margin: 14rpx 0;
  212. }
  213. .img2 {
  214. width: 240rpx;
  215. height: 135rpx;
  216. border-radius: 10rpx;
  217. }
  218. .rightItem {
  219. margin-left: 30rpx;
  220. width: calc(100vw - 300rpx);
  221. }
  222. .noMore {
  223. text-align: center;
  224. line-height: 50rpx;
  225. color: #999999;
  226. font-size: 28rpx;
  227. }
  228. .gotopImg {
  229. width: 100rpx;
  230. height: 100rpx;
  231. }
  232. .gotop {
  233. position: fixed;
  234. right: 15rpx;
  235. bottom: 100rpx;
  236. cursor: pointer;
  237. }
  238. </style>