index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view>
  3. <!-- 轮播图 -->
  4. <view class="banner_box" >
  5. <view class="banner_list" v-if="bannerList.length">
  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" @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. <!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
  18. <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item,index) in productList" :key="index" >
  19. <image class="product_image" :src="item.thumb" mode=""></image>
  20. <view class="product_name">
  21. <text v-if="item.promo_title" class="regiment_title">{{item.promo_title}}</text>
  22. <text v-if="item.regiment_title" class="regiment_title">{{item.regiment_title}}</text>
  23. <text>{{item.name}}</text></view>
  24. <view class="product_spec"><text>{{item.spec}}</text></view>
  25. <view class="stock_price">
  26. <view class="product_price" v-if="isShowPrice">
  27. <text >¥{{item.price}} </text>
  28. </view>
  29. <view class="product_stock">剩{{item.stock}}个</view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="search_fixed" >
  35. <view class="search_box">
  36. <view class="city_name" v-if="!toSelectedCity">
  37. <navigator url="/pages/user/info" v-if="isManager" >{{cityName}}</navigator>
  38. <text v-if="!isManager" >{{cityName}}</text>
  39. </view>
  40. <navigator url="/pages/user/info" v-if="toSelectedCity" class="city_name uncheck">选城市</navigator>
  41. <input class="search_input" type="text" v-model="requestParam.name" @input="searchChange" placeholder="请输入产品名称搜索" />
  42. <button class="search_btn" @click.stop="searchOpen()" data-eventsync="true"> 搜索</button>
  43. </view>
  44. </view>
  45. <view class="to_bottom" v-if="isLast"> -----{{ !productList.length && toSelectedCity?'请选择您的城市':'到底啦'}}-----</view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. // 轮播图
  53. bannerList:[],
  54. // 产品列表
  55. productList:[],
  56. // 请求参数
  57. requestParam:{
  58. name:"",
  59. page:1,
  60. },
  61. // 是否最后一页
  62. isLast:false,
  63. // 是否请求中
  64. isReqing:false,
  65. // 是否显示价格
  66. isShowPrice:false,
  67. // 城市名称
  68. cityName:"选城市",
  69. // 选择城市
  70. toSelectedCity:false,
  71. // 是否是管理员
  72. isManager:false,
  73. }
  74. },
  75. onLoad() {
  76. // #ifdef MP-WEIXIN
  77. //分享按钮
  78. uni.showShareMenu({
  79. withShareTicket: true,
  80. menus: ['shareAppMessage', 'shareTimeline']
  81. })
  82. // #endif
  83. },
  84. onShareAppMessage(obj) {
  85. // 获取分享信息
  86. let shareList = getApp().globalData.shareList;
  87. // 获取分享信息
  88. let shareObj = {
  89. title: '药优惠 得积分 兑豪礼',
  90. path: '/pages/index.vue/index.vue',
  91. imageUrl:'',
  92. };
  93. // 循环列表
  94. for ( let i in shareList ) {
  95. if( shareList[i].pages == 'pages/index.vue/index.vue' ) {
  96. shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path ;
  97. shareObj.title = shareList[i].title ? shareList[i].title : shareObj.title ;
  98. shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl ;
  99. }
  100. }
  101. // 返回分享信息
  102. return shareObj;
  103. },
  104. onShow() {
  105. // 是否显示价格
  106. this.isShowPrice = this.$checkAccess.checkShowPrice();
  107. // 城市名
  108. this.cityName = this.$checkAccess.getCity();
  109. // 选城市
  110. this.cityName = this.cityName ? this.cityName : "选城市",
  111. // 登录并且未选择城市,才可以选择城市
  112. this.toSelectedCity = !this.$checkAccess.getCity() ? true : false;
  113. // 数据
  114. this.isManager = this.$checkAccess.isManager();
  115. // 没有数据的话,或者请求中,不允许刷新
  116. if( this.isReqing ) return ;
  117. // 获取列表
  118. this.$http.request("/api/banner/get_list").then((re)=>{
  119. if(re.code === "success"){
  120. this.bannerList = re.data;
  121. }
  122. })
  123. // 请求参数
  124. this.requestParam.name = "";
  125. // 请求参数
  126. this.requestParam.page = 1;
  127. // 是否是最后一页
  128. this.isLast = false;
  129. // 设置请求中
  130. this.isReqing = true;
  131. // 请求
  132. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  133. // 设置非请求中
  134. this.isReqing = false;
  135. // 成功结果
  136. if( re.code == 'success' ){
  137. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  138. this.productList = re.data.data;
  139. }
  140. });
  141. },
  142. onPullDownRefresh() {
  143. // 如果请求中,不允许请求,
  144. if( this.isReqing ) return false;
  145. // 初始化页码为1
  146. this.requestParam.page = 1;
  147. // 是否是最后一页
  148. this.isLast = false;
  149. // 设置请求中
  150. this.isReqing = true;
  151. // 请求列表
  152. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  153. // 设置非请求中
  154. this.isReqing = false;
  155. // 成功结果
  156. if( re.code == 'success' ){
  157. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  158. this.productList = re.data.data;
  159. }
  160. });
  161. uni.stopPullDownRefresh();
  162. },
  163. onReachBottom() {
  164. // 如果页码是0,避免第一页重复
  165. if( this.requestParam.page < 1 ) return;
  166. // 最后一页不再请求
  167. if( this.isLast ) return;
  168. // 请求中,不再请求
  169. if( this.isReqing ) return;
  170. // 增加一页
  171. this.requestParam.page = this.requestParam.page+1;
  172. // 设置请求中
  173. this.isReqing = true;
  174. // 请求列表
  175. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  176. // 设置非请求中
  177. this.isReqing = false;
  178. // 成功结果
  179. if( re.code == 'success' ){
  180. // 最后一页
  181. if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
  182. // 追加数据
  183. this.productList.push(...re.data.data);
  184. }
  185. });
  186. },
  187. methods: {
  188. searchChange(e){
  189. // 如果没有搜索词
  190. if( !this.requestParam.name ){
  191. this.searchOpen();
  192. }
  193. },
  194. searchOpen(){
  195. // 请求中,不再请求
  196. if( this.isReqing ) return;
  197. // 是否是最后一页
  198. this.isLast = false;
  199. // 初始化页码为1
  200. this.requestParam.page = 1;
  201. // 设置请求中
  202. this.isReqing = true;
  203. // 请求列表
  204. this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
  205. // 设置非请求中
  206. this.isReqing = false;
  207. // 成功结果
  208. if( re.code == 'success' ){
  209. this.productList = re.data.data;
  210. if( re.data.data.length && re.data.last_page >= this.requestParam.page ) this.isLast = true;
  211. }
  212. });
  213. },
  214. toDetail(item){
  215. uni.navigateTo({
  216. url:"/pages/product/index?product_id="+item.id,
  217. })
  218. },
  219. navLottery(url){
  220. // 没有路径,不跳转
  221. if( !url ) return;
  222. // 判断是不是小程序链接
  223. if( url.includes('http') ){
  224. // 转码
  225. let link_url = encodeURIComponent(url);
  226. // 跳转到webview
  227. uni.redirectTo({
  228. url:`/pages/webview/index?link_url=${link_url}`
  229. })
  230. }else{
  231. // 跳转到webview
  232. uni.navigateTo({
  233. url:url
  234. })
  235. }
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="less">
  241. .search_fixed{
  242. top: var(--window-top);
  243. left: 0rpx;
  244. width: 750rpx;
  245. display: block;
  246. position: fixed;
  247. margin: 0rpx auto;
  248. padding: 20rpx 0rpx;
  249. background-color: #FFFFFF;
  250. .search_box{
  251. width: 750rpx;
  252. height: 60rpx;
  253. display: block;
  254. position: relative;
  255. .city_name{
  256. float: left;
  257. width: 80rpx;
  258. height: 60rpx;
  259. display: block;
  260. font-size: 24rpx;
  261. overflow: hidden;
  262. margin-left: 35rpx;
  263. line-height: 60rpx;
  264. white-space: nowrap;
  265. text-overflow: ellipsis;
  266. }
  267. .city_name.uncheck{
  268. color: #E03519;
  269. }
  270. .search_input{
  271. z-index: 0;
  272. float: left;
  273. width: 510rpx;
  274. height: 56rpx;
  275. display: block;
  276. font-size: 24rpx;
  277. padding-left: 20rpx;
  278. position: relative;
  279. border-top-left-radius: 40rpx;
  280. border-bottom-left-radius: 40rpx;
  281. border: 2rpx solid #dddddd;
  282. }
  283. .search_btn{
  284. top: 0rpx;
  285. z-index: 9;
  286. left: 610rpx;
  287. color: #FFFFFF;
  288. position: absolute;
  289. display: block;
  290. width: 120rpx;
  291. height: 60rpx;
  292. font-size: 24rpx;
  293. margin: 0rpx 0rpx;
  294. padding: 0rpx 0rpx;
  295. line-height: 60rpx;
  296. border-radius: 40rpx;
  297. background-color: #E03519;
  298. }
  299. }
  300. }
  301. .banner_box{
  302. width: 680rpx;
  303. display: block;
  304. overflow: hidden;
  305. margin: 0rpx auto;
  306. margin-top: 120rpx;
  307. .banner_list{
  308. display: block;
  309. width: 680rpx;
  310. height: 382rpx;
  311. line-height: 382rpx;
  312. text-align: center;
  313. .banner_swiper{
  314. display: block;
  315. width: 680rpx;
  316. height: 382rpx;
  317. line-height: 382rpx;
  318. text-align: center;
  319. .image{
  320. width: 680rpx;
  321. height: 382rpx;
  322. }
  323. }
  324. }
  325. }
  326. .product_box{
  327. display: block;
  328. overflow: hidden;
  329. margin: 20rpx auto;
  330. padding: 0rpx 35rpx;
  331. .product_list{
  332. display: block;
  333. overflow: hidden;
  334. margin: 0rpx auto;
  335. .product_item{
  336. float: left;
  337. width: 320rpx;
  338. height: 520rpx;
  339. display: block;
  340. overflow: hidden;
  341. margin: 20rpx 0rpx;
  342. margin-right: 40rpx;
  343. background-color: #FFFFFF;
  344. border-radius: 20rpx;
  345. .product_image{
  346. width: 320rpx;
  347. height: 320rpx;
  348. }
  349. .product_name{
  350. height: 80rpx;
  351. font-size: 30rpx;
  352. line-height: 40rpx;
  353. overflow: hidden;
  354. margin: 10rpx 0rpx;
  355. padding: 0rpx 10rpx;
  356. text-overflow: ellipsis;
  357. .regiment_title{
  358. background-color: red;
  359. color: #F9F9F9;
  360. }
  361. }
  362. .product_spec{
  363. height: 30rpx;
  364. color: #999999;
  365. font-size: 24rpx;
  366. line-height: 30rpx;
  367. padding: 0rpx 10rpx;
  368. overflow: hidden;
  369. white-space: nowrap;
  370. text-overflow: ellipsis;
  371. }
  372. .stock_price{
  373. color: #dddddd;
  374. font-size: 20rpx;
  375. overflow: hidden;
  376. line-height: 30rpx;
  377. padding: 0rpx 10rpx;
  378. .product_price{
  379. float: left;
  380. color: red;
  381. font-size: 30rpx;
  382. line-height: 60rpx;
  383. .product_market{
  384. font-size: 24rpx;
  385. color: #999999;
  386. line-height: 30rpx;
  387. vertical-align: top;
  388. text-decoration: line-through;
  389. }
  390. }
  391. .product_stock{
  392. float: right;
  393. font-size: 20rpx;
  394. line-height: 60rpx;
  395. }
  396. }
  397. }
  398. .product_item:nth-child(even){
  399. margin-right: 0rpx;
  400. }
  401. }
  402. }
  403. </style>