index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. // #ifdef MP-WEIXIN
  46. //分享按钮
  47. uni.showShareMenu({
  48. withShareTicket: true,
  49. menus: ['shareAppMessage', 'shareTimeline']
  50. })
  51. // #endif
  52. },
  53. onShow() {
  54. // 没有数据的话,或者请求中,不允许刷新
  55. if( this.isReqing ) return ;
  56. // 请求参数
  57. this.requestParam.name = "";
  58. // 请求参数
  59. this.requestParam.page = 1;
  60. // 是否是最后一页
  61. this.isLast = false;
  62. // 设置请求中
  63. this.isReqing = true;
  64. // 请求
  65. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  66. // 设置非请求中
  67. this.isReqing = false;
  68. // 成功结果
  69. if( re.code == 'success' ){
  70. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  71. this.productList = re.data.data;
  72. }
  73. });
  74. },
  75. onPullDownRefresh() {
  76. // 如果请求中,不允许请求,
  77. if( this.isReqing ) return uni.stopPullDownRefresh();
  78. // 初始化页码为1
  79. this.requestParam.page = 1;
  80. // 是否是最后一页
  81. this.isLast = false;
  82. // 设置请求中
  83. this.isReqing = true;
  84. // 请求列表
  85. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  86. // 设置非请求中
  87. this.isReqing = false;
  88. // 成功结果
  89. if( re.code == 'success' ){
  90. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  91. this.productList = re.data.data;
  92. }
  93. });
  94. uni.stopPullDownRefresh();
  95. },
  96. onReachBottom() {
  97. // 如果页码是0,避免第一页重复
  98. if( this.requestParam.page < 1 ) return;
  99. // 最后一页不再请求
  100. if( this.isLast ) return;
  101. // 请求中,不再请求
  102. if( this.isReqing ) return;
  103. // 增加一页
  104. this.requestParam.page = this.requestParam.page+1;
  105. // 设置请求中
  106. this.isReqing = true;
  107. // 请求列表
  108. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  109. // 设置非请求中
  110. this.isReqing = false;
  111. // 成功结果
  112. if( re.code == 'success' ){
  113. // 最后一页
  114. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  115. // 追加数据
  116. this.productList.push(...re.data.data);
  117. }
  118. });
  119. },
  120. methods: {
  121. searchChange(e){
  122. // 如果没有搜索词
  123. if( !this.requestParam.name ){
  124. this.searchOpen();
  125. }
  126. },
  127. searchOpen(){
  128. // 请求中,不再请求
  129. if( this.isReqing ) return;
  130. // 是否是最后一页
  131. this.isLast = false;
  132. // 初始化页码为1
  133. this.requestParam.page = 1;
  134. // 设置请求中
  135. this.isReqing = true;
  136. // 请求列表
  137. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  138. // 设置非请求中
  139. this.isReqing = false;
  140. // 成功结果
  141. if( re.code == 'success' ){
  142. this.productList = re.data.data;
  143. if( re.data.data.length && re.data.last_page >= this.requestParam.page ) this.isLast = true;
  144. }
  145. });
  146. },
  147. toDetail(item){
  148. uni.navigateTo({
  149. url:"/pages/score/product?id="+item.id,
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="less">
  156. .search_fixed{
  157. top: var(--window-top);
  158. left: 0rpx;
  159. width: 750rpx;
  160. display: block;
  161. position: fixed;
  162. margin: 0rpx auto;
  163. padding: 20rpx 0rpx;
  164. background-color: #FFFFFF;
  165. .search_box{
  166. width: 750rpx;
  167. height: 60rpx;
  168. display: block;
  169. position: relative;
  170. .search_input{
  171. z-index: 0;
  172. width: 590rpx;
  173. height: 56rpx;
  174. display: block;
  175. font-size: 24rpx;
  176. position: relative;
  177. border-top-left-radius: 40rpx;
  178. border-bottom-left-radius: 40rpx;
  179. padding-left: 20rpx;
  180. margin-left: 35rpx;
  181. border: 2rpx solid #dddddd;
  182. }
  183. .search_btn{
  184. top: 0rpx;
  185. z-index: 9;
  186. left: 610rpx;
  187. color: #FFFFFF;
  188. position: absolute;
  189. display: block;
  190. width: 120rpx;
  191. height: 60rpx;
  192. font-size: 24rpx;
  193. margin: 0rpx 0rpx;
  194. padding: 0rpx 0rpx;
  195. line-height: 60rpx;
  196. border-radius: 40rpx;
  197. background-color: #E03519;
  198. }
  199. }
  200. }
  201. .product_box{
  202. display: block;
  203. overflow: hidden;
  204. margin: 0rpx auto;
  205. margin-top: 120rpx;
  206. padding: 0rpx 35rpx;
  207. .product_list{
  208. display: block;
  209. overflow: hidden;
  210. margin: 0rpx auto;
  211. .product_item{
  212. float: left;
  213. width: 320rpx;
  214. height: 490rpx;
  215. display: block;
  216. overflow: hidden;
  217. margin: 20rpx 0rpx;
  218. margin-right: 20rpx;
  219. background-color: #FFFFFF;
  220. border-radius: 20rpx;
  221. .product_image{
  222. width: 320rpx;
  223. height: 320rpx;
  224. }
  225. .product_name{
  226. height: 80rpx;
  227. font-size: 30rpx;
  228. line-height: 40rpx;
  229. overflow: hidden;
  230. margin: 10rpx 0rpx;
  231. padding: 0rpx 10rpx;
  232. text-overflow: ellipsis;
  233. }
  234. .product_spec{
  235. height: 30rpx;
  236. color: #999999;
  237. font-size: 24rpx;
  238. line-height: 30rpx;
  239. padding: 0rpx 10rpx;
  240. overflow: hidden;
  241. white-space: nowrap;
  242. text-overflow: ellipsis;
  243. }
  244. .stock_price{
  245. color: #dddddd;
  246. font-size: 20rpx;
  247. overflow: hidden;
  248. line-height: 30rpx;
  249. padding: 0rpx 10rpx;
  250. .product_price{
  251. float: left;
  252. color: red;
  253. font-size: 30rpx;
  254. line-height: 60rpx;
  255. .product_market{
  256. font-size: 24rpx;
  257. color: #999999;
  258. line-height: 30rpx;
  259. vertical-align: top;
  260. text-decoration: line-through;
  261. }
  262. }
  263. .product_stock{
  264. float: right;
  265. font-size: 20rpx;
  266. line-height: 60rpx;
  267. }
  268. }
  269. }
  270. .product_item:nth-child(even){
  271. margin-right: 0rpx;
  272. }
  273. }
  274. }
  275. </style>