index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <view class="u-p-l-20 u-p-r-20">
  3. <u-navbar :border-bottom="false" :is-back="false">
  4. <view class="main-flex">
  5. <view class="u-p-l-20" @click="notice">
  6. <u-icon color="#666" name="chat" size="50"></u-icon>
  7. </view>
  8. <!-- #ifdef H5-->
  9. <u-search v-model="keyword" :clearabled="true" :disabled="true" :show-action="false"
  10. class="u-p-l-20" input-align="left"
  11. placeholder="输入搜索关键字" style="width: 660rpx" @click="search"></u-search>
  12. <!-- #endif -->
  13. <!-- #ifdef MP-->
  14. <u-search v-model="keyword" :clearabled="true" :disabled="true" :show-action="false"
  15. class="u-p-l-20" input-align="left"
  16. placeholder="输入搜索关键字" style="width: 420rpx" @click="search"></u-search>
  17. <!-- #endif -->
  18. </view>
  19. </u-navbar>
  20. <view>
  21. <u-swiper :interval="5000" :list="swiperList" bg-color="#fff" effect3d effect3d-previous-margin="30" height="300"
  22. mode="rect"></u-swiper>
  23. </view>
  24. <view>
  25. <view class="rowClass">
  26. <u-row justify="center">
  27. <u-col v-for="(item,index) in navList" :key="index" span="3" text-align="center">
  28. <view class="u-padding-top-20" @tap="clickNav">
  29. <image :src="item.src" class="main-icon" mode="widthFix"></image>
  30. <view class="tabName">{{ item.name }}</view>
  31. </view>
  32. </u-col>
  33. </u-row>
  34. </view>
  35. <u-gap height="10"></u-gap>
  36. <view class="firstCate">
  37. <image :src="advertImg" mode="widthFix" style="width: 700rpx;"></image>
  38. </view>
  39. <u-gap height="15"></u-gap>
  40. <view v-show="!loading" class="hotCate">
  41. <view class="left">
  42. <image :src="hotImg" mode="widthFix" style="width: 100rpx;max-width: 100rpx;"></image>
  43. <view class="text">
  44. <view class="title">热门推荐</view>
  45. <view class="desc">Popular Recommendation</view>
  46. </view>
  47. </view>
  48. <view class="right">
  49. <u-icon color="#ddd" name="arrow-right" size="40"></u-icon>
  50. </view>
  51. </view>
  52. <u-gap height="20"></u-gap>
  53. <u-waterfall ref="uWaterfall" v-model="flowList">
  54. <template v-slot:left="{leftList}">
  55. <view v-for="(item, index) in leftList" :key="index" class="demo-warter">
  56. <u-lazy-load :image="item.image" :index="index" border-radius="12" threshold="750"
  57. @click="clickImage(item.id)"></u-lazy-load>
  58. <view class="item-title">{{ item.goodsName }}</view>
  59. <view class="item-bottom">
  60. <view class="item-price">
  61. <view class="new-price">¥{{ item.newPrice }}</view>
  62. <view class="old-price">¥{{ item.oldPrice }}</view>
  63. </view>
  64. <view class="right">
  65. 免邮费
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <template v-slot:right="{rightList}">
  71. <view v-for="(item, index) in rightList" :key="index" class="demo-warter">
  72. <u-lazy-load :image="item.image" :index="index" border-radius="10" threshold="750"
  73. @click="clickImage(item.id)"></u-lazy-load>
  74. <view class="item-title">{{ item.goodsName }}</view>
  75. <view class="item-bottom">
  76. <view class="item-price">
  77. <view class="new-price">¥{{ item.newPrice }}</view>
  78. <view class="old-price">¥{{ item.oldPrice }}</view>
  79. </view>
  80. <view class="right">
  81. 免邮费
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. </u-waterfall>
  87. </view>
  88. <u-loadmore v-show="!loading" :status="loadStatus" bg-color="rgb(250, 250, 250)" style="padding:10rpx 0;"
  89. @loadmore="findGoodsList"></u-loadmore>
  90. <u-back-top :scroll-top="scrollTop" top="5000"></u-back-top>
  91. <u-no-network></u-no-network>
  92. </view>
  93. </template>
  94. <script>
  95. import config from "@/common/config.js" // 全局配置文件
  96. export default {
  97. data() {
  98. return {
  99. keyword: '',
  100. loading: true,
  101. pageNum: 1,
  102. pageSize: 20,
  103. scrollTop: 0,
  104. swiperList: [],
  105. navList: [],
  106. advertImg: null,
  107. hotImg: null,
  108. loadStatus: 'loadmore',
  109. flowList: [],
  110. uvCode: uni.getStorageSync('uvCode')
  111. }
  112. },
  113. onLoad() {
  114. // 移除tab badge
  115. uni.removeTabBarBadge({
  116. index: 2
  117. })
  118. // 获取数据
  119. this.findMallIndexList();
  120. },
  121. onShow() {
  122. // 流量统计
  123. this.appSysFlowInfo()
  124. },
  125. onPageScroll(e) {
  126. this.scrollTop = e.scrollTop;
  127. },
  128. onReachBottom() {
  129. this.loadStatus = 'loading';
  130. // 获取数据
  131. this.findGoodsList()
  132. },
  133. // 下拉刷新
  134. onPullDownRefresh() {
  135. // 获取数据
  136. this.pageNum = 1
  137. this.flowList = []
  138. this.$refs.uWaterfall.clear();
  139. this.findGoodsList();
  140. // 关闭刷新
  141. uni.stopPullDownRefresh();
  142. },
  143. methods: {
  144. search() {
  145. this.$u.route({
  146. url: 'pages/search/search',
  147. })
  148. },
  149. notice() {
  150. this.$u.route({
  151. url: 'pages/notice/notice'
  152. })
  153. },
  154. findMallIndexList() {
  155. this.loading = true
  156. let url = "/api/mallApi/findMallIndexList";
  157. this.$u.get(url, {
  158. pageNum: this.pageNum,
  159. pageSize: this.pageSize,
  160. orderByColumn: 'create_time',
  161. isAsc: 'desc'
  162. }).then(result => {
  163. const data = result.data;
  164. // 轮播
  165. const advertList = data.advertList;
  166. for (let i = 0; i < advertList.length; i++) {
  167. let item = advertList[i]
  168. if (item.advertType === 0) {
  169. item.title = item.advertName
  170. item.image = config.staticUrl + item.advertUrl
  171. this.swiperList.push(item);
  172. }
  173. if (item.advertType === 1) {
  174. this.advertImg = config.staticUrl + item.advertUrl
  175. }
  176. if (item.advertType === 2) {
  177. this.hotImg = config.staticUrl + item.advertUrl
  178. }
  179. }
  180. // 导航栏
  181. const navigateList = data.navigateList;
  182. for (let i = 0; i < navigateList.length; i++) {
  183. let item = navigateList[i]
  184. item.name = item.navigateName
  185. item.src = config.staticUrl + item.navigateUrl
  186. this.navList.push(item);
  187. }
  188. // 商品数据
  189. const goodsList = data.goodsList;
  190. if (this.pageNum > 1 && goodsList.length < this.pageSize) {
  191. return this.loadStatus = 'nomore';
  192. }
  193. for (let i = 0; i < goodsList.length; i++) {
  194. let item = goodsList[i]
  195. item.image = config.staticUrl + item.goodsFaceUrl
  196. this.flowList.push(item);
  197. }
  198. ++this.pageNum
  199. this.loadStatus = 'loadmore';
  200. this.loading = false
  201. });
  202. },
  203. findGoodsList() {
  204. let url = "/api/mallApi/findGoodsList";
  205. this.$u.get(url, {
  206. pageNum: this.pageNum,
  207. pageSize: this.pageSize,
  208. orderByColumn: 'create_time',
  209. isAsc: 'desc'
  210. }).then(result => {
  211. // 商品数据
  212. const goodsList = result.rows;
  213. if (this.pageNum > 1 && goodsList.length < this.pageSize) {
  214. return this.loadStatus = 'nomore';
  215. }
  216. for (let i = 0; i < goodsList.length; i++) {
  217. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  218. let item = goodsList[i]
  219. item.image = config.staticUrl + item.goodsFaceUrl
  220. this.flowList.push(item);
  221. }
  222. ++this.pageNum
  223. this.loadStatus = 'loadmore';
  224. });
  225. },
  226. clickSearch() {
  227. this.$u.route('/pages/search/search');
  228. },
  229. clickImage(goodsId) {
  230. this.$u.route({
  231. url: '/pages/detail/detail',
  232. params: {
  233. goodsId: goodsId
  234. }
  235. })
  236. },
  237. clickNav() {
  238. this.$u.route('/pages/search/searchList');
  239. },
  240. code() {
  241. this.$mytip.toast('请咨询作者')
  242. },
  243. appSysFlowInfo() {
  244. // 流量统计
  245. let uvCode = uni.getStorageSync("uvCode");
  246. let url = "https://sourcebyte.cn/api/flow/upFlow?type=APP&uvCode=" + uvCode;
  247. uni.request({
  248. url: url,
  249. method: "POST",
  250. success: (res) => {
  251. uni.setStorageSync("uvCode", res.data.data);
  252. },
  253. });
  254. },
  255. server() {
  256. window.open('https://sourcebyte.cn')
  257. },
  258. notice() {
  259. this.$u.route('/pages/notice/notice');
  260. },
  261. }
  262. }
  263. </script>
  264. <style>
  265. page {
  266. background-color: #fff;
  267. }
  268. </style>
  269. <style lang="scss" scoped>
  270. .nomore {
  271. background-color: $u-bg-color;
  272. }
  273. .search {
  274. width: 54px;
  275. height: 44px;
  276. &:active {
  277. background-color: $u-bg-color;
  278. }
  279. }
  280. .rowClass {
  281. margin-top: 10 rpx;
  282. }
  283. .firstCate {
  284. text-align: center;
  285. }
  286. .hotCate {
  287. display: flex;
  288. justify-content: space-between;
  289. align-items: center;
  290. padding-left: 10 rpx;
  291. .left {
  292. display: flex;
  293. align-items: center;
  294. .text {
  295. padding-left: 10 rpx;
  296. .title {
  297. font-size: 32 rpx;
  298. color: $u-main-color;
  299. font-weight: 800;
  300. }
  301. .desc {
  302. font-weight: normal;
  303. font-size: 22 rpx;
  304. color: $u-tips-color;
  305. }
  306. }
  307. }
  308. .right {
  309. padding-right: 10 rpx;
  310. }
  311. }
  312. .tabName {
  313. font-size: 22 rpx;
  314. color: $u-main-color;
  315. }
  316. .demo-warter {
  317. border-radius: 8px;
  318. margin-top: 3px;
  319. background-color: $u-bg-color;
  320. padding: 3px;
  321. position: relative;
  322. box-shadow: 4 rpx 0 10 rpx rgba(0, 0, 0, .06);
  323. }
  324. .item-title {
  325. font-size: 28 rpx;
  326. color: $u-main-color;
  327. font-weight: bold;
  328. padding-top: 10 rpx;
  329. padding-left: 10 rpx;
  330. background-color: #fff;
  331. }
  332. .item-bottom {
  333. background-color: #fff;
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. .item-price {
  338. display: flex;
  339. align-items: center;
  340. width: 220 rpx;
  341. max-width: 220 rpx;
  342. text-overflow: ellipsis;
  343. overflow: hidden;
  344. white-space: nowrap;
  345. .new-price {
  346. font-weight: normal;
  347. font-size: 16px;
  348. color: $base-color;
  349. padding: 5px 0 5px 2px;
  350. }
  351. .old-price {
  352. font-weight: normal;
  353. font-size: 13px;
  354. text-decoration: line-through;
  355. color: $u-tips-color;
  356. padding: 5px 0 5px 5px;
  357. }
  358. }
  359. .right {
  360. color: #fff;
  361. background-image: linear-gradient(to left, rgba(#ff536f, 1), rgba(#ff536f, 0.6));
  362. padding: 2 rpx 12 rpx;
  363. border-radius: 30 rpx;
  364. margin-right: 5 rpx;
  365. }
  366. }
  367. .item-desc {
  368. font-weight: normal;
  369. font-size: 26 rpx;
  370. color: $u-tips-color;
  371. padding-bottom: 5 rpx;
  372. padding-left: 10 rpx;
  373. background-color: #fff;
  374. }
  375. </style>