product.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view>
  3. <view class="product_box">
  4. <view class="to_bottom" v-if="!productList.length"> -----还没有产品啦-----</view>
  5. <!-- 产品列表 -->
  6. <view class="product_list" >
  7. <!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
  8. <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item,index) in productList" :key="index" >
  9. <image class="product_image" :src="item.thumb" mode=""></image>
  10. <view class="product_name"><text>{{item.name}}</text></view>
  11. <view class="product_spec"><text>{{item.spec}}</text></view>
  12. <view class="stock_price">
  13. <view class="product_price" >
  14. <text >¥{{item.price}} </text>
  15. </view>
  16. <view class="product_stock">剩{{item.stock}}个</view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. // 产品列表
  28. productList:[],
  29. // 请求参数
  30. requestParam:{
  31. coupon_id:0,
  32. name:"",
  33. page:1,
  34. },
  35. // 是否最后一页
  36. isLast:false,
  37. // 是否请求中
  38. isReqing:false,
  39. }
  40. },
  41. onLoad(param) {
  42. this.requestParam.coupon_id = param.coupon_id;
  43. },
  44. onShow() {
  45. // 没有数据的话,或者请求中,不允许刷新
  46. if( this.isReqing ) return ;
  47. // 请求参数
  48. this.requestParam.name = "";
  49. // 请求参数
  50. this.requestParam.page = 1;
  51. // 是否是最后一页
  52. this.isLast = false;
  53. // 设置请求中
  54. this.isReqing = true;
  55. // 请求
  56. this.$http.request('api/coupon/get_product',this.requestParam).then((re)=>{
  57. // 设置非请求中
  58. this.isReqing = false;
  59. // 成功结果
  60. if( re.code == 'success' ){
  61. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  62. this.productList = re.data.data;
  63. }
  64. });
  65. },
  66. onPullDownRefresh() {
  67. // 如果请求中,不允许请求,
  68. if( this.isReqing ) return false;
  69. // 初始化页码为1
  70. this.requestParam.page = 1;
  71. // 是否是最后一页
  72. this.isLast = false;
  73. // 设置请求中
  74. this.isReqing = true;
  75. // 请求列表
  76. this.$http.request('/api/coupon/get_product',this.requestParam).then((re)=>{
  77. // 设置非请求中
  78. this.isReqing = false;
  79. // 成功结果
  80. if( re.code == 'success' ){
  81. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  82. this.productList = re.data.data;
  83. }
  84. });
  85. uni.stopPullDownRefresh();
  86. },
  87. onReachBottom() {
  88. // 如果页码是0,避免第一页重复
  89. if( this.requestParam.page < 1 ) return;
  90. // 最后一页不再请求
  91. if( this.isLast ) return;
  92. // 请求中,不再请求
  93. if( this.isReqing ) return;
  94. // 增加一页
  95. this.requestParam.page = this.requestParam.page+1;
  96. // 设置请求中
  97. this.isReqing = true;
  98. // 请求列表
  99. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  100. // 设置非请求中
  101. this.isReqing = false;
  102. // 成功结果
  103. if( re.code == 'success' ){
  104. // 最后一页
  105. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  106. // 追加数据
  107. this.productList.push(...re.data.data);
  108. }
  109. });
  110. },
  111. methods: {
  112. toDetail(item){
  113. uni.navigateTo({
  114. url:"/pages/product/index?product_id="+item.id,
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="less">
  121. .product_box{
  122. display: block;
  123. overflow: hidden;
  124. margin: 20rpx auto;
  125. padding: 0rpx 35rpx;
  126. .product_list{
  127. display: block;
  128. overflow: hidden;
  129. margin: 0rpx auto;
  130. .product_item{
  131. float: left;
  132. width: 320rpx;
  133. height: 520rpx;
  134. display: block;
  135. overflow: hidden;
  136. margin: 20rpx 0rpx;
  137. margin-right: 40rpx;
  138. background-color: #FFFFFF;
  139. border-radius: 20rpx;
  140. .product_image{
  141. width: 320rpx;
  142. height: 320rpx;
  143. }
  144. .product_name{
  145. height: 80rpx;
  146. font-size: 30rpx;
  147. line-height: 40rpx;
  148. overflow: hidden;
  149. margin: 10rpx 0rpx;
  150. padding: 0rpx 10rpx;
  151. text-overflow: ellipsis;
  152. }
  153. .product_spec{
  154. height: 30rpx;
  155. color: #999999;
  156. font-size: 24rpx;
  157. line-height: 30rpx;
  158. padding: 0rpx 10rpx;
  159. overflow: hidden;
  160. white-space: nowrap;
  161. text-overflow: ellipsis;
  162. }
  163. .stock_price{
  164. color: #dddddd;
  165. font-size: 20rpx;
  166. overflow: hidden;
  167. line-height: 30rpx;
  168. padding: 0rpx 10rpx;
  169. .product_price{
  170. float: left;
  171. color: red;
  172. font-size: 30rpx;
  173. line-height: 60rpx;
  174. .product_market{
  175. font-size: 24rpx;
  176. color: #999999;
  177. line-height: 30rpx;
  178. vertical-align: top;
  179. text-decoration: line-through;
  180. }
  181. }
  182. .product_stock{
  183. float: right;
  184. font-size: 20rpx;
  185. line-height: 60rpx;
  186. }
  187. }
  188. }
  189. .product_item:nth-child(even){
  190. margin-right: 0rpx;
  191. }
  192. }
  193. }
  194. </style>