searchpage.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. :title="title"
  5. :placeholder="true"
  6. :autoBack="false"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="search-wrap">
  12. <u-search
  13. placeholder="请输入关键词"
  14. :clearabled="true"
  15. :showAction="false"
  16. height="80rpx"
  17. @search="search"
  18. @custom="search"
  19. @clear="reloadList"
  20. bgColor="#fff"
  21. borderColor="#ee0808"
  22. v-model="params.goodsName">
  23. </u-search>
  24. </view>
  25. <!-- <view class="search-history page-wrap" v-if="searchHistory.length>0">
  26. <view class="search-title u-flex u-row-between">
  27. <text>最近搜索</text>
  28. <u-icon @click="clearStorage" name="trash" color="#666" size="35"></u-icon>
  29. </view>
  30. <view class="history-wrap">
  31. <text class="history" v-for="(item,index) in searchHistory" :key="index">
  32. {{item.name}}
  33. </text>
  34. </view>
  35. </view> -->
  36. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  37. <view class="page-wrap" >
  38. <view class="" v-for="item in dataList" :key="item.id" @click="bookticket(item)">
  39. <view class="programme">
  40. <image class="img" :src="item.showImg" ></image>
  41. <view class="text u-flex u-row-between">
  42. <view class="left">
  43. <view class="name">{{item.name}}</view>
  44. </view>
  45. <view class="btn" @click="bookticket(item)">立即报名</view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </mescroll-body>
  51. <u-toast ref="uToast"></u-toast>
  52. </view>
  53. </template>
  54. <script>
  55. // 引入mescroll-mixins.js
  56. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  57. export default {
  58. mixins: [MescrollMixin], // 使用mixin
  59. components: {
  60. },
  61. data() {
  62. return {
  63. staticUrl:this.$commonConfig.staticUrl,
  64. downOption: {},
  65. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  66. upOption: {
  67. page: {
  68. size: 10 // 每页数据的数量,默认10
  69. },
  70. noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  71. empty: {
  72. tip: '暂无相关数据'
  73. }
  74. },
  75. title:'搜索',
  76. params:{
  77. name:'',
  78. // isExplode:0,//是否爆款 0不是,1是
  79. },
  80. // 列表数据
  81. dataList: [],
  82. searchHistory:[],
  83. }
  84. },
  85. onLoad(page) {
  86. let that = this;
  87. this.params.name = page.keyword;
  88. uni.getStorage({
  89. key:'searchgoodshistory',
  90. success: function(storagedata) {
  91. that.searchHistory = storagedata.data;
  92. console.log('storagedata',storagedata.data);
  93. }
  94. })
  95. },
  96. onShow() {
  97. },
  98. methods: {
  99. leftClick(e){
  100. let pages = getCurrentPages();
  101. if(pages.length==1){
  102. uni.$u.route('/pages/index/index')
  103. }else{
  104. uni.navigateBack()
  105. };
  106. },
  107. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  108. downCallback(){
  109. this.mescroll.resetUpScroll();
  110. },
  111. /*上拉加载的回调*/
  112. upCallback(page) {
  113. let that = this;
  114. // 此处可以继续请求其他接口
  115. // if(page.num == 1){
  116. // // 请求其他接口...
  117. // }
  118. let pageNum = page.num; // 页码, 默认从1开始
  119. let pageSize = page.size; // 页长, 默认每页10条
  120. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  121. console.log('this.params',this.params);
  122. this.$u.api.teamIndex(this.params).then(data => {
  123. console.log('data',JSON.parse(JSON.stringify(data)));
  124. // 接口返回的当前页数据列表 (数组)
  125. let curPageData = data.data.performList||[];
  126. console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  127. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  128. let curPageLen = curPageData.length;
  129. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  130. // let totalPage = data.data.data.totalPage;
  131. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  132. let totalSize = data.data.total;
  133. // 接口返回的是否有下一页 (true/false)
  134. // let hasNext = data.xxx;
  135. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  136. //设置列表数据
  137. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  138. this.dataList = this.dataList.concat(curPageData); //追加新数据
  139. // 请求成功,隐藏加载状态
  140. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  141. // this.mescroll.endByPage(curPageLen, totalPage);
  142. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  143. this.mescroll.endBySize(curPageLen, totalSize);
  144. }).catch(err => {
  145. this.mescroll.endErr()
  146. console.log(err)
  147. });
  148. // 存储历史数据
  149. let index = this.searchHistory.findIndex(item => item.name === that.params.goodsName);
  150. // console.log('index',index);
  151. const name = that.params.goodsName;
  152. if (!name || name.length < 1) {
  153. return;
  154. }
  155. if (index !== -1) {
  156. // 已经存在,不用重复添加了
  157. return;
  158. }
  159. this.searchHistory.push({ name: that.params.goodsName });
  160. uni.setStorage({
  161. key: 'searchgoodshistory',
  162. data: that.searchHistory,
  163. success: function() {
  164. // console.log('数据存储成功')
  165. },
  166. fail: function() {
  167. // console.log('数据存储失败')
  168. }
  169. });
  170. },
  171. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  172. reloadList() {
  173. this.mescroll.resetUpScroll();
  174. },
  175. search(e){
  176. this.mescroll.resetUpScroll();
  177. // this.reloadList();
  178. console.log('search',e)
  179. },
  180. clearStorage(){
  181. let that = this;
  182. uni.clearStorage({
  183. key:'searchgoodshistory',
  184. success:function(){
  185. that.searchHistory = []
  186. }
  187. })
  188. },
  189. bookticket(item){
  190. // console.log('bookticket',item);
  191. uni.$u.route('pages/ticketlist',{id:item.id})
  192. },
  193. }
  194. }
  195. </script>
  196. <style>
  197. page{
  198. background-color: #f4f4f4;
  199. }
  200. </style>
  201. <style lang="scss" scoped>
  202. .search-history{
  203. color: #333333;
  204. margin-bottom: 30rpx;
  205. .search-title{
  206. font-size: 32rpx;
  207. font-weight: 600;
  208. line-height: 45rpx;
  209. margin-bottom: 20rpx;
  210. }
  211. .history{
  212. display: inline-block;
  213. height: 48rpx;
  214. line-height: 48rpx;
  215. background: #F5F5F5;
  216. border-radius: 24rpx;
  217. padding: 0 24rpx;
  218. min-width: 100rpx;
  219. margin-left: 20rpx;
  220. margin-bottom: 20rpx;
  221. text-align: center;
  222. }
  223. }
  224. .programme{
  225. margin-bottom: 24rpx;
  226. }
  227. </style>