category.vue 13 KB

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