index.vue 7.7 KB

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