category.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view class="container">
  3. <view class="cate-nav">
  4. <scroll-view :scroll-x="true" class="cate-nav-body" :scroll-left="scrollLeft">
  5. <view :class="'item ' + (id == item.id ? 'active' : '')" :data-id="item.id" :data-index="index" @tap="switchCate" v-for="(item, index) in navList" :key="index">
  6. <view class="name">{{ item.name }}</view>
  7. </view>
  8. </scroll-view>
  9. </view>
  10. <scroll-view :scroll-y="true" :scroll-top="scrollTop" :style="'height:' + scrollHeight + ';'">
  11. <view class="cate-item">
  12. <view class="b">
  13. <navigator
  14. :class="'item ' + ((iindex + 1) % 2 == 0 ? 'item-b' : '')"
  15. :url="'/pages/goods/goods?id=' + iitem.id"
  16. v-for="(iitem, iindex) in goodsList"
  17. :key="iindex"
  18. >
  19. <image class="img" :src="iitem.picUrl" background-size="cover"></image>
  20. <view style="display: flex; margin-top: 10rpx; height: 71rpx">
  21. <text class="name">{{ iitem.name }}</text>
  22. </view>
  23. <view class="price">
  24. <view v-if="iitem.activited" class="retailPrice">
  25. <text class="price-unit">¥</text>
  26. {{ iitem.activityPrice }}
  27. </view>
  28. <view v-else class="retailPrice">
  29. <text class="price-unit">¥</text>
  30. {{ iitem.retailPrice }}
  31. </view>
  32. <view v-if="iitem.activited || iitem.counterPrice != iitem.retailPrice" class="counterPrice">原价¥{{ iitem.counterPrice }}</view>
  33. </view>
  34. </navigator>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </template>
  40. <script>
  41. var util = require('../../utils/util.js');
  42. var api = require('../../config/api.js');
  43. const app = getApp();
  44. export default {
  45. data() {
  46. return {
  47. navList: [],
  48. goodsList: [],
  49. id: 0,
  50. navIndex: 0,
  51. attribute: '',
  52. currentCategory: {},
  53. scrollLeft: 0,
  54. scrollTop: 0,
  55. scrollHeight: 0,
  56. page: 1,
  57. limit: 10,
  58. totalPages: 1,
  59. addressInfo: {},
  60. iindex: 0,
  61. iitem: {
  62. id: '',
  63. picUrl: '',
  64. name: '',
  65. activited: '',
  66. counterPrice: '',
  67. retailPrice: ''
  68. }
  69. };
  70. },
  71. onLoad: function (options) {
  72. // 页面初始化 options为页面跳转所带来的参数
  73. console.log(options);
  74. var that = this;
  75. if (options.id) {
  76. that.setData({
  77. id: parseInt(options.id)
  78. });
  79. }
  80. if (options.attribute) {
  81. that.setData({
  82. attribute: parseInt(options.attribute)
  83. });
  84. }
  85. uni.getSystemInfo({
  86. success: function (res) {
  87. that.setData({
  88. scrollHeight: res.windowHeight
  89. });
  90. }
  91. });
  92. var addressInfo = uni.getStorageSync('addressInfo');
  93. if (addressInfo) {
  94. this.setData({
  95. addressInfo: addressInfo
  96. });
  97. }
  98. this.getCategoryInfo();
  99. },
  100. onReady: function () {
  101. // 页面渲染完成
  102. },
  103. onShow: function () {
  104. // 页面显示
  105. },
  106. onHide: function () {
  107. // 页面隐藏
  108. },
  109. onUnload: function () {
  110. // 页面关闭
  111. },
  112. onReachBottom() {
  113. if (this.totalPages > this.page) {
  114. this.setData({
  115. page: this.page + 1
  116. });
  117. this.getGoodsList();
  118. } else {
  119. uni.showToast({
  120. title: '没有更多商品了',
  121. icon: 'none',
  122. duration: 2000
  123. });
  124. return false;
  125. }
  126. },
  127. methods: {
  128. getCategoryInfo: function () {
  129. console.info('getCategoryInfo');
  130. let that = this;
  131. util.request(api.GoodsCategory, {
  132. id: this.attribute ? '-1' : this.id,
  133. attribute: this.attribute,
  134. shopId: this.addressInfo.shopId,
  135. city: this.addressInfo.city
  136. }).then((res) => {
  137. if (res.errno == 0) {
  138. that.setData({
  139. navList: res.data.brotherCategory,
  140. currentCategory: res.data.currentCategory
  141. });
  142. // 当id是L1分类id时,这里需要重新设置成L1分类的一个子分类的id
  143. // 周期服务包特殊处理
  144. if (this.attribute == '3' || this.attribute == '2') {
  145. uni.setNavigationBarTitle({
  146. title: res.data.currentCategory.name
  147. });
  148. that.setData({
  149. id: res.data.currentCategory.id
  150. });
  151. } else {
  152. uni.setNavigationBarTitle({
  153. title: res.data.parentCategory.name
  154. });
  155. if (res.data.parentCategory.id == that.id) {
  156. that.setData({
  157. id: res.data.currentCategory.id
  158. });
  159. }
  160. }
  161. //nav位置
  162. let currentIndex = 0;
  163. let navListCount = that.navList.length;
  164. for (let i = 0; i < navListCount; i++) {
  165. currentIndex += 1;
  166. if (that.navList[i].id == that.id) {
  167. break;
  168. }
  169. }
  170. if (currentIndex > navListCount / 2 && navListCount > 5) {
  171. that.setData({
  172. scrollLeft: currentIndex * 70
  173. });
  174. }
  175. that.getGoodsList();
  176. } else {
  177. //显示错误信息
  178. }
  179. });
  180. },
  181. getGoodsList: function () {
  182. var that = this;
  183. util.request(api.GoodsList, {
  184. categoryId: this.attribute == '3' ? '-1' : that.id,
  185. attribute: this.attribute == '3' ? '3' : '',
  186. page: that.page,
  187. limit: that.limit,
  188. city: that.addressInfo.city,
  189. shopId: that.addressInfo.shopId
  190. }).then(function (res) {
  191. console.info(res);
  192. console.info(that.page);
  193. if (that.page == 1) {
  194. that.setData({
  195. goodsList: res.data.list,
  196. totalPages: res.data.pages
  197. });
  198. } else {
  199. that.setData({
  200. goodsList: that.goodsList.concat(res.data.list),
  201. totalPages: res.data.pages
  202. });
  203. }
  204. console.info(that.goodsList);
  205. });
  206. },
  207. switchCate: function (event) {
  208. if (this.id == event.currentTarget.dataset.id) {
  209. return false;
  210. }
  211. var that = this;
  212. var clientX = event.detail.x;
  213. var currentTarget = event.currentTarget;
  214. if (clientX < 60) {
  215. that.setData({
  216. scrollLeft: currentTarget.offsetLeft - 60
  217. });
  218. } else if (clientX > 330) {
  219. that.setData({
  220. scrollLeft: currentTarget.offsetLeft
  221. });
  222. }
  223. this.setData({
  224. id: event.currentTarget.dataset.id,
  225. navIndex: event.currentTarget.dataset.index,
  226. page: 1
  227. });
  228. this.getGoodsList();
  229. }
  230. }
  231. };
  232. </script>
  233. <style>
  234. .container {
  235. background: linear-gradient(180deg, #09afff 10%, #f8f8f8 40%);
  236. height: 100vh;
  237. }
  238. page {
  239. background: #f8f8f8;
  240. }
  241. .cate-nav {
  242. width: 690rpx;
  243. padding: 20rpx 0 0;
  244. margin: 0 30rpx 0;
  245. }
  246. .cate-nav-body {
  247. height: 104rpx;
  248. margin: 0 14rpx;
  249. width: 660rpx;
  250. overflow-x: scroll;
  251. white-space: nowrap;
  252. background: url('https://mall.zhaijieshi.cc/file/wx-dy/category-bg.png') no-repeat center bottom;
  253. background-size: 660rpx 104rpx;
  254. }
  255. .cate-nav .item {
  256. display: inline-block;
  257. height: 84rpx;
  258. min-width: 130rpx;
  259. }
  260. .cate-nav .item .name {
  261. display: block;
  262. height: 84rpx;
  263. line-height: 84rpx;
  264. color: #333;
  265. font-size: 30rpx;
  266. width: auto;
  267. }
  268. .cate-nav .item.active .name {
  269. color: #09afff;
  270. }
  271. .cate-item {
  272. margin: 0rpx 30rpx 0;
  273. height: auto;
  274. overflow: hidden;
  275. width: 690rpx;
  276. background: #fff;
  277. height: 100vh;
  278. border-radius: 20rpx 20rpx 0 0;
  279. padding-left: 10rpx;
  280. }
  281. .cate-item .h {
  282. height: 145rpx;
  283. width: 750rpx;
  284. display: flex;
  285. flex-direction: column;
  286. align-items: center;
  287. justify-content: center;
  288. }
  289. .cate-item .h .name {
  290. display: block;
  291. height: 35rpx;
  292. margin-bottom: 18rpx;
  293. font-size: 30rpx;
  294. color: #333;
  295. }
  296. .cate-item .h .desc {
  297. display: block;
  298. height: 24rpx;
  299. font-size: 24rpx;
  300. color: #999;
  301. }
  302. .cate-item .b .item {
  303. float: left;
  304. background: #fff;
  305. width: 306rpx;
  306. height: auto;
  307. overflow: hidden;
  308. padding: 16rpx;
  309. border-radius: 15rpx;
  310. margin: 16.5rpx 16.5rpx 8.5rpx 16.5rpx;
  311. border: 2rpx solid #00c0ff;
  312. border-radius: 20rpx;
  313. }
  314. .cate-item .b .item-b {
  315. margin-left: 6.25rpx;
  316. }
  317. .cate-item .item .img {
  318. width: 274rpx;
  319. height: 274rpx;
  320. background: #e0e0e0;
  321. border-radius: 15rpx;
  322. }
  323. .cate-item .b .item .mark {
  324. width: 122rpx;
  325. height: 100rpx;
  326. margin-top: -20rpx;
  327. margin-left: 0rpx;
  328. }
  329. .cate-item .item .name {
  330. display: block;
  331. width: 274rpx;
  332. margin: 0 0 5rpx 0;
  333. overflow: hidden;
  334. padding: 0 20rpx;
  335. font-size: 26rpx;
  336. color: #1c1c1c;
  337. line-height: 1.3em;
  338. padding-left: 0rpx;
  339. }
  340. .price-unit {
  341. font-size: 23rpx;
  342. font-weight: 400;
  343. color: #202020;
  344. }
  345. .cate-item .item .brand {
  346. display: block;
  347. width: 365.625rpx;
  348. height: 22rpx;
  349. font-size: 22rpx;
  350. color: #ab956d;
  351. margin-top: 10rpx;
  352. margin-left: 22rpx;
  353. }
  354. .counterPrice {
  355. text-decoration: line-through;
  356. font-size: 24rpx;
  357. margin: 0 0 0 20rpx;
  358. color: #c7c7c7;
  359. }
  360. .cate-item .item .price {
  361. height: 40rpx;
  362. display: flex;
  363. margin-top: 10rpx;
  364. align-items: flex-end;
  365. }
  366. .retailPrice {
  367. font-size: 40rpx;
  368. height: 40rpx;
  369. line-height: 40rpx;
  370. font-weight: bold;
  371. color: #202020;
  372. }
  373. .memberPrice {
  374. font-size: 22rpx;
  375. color: #dd483e;
  376. margin: 0 10rpx 0 20rpx;
  377. }
  378. .member-price-tag {
  379. width: 88rpx;
  380. height: 26rpx;
  381. line-height: 26rpx;
  382. background: url('https://mall.zhaijieshi.cc/file/jzmall/weixin/member/member-price-bg.png') no-repeat center center;
  383. background-size: 100% 100%;
  384. color: #5e3a11;
  385. font-size: 16rpx;
  386. padding: 0 8rpx 0 0;
  387. text-align: right;
  388. margin: 0 0 6rpx 0;
  389. }
  390. .cate-nav .item {
  391. padding-top: 20rpx;
  392. height: 104rpx;
  393. }
  394. .cate-nav .item .name {
  395. line-height: 84rpx;
  396. height: 84rpx;
  397. padding: 0 34rpx;
  398. }
  399. .cate-nav .item:first-child .name {
  400. border-radius: 20rpx 0 0 0;
  401. }
  402. .cate-nav .item:last-child .name {
  403. border-radius: 0 20rpx 0 0;
  404. }
  405. .cate-nav .active.item {
  406. padding: 0;
  407. }
  408. .cate-nav .active.item .name {
  409. border-radius: 20rpx 20rpx 0 0;
  410. height: 104rpx;
  411. line-height: 104rpx;
  412. background: #fff;
  413. }
  414. </style>