index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 class="product_box">
  26. <!-- <view class="to_bottom" v-if="!productList.length"> -----还没有积分产品-----</view> -->
  27. <view class="product_list" >
  28. <!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
  29. <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item,index) in productList" :key="index" >
  30. <image class="product_image" :src="item.thumb" mode=""></image>
  31. <view class="product_name"><text>{{item.name}}</text></view>
  32. <view class="stock_price">
  33. <view class="product_price">
  34. <text>{{item.score}} 积分</text>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="header_fixed" >
  41. <view class="user_title">
  42. <view class="user_prc">
  43. <image src="../../static/logo2.jpg" ></image>
  44. </view>
  45. <view class="title">
  46. <view class="">
  47. 王先生
  48. </view>
  49. <view class="">
  50. 5000积分
  51. </view>
  52. </view>
  53. </view>
  54. <view class="search">
  55. <view class="search_box">
  56. <view class="search_input">
  57. <input type="text" placeholder="一年级系统班" />
  58. </view>
  59. <view class="search_icon">
  60. <uni-icons type="search" size="20"></uni-icons>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="course_option">
  65. <view class="option_name">
  66. 综合
  67. </view>
  68. <view class="option_name">
  69. 我可兑换
  70. </view>
  71. <view class="option_name">
  72. 销量
  73. </view>
  74. <view class="option_name">
  75. 积分
  76. </view>
  77. </view>
  78. </view>
  79. <view class="to_bottom" > -----到底了-----</view>
  80. </view>
  81. </template>
  82. <script>
  83. export default {
  84. data() {
  85. return {
  86. // 产品列表
  87. productList:[],
  88. // 请求参数
  89. requestParam:{
  90. name:"",
  91. page:1,
  92. },
  93. // 是否最后一页
  94. isLast:false,
  95. // 是否请求中
  96. isReqing:false,
  97. }
  98. },
  99. onLoad() {
  100. },
  101. onShow() {
  102. // 没有数据的话,或者请求中,不允许刷新
  103. if( this.isReqing ) return ;
  104. // 请求参数
  105. this.requestParam.name = "";
  106. // 请求参数
  107. this.requestParam.page = 1;
  108. // 是否是最后一页
  109. this.isLast = false;
  110. // 设置请求中
  111. this.isReqing = true;
  112. // 请求
  113. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  114. // 设置非请求中
  115. this.isReqing = false;
  116. // 成功结果
  117. if( re.code == 'success' ){
  118. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  119. this.productList = re.data.data;
  120. }
  121. });
  122. },
  123. onPullDownRefresh() {
  124. // 如果请求中,不允许请求,
  125. if( this.isReqing ) return uni.stopPullDownRefresh();
  126. // 初始化页码为1
  127. this.requestParam.page = 1;
  128. // 是否是最后一页
  129. this.isLast = false;
  130. // 设置请求中
  131. this.isReqing = true;
  132. // 请求列表
  133. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  134. // 设置非请求中
  135. this.isReqing = false;
  136. // 成功结果
  137. if( re.code == 'success' ){
  138. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  139. this.productList = re.data.data;
  140. }
  141. });
  142. uni.stopPullDownRefresh();
  143. },
  144. onReachBottom() {
  145. // 如果页码是0,避免第一页重复
  146. if( this.requestParam.page < 1 ) return;
  147. // 最后一页不再请求
  148. if( this.isLast ) return;
  149. // 请求中,不再请求
  150. if( this.isReqing ) return;
  151. // 增加一页
  152. this.requestParam.page = this.requestParam.page+1;
  153. // 设置请求中
  154. this.isReqing = true;
  155. // 请求列表
  156. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  157. // 设置非请求中
  158. this.isReqing = false;
  159. // 成功结果
  160. if( re.code == 'success' ){
  161. // 最后一页
  162. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  163. // 追加数据
  164. this.productList.push(...re.data.data);
  165. }
  166. });
  167. },
  168. methods: {
  169. searchChange(e){
  170. // 如果没有搜索词
  171. if( !this.requestParam.name ){
  172. this.searchOpen();
  173. }
  174. },
  175. searchOpen(){
  176. // 请求中,不再请求
  177. if( this.isReqing ) return;
  178. // 是否是最后一页
  179. this.isLast = false;
  180. // 初始化页码为1
  181. this.requestParam.page = 1;
  182. // 设置请求中
  183. this.isReqing = true;
  184. // 请求列表
  185. this.$http.request('api/score_product/get_list',this.requestParam).then((re)=>{
  186. // 设置非请求中
  187. this.isReqing = false;
  188. // 成功结果
  189. if( re.code == 'success' ){
  190. this.productList = re.data.data;
  191. if( re.data.data.length && re.data.last_page >= this.requestParam.page ) this.isLast = true;
  192. }
  193. });
  194. },
  195. toDetail(item){
  196. uni.navigateTo({
  197. url:"/pages/score/product?id="+item.id,
  198. })
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="less">
  204. // .search_fixed{
  205. // top: var(--window-top);
  206. // left: 0rpx;
  207. // width: 750rpx;
  208. // display: block;
  209. // position: fixed;
  210. // margin: 0rpx auto;
  211. // padding: 20rpx 0rpx;
  212. // background-color: #FFFFFF;
  213. // .search_box{
  214. // width: 750rpx;
  215. // height: 60rpx;
  216. // display: block;
  217. // position: relative;
  218. // .search_input{
  219. // z-index: 0;
  220. // width: 590rpx;
  221. // height: 56rpx;
  222. // display: block;
  223. // font-size: 24rpx;
  224. // position: relative;
  225. // border-top-left-radius: 40rpx;
  226. // border-bottom-left-radius: 40rpx;
  227. // padding-left: 20rpx;
  228. // margin-left: 35rpx;
  229. // border: 2rpx solid #dddddd;
  230. // }
  231. // .search_btn{
  232. // top: 0rpx;
  233. // z-index: 9;
  234. // left: 610rpx;
  235. // color: #FFFFFF;
  236. // position: absolute;
  237. // display: block;
  238. // width: 120rpx;
  239. // height: 60rpx;
  240. // font-size: 24rpx;
  241. // margin: 0rpx 0rpx;
  242. // padding: 0rpx 0rpx;
  243. // line-height: 60rpx;
  244. // border-radius: 40rpx;
  245. // background-color: #E03519;
  246. // }
  247. // }
  248. // }
  249. // .product_box{
  250. // display: block;
  251. // overflow: hidden;
  252. // margin: 0rpx auto;
  253. // margin-top: 120rpx;
  254. // padding: 0rpx 35rpx;
  255. // .product_list{
  256. // display: block;
  257. // overflow: hidden;
  258. // margin: 0rpx auto;
  259. // .product_item{
  260. // float: left;
  261. // width: 320rpx;
  262. // display: block;
  263. // overflow: hidden;
  264. // margin: 20rpx 0rpx;
  265. // margin-right: 20rpx;
  266. // background-color: #FFFFFF;
  267. // border-radius: 20rpx;
  268. // .product_image{
  269. // width: 320rpx;
  270. // height: 320rpx;
  271. // }
  272. // .product_name{
  273. // height: 80rpx;
  274. // font-size: 26rpx;
  275. // line-height: 40rpx;
  276. // overflow: hidden;
  277. // padding: 10rpx 10rpx;
  278. // }
  279. // .product_spec{
  280. // color: #999999;
  281. // font-size: 22rpx;
  282. // line-height: 30rpx;
  283. // padding: 0rpx 10rpx;
  284. // }
  285. // .stock_price{
  286. // color: #dddddd;
  287. // font-size: 20rpx;
  288. // overflow: hidden;
  289. // line-height: 30rpx;
  290. // padding: 0rpx 10rpx;
  291. // .product_price{
  292. // float: left;
  293. // color: red;
  294. // font-size: 30rpx;
  295. // line-height: 60rpx;
  296. // .product_market{
  297. // font-size: 24rpx;
  298. // color: #999999;
  299. // line-height: 30rpx;
  300. // vertical-align: top;
  301. // text-decoration: line-through;
  302. // }
  303. // }
  304. // .product_stock{
  305. // float: right;
  306. // font-size: 20rpx;
  307. // line-height: 60rpx;
  308. // }
  309. // }
  310. // }
  311. // .product_item:nth-child(even){
  312. // margin-right: 0rpx;
  313. // }
  314. // }
  315. // }
  316. .header_fixed{
  317. width: 750rpx;
  318. position: fixed;
  319. top: 0rpx;
  320. background-color: #fff;
  321. .user_title{
  322. width: 690rpx;
  323. margin: 30rpx auto;
  324. display: flex;
  325. .user_prc{
  326. width: 100rpx;
  327. height: 100rpx;
  328. border-radius: 50%;
  329. image{
  330. border-radius: 50%;
  331. width: 100%;
  332. height: 100%;
  333. }
  334. }
  335. .title{
  336. margin-left: 30rpx;
  337. }
  338. }
  339. .search{
  340. width: 690rpx;
  341. margin: 30rpx auto;
  342. padding-top: 1rpx;
  343. .search_box{
  344. width: 690rpx;
  345. height: 70rpx;
  346. border: 2rpx solid #c2c2c2;
  347. position: relative;
  348. border-radius: 60rpx;
  349. .search_input{
  350. position: absolute;
  351. width: 600rpx;
  352. right: 0rpx;
  353. top: 10rpx;
  354. }
  355. .search_icon{
  356. position: absolute;
  357. width: 90rpx;
  358. left: 0rpx;
  359. top: 15rpx;
  360. text-align: center;
  361. }
  362. }
  363. }
  364. .course_option{
  365. display: flex;
  366. width: 690rpx;
  367. margin: 0rpx auto;
  368. justify-content: space-between;
  369. .option_name{
  370. text-align: center;
  371. width: 150rpx;
  372. height: 50rpx;
  373. line-height: 50rpx;
  374. font-size: 24rpx;
  375. border-radius: 60rpx;
  376. margin: 20rpx 0rpx;
  377. background-color: #e2e2e2;
  378. }
  379. }
  380. }
  381. .product_box{
  382. display: block;
  383. overflow: hidden;
  384. margin: 0rpx auto;
  385. margin-top: 380rpx;
  386. padding: 0rpx 35rpx;
  387. .product_list{
  388. display: block;
  389. overflow: hidden;
  390. margin: 0rpx auto;
  391. .product_item{
  392. float: left;
  393. width: 320rpx;
  394. display: block;
  395. overflow: hidden;
  396. margin: 20rpx 0rpx;
  397. margin-right: 20rpx;
  398. background-color: #FFFFFF;
  399. border-radius: 20rpx;
  400. .product_image{
  401. width: 320rpx;
  402. height: 320rpx;
  403. }
  404. .product_name{
  405. height: 80rpx;
  406. font-size: 26rpx;
  407. line-height: 40rpx;
  408. overflow: hidden;
  409. padding: 10rpx 10rpx;
  410. }
  411. .product_spec{
  412. color: #999999;
  413. font-size: 22rpx;
  414. line-height: 30rpx;
  415. padding: 0rpx 10rpx;
  416. }
  417. .stock_price{
  418. color: #dddddd;
  419. font-size: 20rpx;
  420. overflow: hidden;
  421. line-height: 30rpx;
  422. padding: 0rpx 10rpx;
  423. .product_price{
  424. float: left;
  425. color: red;
  426. font-size: 30rpx;
  427. line-height: 60rpx;
  428. .product_market{
  429. font-size: 24rpx;
  430. color: #999999;
  431. line-height: 30rpx;
  432. vertical-align: top;
  433. text-decoration: line-through;
  434. }
  435. }
  436. .product_stock{
  437. float: right;
  438. font-size: 20rpx;
  439. line-height: 60rpx;
  440. }
  441. }
  442. }
  443. .product_item:nth-child(even){
  444. margin-right: 0rpx;
  445. }
  446. }
  447. }
  448. </style>