index.vue 6.9 KB

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