newGoods.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="container">
  3. <view class="brand-info">
  4. <view class="name">
  5. <image class="img" :src="bannerInfo.img_url" background-size="cover"></image>
  6. <view class="info-box">
  7. <view class="info">
  8. <text class="txt">{{bannerInfo.name||''}}</text>
  9. <text class="line"></text>
  10. </view>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="sort">
  15. <view class="sort-box">
  16. <view :class="'item '+(currentSortType == 'default' ? 'active' : '')" @tap="openSortFilter" id="defaultSort">
  17. <text class="txt">综合</text>
  18. </view>
  19. <view :class="'item by-price '+(currentSortType == 'price' ? 'active' : '') + (currentSortOrder == 'asc' ? ' asc' : ' desc')"
  20. @tap="openSortFilter" id="priceSort">
  21. <text class="txt">价格</text>
  22. </view>
  23. <view :class="'item '+(currentSortType == 'category' ? 'active' : '')" @tap="openSortFilter" id="categoryFilter">
  24. <text class="txt">分类</text>
  25. </view>
  26. </view>
  27. <view class="sort-box-category" v-if="categoryFilter">
  28. <view :class="'item '+(item.checked ? 'active' : '')" v-for="(item, index) in filterCategory" :key="item.id"
  29. :data-category-index="index" @tap="selectCategory">{{item.name}}</view>
  30. </view>
  31. </view>
  32. <view class="cate-item">
  33. <view class="b">
  34. <block v-for="(iitem, iindex) in goodsList" :key="iindex">
  35. <navigator :class="'item '+(iindex % 2 == 0 ? 'item-b' : '')" :url="'../goods/goods?id='+iitem.id">
  36. <image class="img" :src="iitem.list_pic_url" background-size="cover"></image>
  37. <text class="name">{{iitem.name||''}}</text>
  38. <text class="price">¥{{iitem.retail_price||''}}</text>
  39. </navigator>
  40. </block>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. const api = require('@/utils/api.js');
  47. const util = require("@/utils/util.js");
  48. export default {
  49. data() {
  50. return {
  51. bannerInfo: {
  52. 'img_url': '',
  53. 'name': ''
  54. },
  55. categoryFilter: false,
  56. filterCategory: [],
  57. goodsList: [],
  58. categoryId: 0,
  59. currentSortType: 'default',
  60. currentSortOrder: 'desc',
  61. page: 1,
  62. size: 1000
  63. }
  64. },
  65. methods: {
  66. getData: function() {
  67. let that = this;
  68. util.request(api.GoodsNew).then(function(res) {
  69. if (res.errno === 0) {
  70. that.bannerInfo = res.data.bannerInfo;
  71. that.getGoodsList();
  72. }
  73. });
  74. },
  75. getGoodsList() {
  76. var that = this;
  77. util.request(api.GoodsList, {
  78. isNew: 1,
  79. page: that.page,
  80. size: that.size,
  81. order: that.currentSortOrder,
  82. sort: that.currentSortType,
  83. categoryId: that.categoryId
  84. }).then(function(res) {
  85. if (res.errno === 0) {
  86. that.goodsList = res.data.goodsList
  87. that.filterCategory = res.data.filterCategory
  88. }
  89. });
  90. },
  91. openSortFilter: function(event) {
  92. let currentId = event.currentTarget.id;
  93. var that = this;
  94. switch (currentId) {
  95. case 'categoryFilter':
  96. that.categoryFilter = !that.categoryFilter
  97. that.currentSortType = 'category'
  98. that.currentSortOrder = 'asc'
  99. break;
  100. case 'priceSort':
  101. let tmpSortOrder = 'asc';
  102. if (that.currentSortOrder == 'asc') {
  103. tmpSortOrder = 'desc';
  104. }
  105. that.currentSortType = 'price'
  106. that.currentSortOrder = tmpSortOrder
  107. that.categoryFilter = false
  108. that.getData();
  109. break;
  110. default:
  111. //综合排序
  112. that.currentSortType = 'default'
  113. that.currentSortOrder = 'desc'
  114. that.categoryFilter = false
  115. that.getData();
  116. }
  117. },
  118. selectCategory: function(event) {
  119. var that = this;
  120. let currentIndex = event.target.dataset.categoryIndex;
  121. that.categoryFilter = false
  122. that.categoryId = that.filterCategory[currentIndex].id
  123. that.getData();
  124. }
  125. },
  126. onLoad: function() {
  127. this.getData();
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. page {
  133. background: #f4f4f4;
  134. }
  135. .brand-info .name {
  136. width: 100%;
  137. height: 278rpx;
  138. position: relative;
  139. }
  140. .brand-info .img {
  141. position: absolute;
  142. top: 0;
  143. left: 0;
  144. width: 100%;
  145. height: 278rpx;
  146. }
  147. .brand-info .info-box {
  148. position: absolute;
  149. top: 0;
  150. left: 0;
  151. width: 100%;
  152. height: 278rpx;
  153. text-align: center;
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. }
  158. .brand-info .info {
  159. display: block;
  160. }
  161. .brand-info .txt {
  162. display: block;
  163. height: 40rpx;
  164. font-size: 37.5rpx;
  165. color: #fff;
  166. }
  167. .brand-info .line {
  168. margin: 0 auto;
  169. margin-top: 16rpx;
  170. display: block;
  171. height: 2rpx;
  172. width: 145rpx;
  173. background: #fff;
  174. }
  175. .sort {
  176. position: relative;
  177. background: #fff;
  178. width: 100%;
  179. height: 78rpx;
  180. }
  181. .sort-box {
  182. background: #fff;
  183. width: 100%;
  184. height: 78rpx;
  185. overflow: hidden;
  186. padding: 0 30rpx;
  187. display: flex;
  188. border-bottom: 1px solid #d9d9d9;
  189. }
  190. .sort-box .item {
  191. height: 78rpx;
  192. line-height: 78rpx;
  193. text-align: center;
  194. flex: 1;
  195. color: #333;
  196. font-size: 30rpx;
  197. }
  198. .sort-box .item .txt {
  199. display: block;
  200. width: 100%;
  201. height: 100%;
  202. color: #333;
  203. }
  204. .sort-box .item.active .txt {
  205. color: #b4282d;
  206. }
  207. .sort-box .item.by-price {
  208. background: url(//yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/no-3127092a69.png) 155rpx center no-repeat;
  209. background-size: 15rpx 21rpx;
  210. }
  211. .sort-box .item.by-price.active.asc {
  212. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/up-636b92c0a5.png) 155rpx center no-repeat;
  213. background-size: 15rpx 21rpx;
  214. }
  215. .sort-box .item.by-price.active.desc {
  216. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/down-95e035f3e5.png) 155rpx center no-repeat;
  217. background-size: 15rpx 21rpx;
  218. }
  219. .sort-box-category {
  220. background: #fff;
  221. width: 100%;
  222. height: auto;
  223. overflow: hidden;
  224. padding: 40rpx 40rpx 0 0;
  225. border-bottom: 1px solid #d9d9d9;
  226. }
  227. .sort-box-category .item {
  228. height: 54rpx;
  229. line-height: 54rpx;
  230. text-align: center;
  231. float: left;
  232. padding: 0 16rpx;
  233. margin: 0 0 40rpx 40rpx;
  234. border: 1px solid #666;
  235. color: #333;
  236. font-size: 24rpx;
  237. }
  238. .sort-box-category .item.active {
  239. color: #b4282d;
  240. border: 1px solid #b4282d;
  241. }
  242. .cate-item .b {
  243. width: 750rpx;
  244. height: auto;
  245. overflow: hidden;
  246. border-top: 1rpx solid #f4f4f4;
  247. margin-top: 20rpx;
  248. }
  249. .cate-item .b .item {
  250. float: left;
  251. background: #fff;
  252. width: 375rpx;
  253. padding-bottom: 33.333rpx;
  254. border-bottom: 1rpx solid #f4f4f4;
  255. height: auto;
  256. overflow: hidden;
  257. text-align: center;
  258. }
  259. .cate-item .b .item-b {
  260. border-right: 1rpx solid #f4f4f4;
  261. }
  262. .cate-item .item .img {
  263. margin-top: 10rpx;
  264. width: 302rpx;
  265. height: 302rpx;
  266. }
  267. .cate-item .item .name {
  268. display: block;
  269. width: 365.625rpx;
  270. height: 35rpx;
  271. padding: 0 20rpx;
  272. overflow: hidden;
  273. margin: 11.5rpx 0 22rpx 0;
  274. text-align: center;
  275. font-size: 30rpx;
  276. color: #333;
  277. }
  278. .cate-item .item .price {
  279. display: block;
  280. width: 365.625rpx;
  281. height: 30rpx;
  282. text-align: center;
  283. font-size: 30rpx;
  284. color: #b4282d;
  285. }
  286. </style>