catalog.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="container">
  3. <view class="search">
  4. <navigator url="/pages/search/search" class="input">
  5. <image class="icon"></image>
  6. <text class="txt">商品搜索, 共{{goodsCount}}款好物</text>
  7. </navigator>
  8. </view>
  9. <view class="catalog">
  10. <scroll-view class="nav" :scroll-y="true">
  11. <view :class="'item ' + (currentCategory.id == item.id ? 'active' : '')" v-for="(item, index) in navList" :key="index"
  12. :data-id="item.id" :data-index="index" @tap="switchCate">{{item.name}}</view>
  13. </scroll-view>
  14. <scroll-view class="cate" :scroll-y="true">
  15. <navigator url="url" class="banner">
  16. <image class="image" :src="currentCategory.wap_banner_url"></image>
  17. <view class="txt">{{currentCategory.front_name}}</view>
  18. </navigator>
  19. <view class="hd">
  20. <text class="line"></text>
  21. <text class="txt">{{currentCategory.name||''}}分类</text>
  22. </view>
  23. <view class="bd">
  24. <navigator :url="'/pages/category/category?id='+item.id" :class="'item ' + ((index+1) % 3 == 0 ? 'last' : '')" v-for="(item, index) in currentCategory.subCategoryList"
  25. :key="index">
  26. <image class="icon" :src="item.wap_banner_url"></image>
  27. <text class="txt">{{item.name}}</text>
  28. </navigator>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. const util = require("@/utils/util.js");
  36. const api = require('@/utils/api.js');
  37. export default {
  38. data() {
  39. return {
  40. navList: [],
  41. categoryList: [],
  42. currentCategory: {},
  43. scrollLeft: 0,
  44. scrollTop: 0,
  45. goodsCount: 0,
  46. scrollHeight: 0
  47. }
  48. },
  49. methods: {
  50. getCatalog: function() {
  51. //CatalogList
  52. let that = this;
  53. uni.showLoading({
  54. title: '加载中...',
  55. });
  56. util.request(api.CatalogList).then(function(res) {
  57. that.navList = res.data.categoryList
  58. that.currentCategory = res.data.currentCategory
  59. uni.hideLoading();
  60. });
  61. util.request(api.GoodsCount).then(function(res) {
  62. that.goodsCount = res.data.goodsCount
  63. });
  64. },
  65. getCurrentCategory: function(id) {
  66. let that = this;
  67. util.request(api.CatalogCurrent, {
  68. id: id
  69. }).then(function(res) {
  70. that.currentCategory = res.data.currentCategory
  71. });
  72. },
  73. getList: function() {
  74. var that = this;
  75. util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.cat_id)
  76. .then(function(res) {
  77. that.categoryList = res.data
  78. });
  79. },
  80. switchCate: function(event) {
  81. var that = this;
  82. var currentTarget = event.currentTarget;
  83. if (this.currentCategory.id == event.currentTarget.dataset.id) {
  84. return false;
  85. }
  86. this.getCurrentCategory(event.currentTarget.dataset.id);
  87. }
  88. },
  89. onLoad: function() {
  90. this.getCatalog();
  91. }
  92. }
  93. </script>
  94. <style lang="scss">
  95. page {
  96. height: 100%;
  97. }
  98. .container {
  99. background: #f9f9f9;
  100. height: 100%;
  101. width: 100%;
  102. display: flex;
  103. flex-direction: column;
  104. }
  105. .search {
  106. height: 88rpx;
  107. width: 100%;
  108. padding: 0 30rpx;
  109. background: #fff;
  110. display: flex;
  111. align-items: center;
  112. }
  113. .search .input {
  114. width: 690rpx;
  115. height: 56rpx;
  116. background: #ededed;
  117. border-radius: 8rpx;
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. }
  122. .search .icon {
  123. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png) center no-repeat;
  124. background-size: 100%;
  125. width: 28rpx;
  126. height: 28rpx;
  127. }
  128. .search .txt {
  129. height: 42rpx;
  130. line-height: 42rpx;
  131. color: #666;
  132. padding-left: 10rpx;
  133. font-size: 30rpx;
  134. }
  135. .catalog {
  136. flex: 1;
  137. width: 100%;
  138. background: #fff;
  139. display: flex;
  140. border-top: 1px solid #fafafa;
  141. }
  142. .catalog .nav {
  143. width: 162rpx;
  144. height: 100%;
  145. }
  146. .catalog .nav .item {
  147. text-align: center;
  148. line-height: 90rpx;
  149. width: 162rpx;
  150. height: 90rpx;
  151. color: #333;
  152. font-size: 28rpx;
  153. border-left: 6rpx solid #fff;
  154. }
  155. .catalog .nav .item.active {
  156. color: #ab2b2b;
  157. font-size: 36rpx;
  158. border-left: 6rpx solid #ab2b2b;
  159. }
  160. .catalog .cate {
  161. border-left: 1px solid #fafafa;
  162. flex: 1;
  163. height: 100%;
  164. padding: 0 30rpx 0 30rpx;
  165. }
  166. .banner {
  167. display: block;
  168. height: 222rpx;
  169. width: 100%;
  170. position: relative;
  171. }
  172. .banner .image {
  173. position: absolute;
  174. top: 30rpx;
  175. left: 0;
  176. border-radius: 4rpx;
  177. height: 192rpx;
  178. width: 100%;
  179. }
  180. .banner .txt {
  181. position: absolute;
  182. top: 30rpx;
  183. text-align: center;
  184. color: #fff;
  185. font-size: 28rpx;
  186. left: 0;
  187. height: 192rpx;
  188. line-height: 192rpx;
  189. width: 100%;
  190. }
  191. .catalog .hd {
  192. height: 108rpx;
  193. width: 100%;
  194. display: flex;
  195. justify-content: center;
  196. align-items: center;
  197. }
  198. .catalog .hd .txt {
  199. font-size: 24rpx;
  200. text-align: center;
  201. color: #333;
  202. padding: 0 10rpx;
  203. width: auto;
  204. }
  205. .catalog .hd .line {
  206. width: 40rpx;
  207. height: 1px;
  208. background: #d9d9d9;
  209. }
  210. .catalog .bd {
  211. height: auto;
  212. width: 100%;
  213. overflow: hidden;
  214. }
  215. .catalog .bd .item {
  216. display: block;
  217. float: left;
  218. height: 216rpx;
  219. width: 144rpx;
  220. margin-right: 34rpx;
  221. }
  222. .catalog .bd .item.last {
  223. margin-right: 0;
  224. }
  225. .catalog .bd .item .icon {
  226. height: 144rpx;
  227. width: 144rpx;
  228. }
  229. .catalog .bd .item .txt {
  230. display: block;
  231. text-align: center;
  232. font-size: 24rpx;
  233. color: #333;
  234. height: 72rpx;
  235. width: 144rpx;
  236. }
  237. </style>