category.vue 12 KB

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