index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <view class="product_box">
  4. <view class="to_bottom" v-if="!productList.length"> -----还没有积分产品-----</view>
  5. <view class="product_list" >
  6. <!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
  7. <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item,index) in productList" :key="index" >
  8. <image class="product_image" :src="item.thumb" mode=""></image>
  9. <view class="product_name"><text>{{item.name}}</text></view>
  10. <view class="stock_price">
  11. <view class="product_price">
  12. <text>{{item.score}} 积分</text>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="search_fixed" >
  19. <view class="search_box">
  20. <input class="search_input" type="text" v-model="requestParam.name" @input="searchChange" placeholder="请输入产品名称搜索" />
  21. <button class="search_btn" @click.stop="searchOpen()" data-eventsync="true"> 搜索</button>
  22. </view>
  23. </view>
  24. <view class="to_bottom" v-if="isLast"> -----到底了-----</view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. // 产品列表
  32. productList:[],
  33. // 请求参数
  34. requestParam:{
  35. name:"",
  36. page:1,
  37. },
  38. // 是否最后一页
  39. isLast:false,
  40. // 是否请求中
  41. isReqing:false,
  42. }
  43. },
  44. onLoad() {
  45. },
  46. onShow() {
  47. // 没有数据的话,或者请求中,不允许刷新
  48. if( this.isReqing ) return ;
  49. // 请求参数
  50. this.requestParam.name = "";
  51. // 请求参数
  52. this.requestParam.page = 1;
  53. // 是否是最后一页
  54. this.isLast = false;
  55. // 设置请求中
  56. this.isReqing = true;
  57. // 请求
  58. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  59. // 设置非请求中
  60. this.isReqing = false;
  61. // 成功结果
  62. if( re.code == 'success' ){
  63. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  64. this.productList = re.data.data;
  65. }
  66. });
  67. },
  68. onPullDownRefresh() {
  69. // 如果请求中,不允许请求,
  70. if( this.isReqing ) return uni.stopPullDownRefresh();
  71. // 初始化页码为1
  72. this.requestParam.page = 1;
  73. // 是否是最后一页
  74. this.isLast = false;
  75. // 设置请求中
  76. this.isReqing = true;
  77. // 请求列表
  78. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  79. // 设置非请求中
  80. this.isReqing = false;
  81. // 成功结果
  82. if( re.code == 'success' ){
  83. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  84. this.productList = re.data.data;
  85. }
  86. });
  87. uni.stopPullDownRefresh();
  88. },
  89. onReachBottom() {
  90. // 如果页码是0,避免第一页重复
  91. if( this.requestParam.page < 1 ) return;
  92. // 最后一页不再请求
  93. if( this.isLast ) return;
  94. // 请求中,不再请求
  95. if( this.isReqing ) return;
  96. // 增加一页
  97. this.requestParam.page = this.requestParam.page+1;
  98. // 设置请求中
  99. this.isReqing = true;
  100. // 请求列表
  101. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  102. // 设置非请求中
  103. this.isReqing = false;
  104. // 成功结果
  105. if( re.code == 'success' ){
  106. // 最后一页
  107. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  108. // 追加数据
  109. this.productList.push(...re.data.data);
  110. }
  111. });
  112. },
  113. methods: {
  114. searchChange(e){
  115. // 如果没有搜索词
  116. if( !this.requestParam.name ){
  117. this.searchOpen();
  118. }
  119. },
  120. searchOpen(){
  121. // 请求中,不再请求
  122. if( this.isReqing ) return;
  123. // 是否是最后一页
  124. this.isLast = false;
  125. // 初始化页码为1
  126. this.requestParam.page = 1;
  127. // 设置请求中
  128. this.isReqing = true;
  129. // 请求列表
  130. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  131. // 设置非请求中
  132. this.isReqing = false;
  133. // 成功结果
  134. if( re.code == 'success' ){
  135. this.productList = re.data.data;
  136. if( re.data.data.length && re.data.last_page >= this.requestParam.page ) this.isLast = true;
  137. }
  138. });
  139. },
  140. toDetail(item){
  141. uni.navigateTo({
  142. url:"/pages/score/product?id="+item.id,
  143. })
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="less">
  149. .search_fixed{
  150. top: var(--window-top);
  151. left: 0rpx;
  152. width: 750rpx;
  153. display: block;
  154. position: fixed;
  155. margin: 0rpx auto;
  156. padding: 20rpx 0rpx;
  157. background-color: #FFFFFF;
  158. .search_box{
  159. width: 750rpx;
  160. height: 60rpx;
  161. display: block;
  162. position: relative;
  163. .search_input{
  164. z-index: 0;
  165. width: 590rpx;
  166. height: 56rpx;
  167. display: block;
  168. font-size: 24rpx;
  169. position: relative;
  170. border-top-left-radius: 40rpx;
  171. border-bottom-left-radius: 40rpx;
  172. padding-left: 20rpx;
  173. margin-left: 35rpx;
  174. border: 2rpx solid #dddddd;
  175. }
  176. .search_btn{
  177. top: 0rpx;
  178. z-index: 9;
  179. left: 610rpx;
  180. color: #FFFFFF;
  181. position: absolute;
  182. display: block;
  183. width: 120rpx;
  184. height: 60rpx;
  185. font-size: 24rpx;
  186. margin: 0rpx 0rpx;
  187. padding: 0rpx 0rpx;
  188. line-height: 60rpx;
  189. border-radius: 40rpx;
  190. background-color: #E03519;
  191. }
  192. }
  193. }
  194. .product_box{
  195. display: block;
  196. overflow: hidden;
  197. margin: 0rpx auto;
  198. margin-top: 120rpx;
  199. padding: 0rpx 35rpx;
  200. .product_list{
  201. display: block;
  202. overflow: hidden;
  203. margin: 0rpx auto;
  204. .product_item{
  205. float: left;
  206. width: 320rpx;
  207. display: block;
  208. overflow: hidden;
  209. margin: 20rpx 0rpx;
  210. margin-right: 20rpx;
  211. background-color: #FFFFFF;
  212. border-radius: 20rpx;
  213. .product_image{
  214. width: 320rpx;
  215. height: 320rpx;
  216. }
  217. .product_name{
  218. height: 80rpx;
  219. font-size: 26rpx;
  220. line-height: 40rpx;
  221. overflow: hidden;
  222. padding: 10rpx 10rpx;
  223. }
  224. .product_spec{
  225. color: #999999;
  226. font-size: 22rpx;
  227. line-height: 30rpx;
  228. padding: 0rpx 10rpx;
  229. }
  230. .stock_price{
  231. color: #dddddd;
  232. font-size: 20rpx;
  233. overflow: hidden;
  234. line-height: 30rpx;
  235. padding: 0rpx 10rpx;
  236. .product_price{
  237. float: left;
  238. color: red;
  239. font-size: 30rpx;
  240. line-height: 60rpx;
  241. .product_market{
  242. font-size: 24rpx;
  243. color: #999999;
  244. line-height: 30rpx;
  245. vertical-align: top;
  246. text-decoration: line-through;
  247. }
  248. }
  249. .product_stock{
  250. float: right;
  251. font-size: 20rpx;
  252. line-height: 60rpx;
  253. }
  254. }
  255. }
  256. .product_item:nth-child(even){
  257. margin-right: 0rpx;
  258. }
  259. }
  260. }
  261. </style>