newGoods.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view class="container">
  3. <view class="brand-info">
  4. <view class="name">
  5. <image class="img" :src="bannerInfo.imgUrl" 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 ' + (currentSortType == 'price' ? 'active' : '')" @tap="openSortFilter" id="priceSort">
  20. <text class="txt">价格</text>
  21. <!-- <van-icon name="arrow-up" v-if="currentSortType == 'price' && currentSortOrder == 'asc'" /> -->
  22. <!-- <van-icon name="arrow-down" v-else-if="currentSortType == 'price' && currentSortOrder == 'desc'" /> -->
  23. </view>
  24. <view :class="'item ' + (currentSortType == 'category' ? 'active' : '')" @tap="openSortFilter" id="categoryFilter">
  25. <text class="txt">分类</text>
  26. </view>
  27. </view>
  28. <view class="sort-box-category" v-if="categoryFilter">
  29. <view :class="'item ' + (item.checked ? 'active' : '')" :data-category-index="index" @tap="selectCategory" v-for="(item, index) in filterCategory" :key="index">
  30. {{ item.name }}
  31. </view>
  32. </view>
  33. </view>
  34. <view class="cate-item">
  35. <view class="b">
  36. <block v-for="(iitem, iindex) in goodsList" :key="iindex">
  37. <navigator :class="'item ' + (iindex % 2 == 0 ? 'item-b' : '')" :url="'../goods/goods?id=' + iitem.id">
  38. <image class="img" :src="iitem.picUrl" background-size="cover"></image>
  39. <text class="name">{{ iitem.name }}</text>
  40. <text class="price">¥{{ iitem.retailPrice }}</text>
  41. </navigator>
  42. </block>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. var util = require('../../../utils/util.js');
  49. var api = require('../../../config/api.js');
  50. var app = getApp();
  51. export default {
  52. data() {
  53. return {
  54. addressInfo: {},
  55. bannerInfo: {
  56. imgUrl: '/static/images/new.png',
  57. name: '大家都在买的'
  58. },
  59. categoryFilter: false,
  60. filterCategory: [],
  61. goodsList: [],
  62. categoryId: 0,
  63. currentSortType: 'default',
  64. currentSort: 'create_time',
  65. currentSortOrder: 'desc',
  66. page: 1,
  67. limit: 10,
  68. iindex: 0,
  69. iitem: {
  70. id: '',
  71. picUrl: '',
  72. name: '',
  73. retailPrice: ''
  74. }
  75. };
  76. },
  77. onLoad: function (options) {
  78. // 页面初始化 options为页面跳转所带来的参数
  79. var addressInfo = uni.getStorageSync('addressInfo');
  80. if (addressInfo) {
  81. this.setData({
  82. addressInfo: addressInfo
  83. });
  84. }
  85. this.getGoodsList();
  86. },
  87. onReady: function () {
  88. // 页面渲染完成
  89. },
  90. onShow: function () {
  91. // 页面显示
  92. },
  93. onHide: function () {
  94. // 页面隐藏
  95. },
  96. onUnload: function () {
  97. // 页面关闭
  98. },
  99. methods: {
  100. getGoodsList: function () {
  101. var that = this;
  102. util.request(api.GoodsList, {
  103. isNew: true,
  104. page: that.page,
  105. limit: that.limit,
  106. order: that.currentSortOrder,
  107. sort: that.currentSort,
  108. categoryId: that.categoryId,
  109. city: that.addressInfo.city,
  110. shopId: that.addressInfo.shopId
  111. }).then(function (res) {
  112. if (res.errno === 0) {
  113. that.setData({
  114. goodsList: res.data.list,
  115. filterCategory: res.data.filterCategoryList
  116. });
  117. }
  118. });
  119. },
  120. openSortFilter: function (event) {
  121. let currentId = event.currentTarget.id;
  122. switch (currentId) {
  123. case 'categoryFilter':
  124. this.setData({
  125. categoryFilter: !this.categoryFilter,
  126. currentSortType: 'category',
  127. currentSort: 'create_time',
  128. currentSortOrder: 'desc'
  129. });
  130. break;
  131. case 'priceSort':
  132. let tmpSortOrder = 'asc';
  133. if (this.currentSortOrder == 'asc') {
  134. tmpSortOrder = 'desc';
  135. }
  136. this.setData({
  137. currentSortType: 'price',
  138. currentSort: 'retail_price',
  139. currentSortOrder: tmpSortOrder,
  140. categoryFilter: false
  141. });
  142. this.getGoodsList();
  143. break;
  144. default:
  145. //综合排序
  146. this.setData({
  147. currentSortType: 'default',
  148. currentSort: 'create_time',
  149. currentSortOrder: 'desc',
  150. categoryFilter: false,
  151. categoryId: 0
  152. });
  153. this.getGoodsList();
  154. }
  155. },
  156. selectCategory: function (event) {
  157. let currentIndex = event.target.dataset.categoryIndex;
  158. this.setData({
  159. categoryFilter: false,
  160. categoryId: this.filterCategory[currentIndex].id
  161. });
  162. this.getGoodsList();
  163. }
  164. }
  165. };
  166. </script>
  167. <style>
  168. page {
  169. background: #f4f4f4;
  170. }
  171. .brand-info .name {
  172. width: 100%;
  173. height: 278rpx;
  174. position: relative;
  175. }
  176. .brand-info .img {
  177. position: absolute;
  178. top: 0;
  179. left: 0;
  180. width: 100%;
  181. height: 278rpx;
  182. }
  183. .brand-info .info-box {
  184. position: absolute;
  185. top: 0;
  186. left: 0;
  187. width: 100%;
  188. height: 278rpx;
  189. text-align: center;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. }
  194. .brand-info .info {
  195. display: block;
  196. }
  197. .brand-info .txt {
  198. display: block;
  199. height: 40rpx;
  200. font-size: 37.5rpx;
  201. color: #fff;
  202. }
  203. .brand-info .line {
  204. margin: 0 auto;
  205. margin-top: 16rpx;
  206. display: block;
  207. height: 2rpx;
  208. width: 145rpx;
  209. background: #fff;
  210. }
  211. .sort {
  212. position: relative;
  213. background: #fff;
  214. width: 100%;
  215. height: 78rpx;
  216. }
  217. .sort-box {
  218. background: #fff;
  219. width: 100%;
  220. height: 78rpx;
  221. overflow: hidden;
  222. padding: 0 30rpx;
  223. display: flex;
  224. border-bottom: 1px solid #d9d9d9;
  225. }
  226. .sort-box .item {
  227. height: 78rpx;
  228. line-height: 78rpx;
  229. text-align: center;
  230. flex: 1;
  231. color: #333;
  232. font-size: 30rpx;
  233. }
  234. .sort-box .item .txt {
  235. color: #333;
  236. }
  237. .sort-box .item.active .txt {
  238. color: #b4282d;
  239. }
  240. .sort-box .item .van-icon {
  241. margin-left: 6rpx;
  242. }
  243. .sort-box-category {
  244. background: #fff;
  245. width: 100%;
  246. height: auto;
  247. overflow: hidden;
  248. padding: 40rpx 40rpx 0 0;
  249. border-bottom: 1px solid #d9d9d9;
  250. }
  251. .sort-box-category .item {
  252. height: 54rpx;
  253. line-height: 54rpx;
  254. text-align: center;
  255. float: left;
  256. padding: 0 16rpx;
  257. margin: 0 0 40rpx 40rpx;
  258. border: 1px solid #666;
  259. color: #333;
  260. font-size: 24rpx;
  261. }
  262. .sort-box-category .item.active {
  263. color: #b4282d;
  264. border: 1px solid #b4282d;
  265. }
  266. .cate-item .b {
  267. width: 750rpx;
  268. height: auto;
  269. overflow: hidden;
  270. border-top: 1rpx solid #f4f4f4;
  271. margin-top: 20rpx;
  272. }
  273. .cate-item .b .item {
  274. float: left;
  275. background: #fff;
  276. width: 375rpx;
  277. padding-bottom: 33.333rpx;
  278. border-bottom: 1rpx solid #f4f4f4;
  279. height: auto;
  280. overflow: hidden;
  281. text-align: center;
  282. }
  283. .cate-item .b .item-b {
  284. border-right: 1rpx solid #f4f4f4;
  285. }
  286. .cate-item .item .img {
  287. margin-top: 10rpx;
  288. width: 302rpx;
  289. height: 302rpx;
  290. }
  291. .cate-item .item .name {
  292. display: block;
  293. width: 365.625rpx;
  294. height: 35rpx;
  295. padding: 0 20rpx;
  296. overflow: hidden;
  297. margin: 11.5rpx 0 22rpx 0;
  298. text-align: center;
  299. font-size: 30rpx;
  300. color: #333;
  301. }
  302. .cate-item .item .price {
  303. display: block;
  304. width: 365.625rpx;
  305. height: 30rpx;
  306. text-align: center;
  307. font-size: 30rpx;
  308. color: #b4282d;
  309. }
  310. </style>