category.vue 14 KB

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