index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view>
  3. <!-- 轮播图 -->
  4. <view class="banner_box" >
  5. <view class="banner_list" >
  6. <swiper class="banner_swiper" :autoplay="true" >
  7. <swiper-item v-for="(item,index) in bannerList" :key="index">
  8. <image :src="item.thumb" class="image" mode="widthFix" @click="navLottery(item.link_url)"></image>
  9. </swiper-item>
  10. </swiper>
  11. </view>
  12. </view>
  13. <view class="product_box">
  14. <view class="to_bottom" v-if="!productList.length"> -----还没有产品啦-----</view>
  15. <!-- 产品列表 -->
  16. <view class="product_list" >
  17. <!-- <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item,index) in productList" :key="index" >
  18. <image class="product_image" :src="item.thumb" mode=""></image>
  19. <view class="product_name"><text>{{item.name}}</text></view>
  20. <view class="product_spec"><text>{{item.spec}}</text></view>
  21. <view class="stock_price">
  22. <view class="product_price" v-if="isShowPrice">
  23. <text >¥{{item.price}} </text>
  24. </view>
  25. <view class="product_stock">剩{{item.stock}}个</view>
  26. </view>
  27. </view> -->
  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. <view class="product_left">
  31. <image class="product_image" :src="item.thumb" mode=""></image>
  32. </view>
  33. <view class="product_right">
  34. <view class="product_title">
  35. <view class="product_text">
  36. <text>{{item.name}}</text>
  37. </view>
  38. <view class="time">
  39. <text>{{item.spec}}</text>
  40. </view>
  41. </view>
  42. <view class="stock_price">
  43. <view class="product_price" >
  44. <span style="font-size: 26rpx;">¥</span><text >{{item.price}}</text>
  45. </view>
  46. <view class="product_order_but">
  47. <button>立即购买</button>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="search_fixed" >
  55. <view class="search_box">
  56. <input class="search_input" type="text" v-model="requestParam.name" @input="searchChange" placeholder="请输入产品名称搜索" />
  57. <button class="search_btn" @click.stop="searchOpen()" data-eventsync="true"> 搜索</button>
  58. </view>
  59. </view>
  60. <view class="to_bottom" v-if="isLast"> -----到底啦-----</view>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. // 轮播图
  68. bannerList:[],
  69. // 产品列表
  70. productList:[],
  71. // 请求参数
  72. requestParam:{
  73. name:"",
  74. page:1,
  75. },
  76. // 是否最后一页
  77. isLast:false,
  78. // 是否请求中
  79. isReqing:false,
  80. // 是否显示价格
  81. isShowPrice:false,
  82. }
  83. },
  84. onLoad() {
  85. },
  86. onShow() {
  87. // 是否显示价格
  88. this.isShowPrice = this.$checkAccess.checkShowPrice();
  89. // 没有数据的话,或者请求中,不允许刷新
  90. if( this.isReqing ) return ;
  91. // 获取列表
  92. this.$http.request("/api/banner/get_list").then((re)=>{
  93. if(re.code === "success"){
  94. this.bannerList = re.data;
  95. }
  96. })
  97. // 请求参数
  98. this.requestParam.name = "";
  99. // 请求参数
  100. this.requestParam.page = 1;
  101. // 是否是最后一页
  102. this.isLast = false;
  103. // 设置请求中
  104. this.isReqing = true;
  105. // 请求
  106. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  107. // 设置非请求中
  108. this.isReqing = false;
  109. // 成功结果
  110. if( re.code == 'success' ){
  111. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  112. this.productList = re.data.data;
  113. }
  114. });
  115. },
  116. onPullDownRefresh() {
  117. // 如果请求中,不允许请求,
  118. if( this.isReqing ) return false;
  119. // 初始化页码为1
  120. this.requestParam.page = 1;
  121. // 是否是最后一页
  122. this.isLast = false;
  123. // 设置请求中
  124. this.isReqing = true;
  125. // 请求列表
  126. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  127. // 设置非请求中
  128. this.isReqing = false;
  129. // 成功结果
  130. if( re.code == 'success' ){
  131. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  132. this.productList = re.data.data;
  133. }
  134. });
  135. uni.stopPullDownRefresh();
  136. },
  137. onReachBottom() {
  138. // 如果页码是0,避免第一页重复
  139. if( this.requestParam.page < 1 ) return;
  140. // 最后一页不再请求
  141. if( this.isLast ) return;
  142. // 请求中,不再请求
  143. if( this.isReqing ) return;
  144. // 增加一页
  145. this.requestParam.page = this.requestParam.page+1;
  146. // 设置请求中
  147. this.isReqing = true;
  148. // 请求列表
  149. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  150. // 设置非请求中
  151. this.isReqing = false;
  152. // 成功结果
  153. if( re.code == 'success' ){
  154. // 最后一页
  155. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  156. // 追加数据
  157. this.productList.push(...re.data.data);
  158. }
  159. });
  160. },
  161. methods: {
  162. searchChange(e){
  163. // 如果没有搜索词
  164. if( !this.requestParam.name ){
  165. this.searchOpen();
  166. }
  167. },
  168. searchOpen(){
  169. // 请求中,不再请求
  170. if( this.isReqing ) return;
  171. // 是否是最后一页
  172. this.isLast = false;
  173. // 初始化页码为1
  174. this.requestParam.page = 1;
  175. // 设置请求中
  176. this.isReqing = true;
  177. // 请求列表
  178. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  179. // 设置非请求中
  180. this.isReqing = false;
  181. // 成功结果
  182. if( re.code == 'success' ){
  183. this.productList = re.data.data;
  184. if( re.data.data.length && re.data.last_page >= this.requestParam.page ) this.isLast = true;
  185. }
  186. });
  187. },
  188. toDetail(item){
  189. uni.navigateTo({
  190. url:"/pages/product/index?product_id="+item.id,
  191. })
  192. },
  193. navLottery(url){
  194. // 没有路径,不跳转
  195. if( !url ) return;
  196. // 转码
  197. let link_url = encodeURIComponent(url);
  198. // 跳转到webview
  199. uni.redirectTo({
  200. url:`/pages/webview/index?link_url=${link_url}`
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="less">
  207. .search_fixed{
  208. top: var(--window-top);
  209. width: 750rpx;
  210. display: block;
  211. position: fixed;
  212. margin: 0rpx auto;
  213. padding: 20rpx 0rpx;
  214. background-color: #FFFFFF;
  215. .search_box{
  216. width: 590rpx;
  217. height: 60rpx;
  218. display: block;
  219. position: relative;
  220. .search_input{
  221. z-index: 0;
  222. width:580rpx;
  223. height: 56rpx;
  224. display: block;
  225. font-size: 24rpx;
  226. position: relative;
  227. border-top-left-radius: 40rpx;
  228. border-bottom-left-radius: 40rpx;
  229. padding-left: 20rpx;
  230. margin-left: 35rpx;
  231. background-color: #FFFFFF;
  232. border: 2rpx solid #dddddd;
  233. text{
  234. width: 120rpx;
  235. height: 60rpx;
  236. line-height: 60rpx;
  237. margin-left: 80rpx;
  238. }
  239. }
  240. .icon{
  241. position: absolute;
  242. top: 0rpx;
  243. left: 60rpx;
  244. width: 120rpx;
  245. height: 60rpx;
  246. line-height: 60rpx;
  247. }
  248. .search_btn{
  249. top: 0rpx;
  250. z-index: 9;
  251. left: 610rpx;
  252. color: #FFFFFF;
  253. position: absolute;
  254. display: block;
  255. width: 120rpx;
  256. height: 60rpx;
  257. font-size: 24rpx;
  258. margin: 0rpx 0rpx;
  259. padding: 0rpx 0rpx;
  260. line-height: 60rpx;
  261. border-radius: 40rpx;
  262. background-color: #E03519;
  263. }
  264. }
  265. }
  266. .banner_box{
  267. width: 680rpx;
  268. display: block;
  269. overflow: hidden;
  270. margin: 0rpx auto;
  271. margin-top: 120rpx;
  272. .banner_list{
  273. display: block;
  274. max-width: 680rpx;
  275. text-align: center;
  276. .banner_swiper{
  277. display: block;
  278. max-width: 680rpx;
  279. text-align: center;
  280. .image{
  281. width: 680rpx;
  282. height: 382rpx;
  283. }
  284. }
  285. }
  286. }
  287. .product_box{
  288. display: block;
  289. overflow: hidden;
  290. margin: 20rpx auto;
  291. padding: 0rpx 35rpx;
  292. .product_list{
  293. display: block;
  294. overflow: hidden;
  295. margin: 0rpx auto;
  296. .product_item{
  297. width: 690rpx;
  298. display: block;
  299. overflow: hidden;
  300. margin: 20rpx 0rpx;
  301. margin-right: 20rpx;
  302. background-color: #FFFFFF;
  303. border-radius: 20rpx;
  304. .product_left{
  305. float: left;
  306. .product_image{
  307. margin: 20rpx 20rpx;
  308. width: 224rpx;
  309. height: 200rpx;
  310. border-radius: 20rpx;
  311. }
  312. }
  313. .product_right{
  314. float: left;
  315. width: 380rpx;
  316. margin: 20rpx 20rpx;
  317. .product_title{
  318. line-height: 1.5;
  319. .product_text{
  320. font-size: 30rpx;
  321. font-weight: 600;
  322. }
  323. .time{
  324. font-size: 24rpx;
  325. }
  326. }
  327. .stock_price{
  328. color: #dddddd;
  329. height: 100rpx;
  330. font-size: 20rpx;
  331. overflow: hidden;
  332. line-height: 30rpx;
  333. padding: 0rpx 10rpx;
  334. margin-top: 40rpx;
  335. .product_price{
  336. float: left;
  337. color: red;
  338. font-size: 50rpx;
  339. font-weight: 600;
  340. line-height: 100rpx;
  341. }
  342. .product_order_but{
  343. float: right;
  344. button{
  345. width: 166rpx;
  346. height: 64rpx;
  347. font-size: 26rpx;
  348. font-weight: 600;
  349. margin: 20rpx 0rpx;
  350. background-color: #1fbe7e;
  351. border-radius: 40rpx;
  352. color: #FFFFFF;
  353. }
  354. }
  355. }
  356. }
  357. }
  358. .product_item:nth-child(even){
  359. margin-right: 0rpx;
  360. }
  361. }
  362. }
  363. </style>