search.vue 5.4 KB

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