list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <view style="padding-top: 120rpx">
  3. <!-- 轮播图 -->
  4. <view class="search_fixed">
  5. <view class="search_box">
  6. <input class="search_input" type="text" v-model="requestParam.name" @input="searchChange" placeholder="请输入产品名称搜索" />
  7. <button class="search_btn" @click.stop="searchOpen()" data-eventsync="true">搜索</button>
  8. </view>
  9. </view>
  10. <view class="product_box">
  11. <view class="to_bottom" v-if="!productList.length"> -----还没有产品啦-----</view>
  12. <!-- 产品列表 -->
  13. <view class="product_list">
  14. <!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
  15. <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item, index) in productList" :key="index">
  16. <view class="product_item_content">
  17. <view class="product_image_content">
  18. <image class="product_image" :src="item.thumb" mode=""></image>
  19. </view>
  20. <view>
  21. <view class="product_name">
  22. <text v-if="item.promo_title" class="regiment_title">{{ item.promo_title }}</text>
  23. <text v-if="item.regiment_title" class="regiment_title">{{ item.regiment_title }}</text>
  24. <text>{{ item.name }}</text></view
  25. >
  26. <view class="product_spec"
  27. ><text>{{ item.spec }}</text></view
  28. ></view
  29. >
  30. </view>
  31. <view class="product_item_bottom">
  32. <view class="stock_price">
  33. <view class="product_price" v-if="isShowPrice">
  34. <text>¥{{ item.price }} </text>
  35. </view>
  36. <view class="product_stock">剩{{ item.stock }}个</view>
  37. </view>
  38. <view class="stock_button">立即抢购</view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="to_bottom" v-if="isLast" style="display: flex; justify-content: center">
  44. -----
  45. <view :style="!productList.length && toSelectedCity ? 'font-weight:bold;font-size:36rpx' : ''">{{ !productList.length && toSelectedCity ? '请点击左上角选择你的城市' : '到底啦' }}</view> -----
  46. </view>
  47. <uni-popup ref="addFollow" type="center" class="center_popup">
  48. <FollowPopup :closePopup="closePopup" />
  49. </uni-popup>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. // 轮播图
  57. bannerList: [],
  58. // 产品列表
  59. productList: [],
  60. // 请求参数
  61. requestParam: {
  62. name: '',
  63. page: 1,
  64. },
  65. // 是否最后一页
  66. isLast: false,
  67. // 是否请求中
  68. isReqing: false,
  69. // 是否显示价格
  70. isShowPrice: false,
  71. // 城市名称
  72. cityName: '选城市',
  73. // 选择城市
  74. toSelectedCity: false,
  75. // 是否是管理员
  76. isManager: false,
  77. };
  78. },
  79. onLoad() {
  80. // #ifdef MP-WEIXIN
  81. //分享按钮
  82. uni.showShareMenu({
  83. withShareTicket: true,
  84. menus: ['shareAppMessage', 'shareTimeline'],
  85. });
  86. // #endif
  87. },
  88. onShareAppMessage(obj) {
  89. // 获取分享信息
  90. let shareList = getApp().globalData.shareList;
  91. // 获取分享信息
  92. let shareObj = {
  93. title: '999智控终端平台\n药优惠 得积分 兑豪礼',
  94. path: '/pages/index/index',
  95. imageUrl: '',
  96. };
  97. // 循环列表
  98. for (let i in shareList) {
  99. if (shareList[i].pages == 'pages/index/index') {
  100. shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
  101. shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
  102. shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
  103. }
  104. }
  105. // 返回分享信息
  106. return shareObj;
  107. },
  108. onShow() {
  109. // 是否显示价格
  110. this.isShowPrice = this.$checkAccess.checkShowPrice();
  111. // 城市名
  112. this.cityName = this.$checkAccess.getCity();
  113. // 选城市
  114. (this.cityName = this.cityName ? this.cityName : '选城市'),
  115. // 登录并且未选择城市,才可以选择城市
  116. (this.toSelectedCity = !this.$checkAccess.getCity() ? true : false);
  117. // 数据
  118. //未选城市先弹窗提醒选择城市
  119. if (!this.$checkAccess.getCity() && this.$checkAccess.checkLogin()) {
  120. uni.showModal({
  121. title: '',
  122. content: '请先选择城市',
  123. success: (res) => {
  124. if (res.confirm) {
  125. uni.navigateTo({
  126. url: '/pages/user/info',
  127. });
  128. }
  129. },
  130. });
  131. }
  132. //如果已选城市且没有添加客服每天弹窗一次
  133. if (this.$checkAccess.getCity() && this.$checkAccess.getFollowQrcode()) {
  134. // 获取弹出时间
  135. let followPopupTime = uni.getStorageSync('followPopupTime');
  136. // 现在的时候
  137. let nowTime = new Date().getTime();
  138. // 时间戳
  139. followPopupTime = followPopupTime ? followPopupTime : 0;
  140. // 弹出结果
  141. if (followPopupTime <= 0 || followPopupTime - nowTime > 86400000) {
  142. this.$refs.addFollow.open('center');
  143. uni.setStorageSync('followPopupTime', nowTime);
  144. }
  145. }
  146. this.isManager = this.$checkAccess.isManager();
  147. // 没有数据的话,或者请求中,不允许刷新
  148. if (this.isReqing) return;
  149. // 获取列表
  150. this.$http.request('/api/banner/get_list').then((re) => {
  151. if (re.code === 'success') {
  152. this.bannerList = re.data;
  153. }
  154. });
  155. // 请求参数
  156. this.requestParam.name = '';
  157. // 请求参数
  158. this.requestParam.page = 1;
  159. // 是否是最后一页
  160. this.isLast = false;
  161. // 设置请求中
  162. this.isReqing = true;
  163. // 请求
  164. this.$http.request('api/product/get_list', this.requestParam).then((re) => {
  165. // 设置非请求中
  166. this.isReqing = false;
  167. // 成功结果
  168. if (re.code == 'success') {
  169. // 如果是最后一页
  170. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  171. // 赋值
  172. this.productList = re.data.data;
  173. // 获取下一页
  174. this.getMore(re);
  175. }
  176. });
  177. },
  178. onPullDownRefresh() {
  179. // 如果请求中,不允许请求,
  180. if (this.isReqing) return false;
  181. // 初始化页码为1
  182. this.requestParam.page = 1;
  183. // 是否是最后一页
  184. this.isLast = false;
  185. // 设置请求中
  186. this.isReqing = true;
  187. // 请求列表
  188. this.$http.request('api/product/get_list', this.requestParam).then((re) => {
  189. // 设置非请求中
  190. this.isReqing = false;
  191. // 成功结果
  192. if (re.code == 'success') {
  193. // 如果是最后一页
  194. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  195. // 赋值
  196. this.productList = re.data.data;
  197. // 获取下一页
  198. this.getMore(re);
  199. }
  200. });
  201. uni.stopPullDownRefresh();
  202. },
  203. onReachBottom() {
  204. // 如果页码是0,避免第一页重复
  205. if (this.requestParam.page < 1) return;
  206. // 最后一页不再请求
  207. if (this.isLast) return;
  208. // 请求中,不再请求
  209. if (this.isReqing) return;
  210. // 增加一页
  211. this.requestParam.page = this.requestParam.page + 1;
  212. // 设置请求中
  213. this.isReqing = true;
  214. // 请求列表
  215. this.$http.request('api/product/get_list', this.requestParam).then((re) => {
  216. // 设置非请求中
  217. this.isReqing = false;
  218. // 成功结果
  219. if (re.code == 'success') {
  220. // 最后一页
  221. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  222. // 追加数据
  223. this.productList.push(...re.data.data);
  224. }
  225. });
  226. },
  227. methods: {
  228. // 请求加载下一页
  229. getMore(callback) {
  230. // 首页不足10个,并且下一页存在大于当前页
  231. if (this.productList.length < 10 && callback.data.last_page > this.requestParam.page) {
  232. // 最后一页不再请求
  233. if (this.isLast) return;
  234. // 增加一页
  235. this.requestParam.page = this.requestParam.page + 1;
  236. // 请求列表
  237. this.$http.request('api/product/get_list', this.requestParam).then((re) => {
  238. // 成功结果
  239. if (re.code == 'success') {
  240. // 最后一页
  241. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  242. // 追加数据
  243. this.productList.push(...re.data.data);
  244. // 获取下一页
  245. this.getMore(re);
  246. }
  247. });
  248. }
  249. },
  250. searchChange(e) {
  251. // 如果没有搜索词
  252. if (!this.requestParam.name) {
  253. this.searchOpen();
  254. }
  255. },
  256. searchOpen() {
  257. // 请求中,不再请求
  258. if (this.isReqing) return;
  259. // 是否是最后一页
  260. this.isLast = false;
  261. // 初始化页码为1
  262. this.requestParam.page = 1;
  263. // 设置请求中
  264. this.isReqing = true;
  265. // 请求列表
  266. this.$http.request('api/product/get_list', this.requestParam).then((re) => {
  267. // 设置非请求中
  268. this.isReqing = false;
  269. // 成功结果
  270. if (re.code == 'success') {
  271. this.productList = re.data.data;
  272. if (re.data.data.length && re.data.last_page >= this.requestParam.page) this.isLast = true;
  273. }
  274. });
  275. },
  276. toDetail(item) {
  277. uni.navigateTo({
  278. url: '/pages/product/index?product_id=' + item.id,
  279. });
  280. },
  281. navLottery(url) {
  282. // 没有路径,不跳转
  283. if (!url) return;
  284. // 判断是不是小程序链接
  285. if (url.includes('http')) {
  286. // 转码
  287. let link_url = encodeURIComponent(url);
  288. // 跳转到webview
  289. uni.redirectTo({
  290. url: `/pages/webview/index?link_url=${link_url}`,
  291. });
  292. } else {
  293. // 跳转到webview
  294. uni.navigateTo({
  295. url: url,
  296. });
  297. }
  298. },
  299. closePopup() {
  300. this.$refs.addFollow.close();
  301. //存key以及时间
  302. uni.setStorage({
  303. key: 'followPopupTime',
  304. data: new Date().getTime(),
  305. });
  306. },
  307. },
  308. };
  309. </script>
  310. <style lang="less" scoped>
  311. .search_fixed {
  312. top: var(--window-top);
  313. left: 0rpx;
  314. width: 750rpx;
  315. display: block;
  316. position: fixed;
  317. margin: 0rpx auto;
  318. padding: 20rpx 20rpx;
  319. background-color: #ffffff;
  320. box-sizing: border-box;
  321. .search_box {
  322. width: 750rpx;
  323. height: 60rpx;
  324. display: block;
  325. position: relative;
  326. .search_input {
  327. z-index: 0;
  328. float: left;
  329. width: 600rpx;
  330. height: 56rpx;
  331. display: block;
  332. font-size: 24rpx;
  333. padding-left: 20rpx;
  334. position: relative;
  335. border-top-left-radius: 40rpx;
  336. border-bottom-left-radius: 40rpx;
  337. border: 2rpx solid #dddddd;
  338. }
  339. .search_btn {
  340. top: 0rpx;
  341. z-index: 9;
  342. right: 40rpx;
  343. color: #ffffff;
  344. position: absolute;
  345. display: block;
  346. width: 120rpx;
  347. height: 60rpx;
  348. font-size: 24rpx;
  349. margin: 0rpx 0rpx;
  350. padding: 0rpx 0rpx;
  351. line-height: 60rpx;
  352. border-radius: 40rpx;
  353. background-color: #e03519;
  354. }
  355. }
  356. }
  357. .product_box {
  358. display: block;
  359. overflow: hidden;
  360. margin: -20rpx auto 20rpx;
  361. padding: 0rpx 35rpx;
  362. .product_list {
  363. display: block;
  364. overflow: hidden;
  365. margin: 0rpx auto;
  366. .product_item {
  367. // float: left;
  368. width: 100%;
  369. // height: 520rpx;
  370. display: block;
  371. overflow: hidden;
  372. margin: 20rpx 0rpx;
  373. margin-right: 40rpx;
  374. background-color: #ffffff;
  375. border-radius: 20rpx;
  376. padding: 16rpx;
  377. box-sizing: border-box;
  378. .product_item_content {
  379. display: flex;
  380. gap: 10rpx;
  381. }
  382. .product_item_bottom {
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: center;
  386. }
  387. .product_image_content {
  388. width: 168rpx;
  389. height: 168rpx;
  390. background: #f5f5f5;
  391. border-radius: 16rpx 16rpx 16rpx 16rpx;
  392. display: flex;
  393. align-items: center;
  394. justify-content: center;
  395. flex-shrink: 0;
  396. }
  397. .product_image {
  398. width: 143rpx;
  399. height: 149rpx;
  400. flex-shrink: 0;
  401. }
  402. .product_name {
  403. // height: 80rpx;
  404. font-size: 30rpx;
  405. line-height: 40rpx;
  406. overflow: hidden;
  407. margin: 10rpx 0rpx;
  408. padding: 0rpx 10rpx;
  409. text-overflow: ellipsis;
  410. .regiment_title {
  411. background-color: red;
  412. color: #f9f9f9;
  413. }
  414. }
  415. .product_spec {
  416. height: 30rpx;
  417. color: #999999;
  418. font-size: 24rpx;
  419. line-height: 30rpx;
  420. padding: 0rpx 10rpx;
  421. overflow: hidden;
  422. white-space: nowrap;
  423. text-overflow: ellipsis;
  424. }
  425. .stock_price {
  426. color: #dddddd;
  427. font-size: 20rpx;
  428. overflow: hidden;
  429. line-height: 30rpx;
  430. padding: 0rpx 10rpx;
  431. display: flex;
  432. gap: 10rpx;
  433. align-items: baseline;
  434. padding-left: 185rpx;
  435. box-sizing: border-box;
  436. .product_price {
  437. color: red;
  438. font-size: 30rpx;
  439. line-height: 60rpx;
  440. .product_market {
  441. font-size: 24rpx;
  442. color: #999999;
  443. line-height: 30rpx;
  444. vertical-align: top;
  445. text-decoration: line-through;
  446. }
  447. }
  448. .product_stock {
  449. font-size: 20rpx;
  450. line-height: 60rpx;
  451. }
  452. }
  453. .stock_button {
  454. width: 152rpx;
  455. height: 60rpx;
  456. background: #f89c33;
  457. border-radius: 500rpx 500rpx 500rpx 500rpx;
  458. color: #ffffff;
  459. color: 26rpx;
  460. text-align: center;
  461. line-height: 60rpx;
  462. }
  463. }
  464. .product_item:nth-child(even) {
  465. margin-right: 0rpx;
  466. }
  467. }
  468. }
  469. </style>