index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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"
  10. ><text>{{ item.name }}</text></view
  11. >
  12. <view class="stock_price">
  13. <view class="product_price">
  14. <text>{{ item.score }} 积分</text>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="search_fixed">
  21. <view class="search_box">
  22. <input class="search_input" type="text" v-model="requestParam.name" @input="searchChange" placeholder="请输入产品名称搜索" />
  23. <button class="search_btn" @click.stop="searchOpen()" data-eventsync="true">搜索</button>
  24. </view>
  25. </view>
  26. <view class="to_bottom" v-if="isLast"> -----到底了-----</view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. // 产品列表
  34. productList: [],
  35. // 请求参数
  36. requestParam: {
  37. name: "",
  38. page: 1,
  39. },
  40. // 是否最后一页
  41. isLast: false,
  42. // 是否请求中
  43. isReqing: false,
  44. };
  45. },
  46. onLoad() {
  47. // #ifdef MP-WEIXIN
  48. //分享按钮
  49. uni.showShareMenu({
  50. withShareTicket: true,
  51. menus: ["shareAppMessage", "shareTimeline"],
  52. });
  53. // #endif
  54. },
  55. onShareAppMessage(obj) {
  56. // 获取分享信息
  57. let shareList = getApp().globalData.shareList;
  58. // 获取分享信息
  59. let shareObj = {
  60. title: "999智控终端平台\n药优惠 得积分 兑豪礼",
  61. path: "/pages/score/index",
  62. imageUrl: "",
  63. };
  64. // 循环列表
  65. for (let i in shareList) {
  66. if (shareList[i].pages == "pages/score/index") {
  67. shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
  68. shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
  69. shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
  70. }
  71. }
  72. // 返回分享信息
  73. return shareObj;
  74. },
  75. onShow() {
  76. // 如果登录才请求
  77. if( !this.$checkAccess.checkLogin() ) return ;
  78. // 没有数据的话,或者请求中,不允许刷新
  79. if (this.isReqing) return;
  80. // 请求参数
  81. this.requestParam.name = "";
  82. // 请求参数
  83. this.requestParam.page = 1;
  84. // 是否是最后一页
  85. this.isLast = false;
  86. // 设置请求中
  87. this.isReqing = true;
  88. // 请求
  89. this.$http.request("api/score_product/get_list", this.requestParam).then((re) => {
  90. // 设置非请求中
  91. this.isReqing = false;
  92. // 成功结果
  93. if (re.code == "success") {
  94. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  95. this.productList = re.data.data;
  96. }
  97. });
  98. },
  99. onPullDownRefresh() {
  100. // 如果登录才请求
  101. if( !this.$checkAccess.checkLogin() ) return ;
  102. // 如果请求中,不允许请求,
  103. if (this.isReqing) return uni.stopPullDownRefresh();
  104. // 初始化页码为1
  105. this.requestParam.page = 1;
  106. // 是否是最后一页
  107. this.isLast = false;
  108. // 设置请求中
  109. this.isReqing = true;
  110. // 请求列表
  111. this.$http.request("api/score_product/get_list", this.requestParam).then((re) => {
  112. // 设置非请求中
  113. this.isReqing = false;
  114. // 成功结果
  115. if (re.code == "success") {
  116. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  117. this.productList = re.data.data;
  118. }
  119. });
  120. uni.stopPullDownRefresh();
  121. },
  122. onReachBottom() {
  123. // 如果登录才请求
  124. if( !this.$checkAccess.checkLogin() ) return ;
  125. // 如果页码是0,避免第一页重复
  126. if (this.requestParam.page < 1) return;
  127. // 最后一页不再请求
  128. if (this.isLast) return;
  129. // 请求中,不再请求
  130. if (this.isReqing) return;
  131. // 增加一页
  132. this.requestParam.page = this.requestParam.page + 1;
  133. // 设置请求中
  134. this.isReqing = true;
  135. // 请求列表
  136. this.$http.request("api/score_product/get_list", this.requestParam).then((re) => {
  137. // 设置非请求中
  138. this.isReqing = false;
  139. // 成功结果
  140. if (re.code == "success") {
  141. // 最后一页
  142. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  143. // 追加数据
  144. this.productList.push(...re.data.data);
  145. }
  146. });
  147. },
  148. methods: {
  149. searchChange(e) {
  150. // 如果没有搜索词
  151. if (!this.requestParam.name) {
  152. this.searchOpen();
  153. }
  154. },
  155. searchOpen() {
  156. // 请求中,不再请求
  157. if (this.isReqing) return;
  158. // 是否是最后一页
  159. this.isLast = false;
  160. // 初始化页码为1
  161. this.requestParam.page = 1;
  162. // 设置请求中
  163. this.isReqing = true;
  164. // 请求列表
  165. this.$http.request("api/score_product/get_list", this.requestParam).then((re) => {
  166. // 设置非请求中
  167. this.isReqing = false;
  168. // 成功结果
  169. if (re.code == "success") {
  170. this.productList = re.data.data;
  171. if (re.data.data.length && re.data.last_page >= this.requestParam.page) this.isLast = true;
  172. }
  173. });
  174. },
  175. toDetail(item) {
  176. uni.navigateTo({
  177. url: "/pages/score/product?id=" + item.id,
  178. });
  179. },
  180. },
  181. };
  182. </script>
  183. <style lang="less">
  184. .search_fixed {
  185. top: var(--window-top);
  186. left: 0rpx;
  187. width: 750rpx;
  188. display: block;
  189. position: fixed;
  190. margin: 0rpx auto;
  191. padding: 20rpx 0rpx;
  192. background-color: #ffffff;
  193. .search_box {
  194. width: 750rpx;
  195. height: 60rpx;
  196. display: block;
  197. position: relative;
  198. .search_input {
  199. z-index: 0;
  200. width: 590rpx;
  201. height: 56rpx;
  202. display: block;
  203. font-size: 24rpx;
  204. position: relative;
  205. border-top-left-radius: 40rpx;
  206. border-bottom-left-radius: 40rpx;
  207. padding-left: 20rpx;
  208. margin-left: 35rpx;
  209. border: 2rpx solid #dddddd;
  210. }
  211. .search_btn {
  212. top: 0rpx;
  213. z-index: 9;
  214. left: 610rpx;
  215. color: #ffffff;
  216. position: absolute;
  217. display: block;
  218. width: 120rpx;
  219. height: 60rpx;
  220. font-size: 24rpx;
  221. margin: 0rpx 0rpx;
  222. padding: 0rpx 0rpx;
  223. line-height: 60rpx;
  224. border-radius: 40rpx;
  225. background-color: #e03519;
  226. }
  227. }
  228. }
  229. .product_box {
  230. display: block;
  231. overflow: hidden;
  232. margin: 0rpx auto;
  233. margin-top: 120rpx;
  234. padding: 0rpx 35rpx;
  235. .product_list {
  236. display: block;
  237. overflow: hidden;
  238. margin: 0rpx auto;
  239. .product_item {
  240. float: left;
  241. width: 320rpx;
  242. height: 490rpx;
  243. display: block;
  244. overflow: hidden;
  245. margin: 20rpx 0rpx;
  246. margin-right: 40rpx;
  247. background-color: #ffffff;
  248. border-radius: 20rpx;
  249. .product_image {
  250. width: 320rpx;
  251. height: 320rpx;
  252. }
  253. .product_name {
  254. height: 80rpx;
  255. font-size: 30rpx;
  256. line-height: 40rpx;
  257. overflow: hidden;
  258. margin: 10rpx 0rpx;
  259. padding: 0rpx 10rpx;
  260. text-overflow: ellipsis;
  261. }
  262. .product_spec {
  263. height: 30rpx;
  264. color: #999999;
  265. font-size: 24rpx;
  266. line-height: 30rpx;
  267. padding: 0rpx 10rpx;
  268. overflow: hidden;
  269. white-space: nowrap;
  270. text-overflow: ellipsis;
  271. }
  272. .stock_price {
  273. color: #dddddd;
  274. font-size: 20rpx;
  275. overflow: hidden;
  276. line-height: 30rpx;
  277. padding: 0rpx 10rpx;
  278. .product_price {
  279. float: left;
  280. color: red;
  281. font-size: 30rpx;
  282. line-height: 60rpx;
  283. .product_market {
  284. font-size: 24rpx;
  285. color: #999999;
  286. line-height: 30rpx;
  287. vertical-align: top;
  288. text-decoration: line-through;
  289. }
  290. }
  291. .product_stock {
  292. float: right;
  293. font-size: 20rpx;
  294. line-height: 60rpx;
  295. }
  296. }
  297. }
  298. .product_item:nth-child(even) {
  299. margin-right: 0rpx;
  300. }
  301. }
  302. }
  303. </style>