list.vue 14 KB

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