index.vue 8.3 KB

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