list.vue 12 KB

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