index.vue 13 KB

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