hotGoods.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <view class="container">
  3. <view class="brand-info">
  4. <view class="name">
  5. <image class="img" :src="bannerInfo.imgUrl" mode="widthFix"></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="'/pages/goods/goods?id=' + iitem.id">
  38. <image class="img" :src="iitem.picUrl" background-size="cover"></image>
  39. <!-- <text class="name">{{iitem.name}}</text> -->
  40. <view style="display: flex; margin-top: 10rpx; height: 71rpx">
  41. <!-- <image wx:if="{{iitem.activited}}"
  42. src="https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/activity/618.png"
  43. style="width: 39px;height:16px;margin-right: 2px;" /> -->
  44. <text class="name">{{ iitem.name }}</text>
  45. </view>
  46. <view class="price">
  47. <!-- <view class="retailPrice">¥{{iitem.retailPrice}}</view>
  48. <view class="memberPrice">¥{{iitem.memberPrice}}</view>
  49. <view class="member-price-tag">会员价</view> -->
  50. <view v-if="iitem.activited" class="retailPrice">
  51. <text class="price-unit">¥</text>
  52. {{ iitem.activityPrice }}
  53. </view>
  54. <view v-else class="retailPrice">
  55. <text class="price-unit">¥</text>
  56. {{ iitem.retailPrice }}
  57. </view>
  58. <view v-if="iitem.activited || iitem.counterPrice != iitem.retailPrice" class="counterPrice">原价¥{{ iitem.counterPrice }}</view>
  59. </view>
  60. <!-- <view class="price"><text>¥{{iitem.retailPrice}}</text>
  61. <text class="counterPrice sub-color">¥{{iitem.counterPrice}}</text>
  62. </view> -->
  63. </navigator>
  64. </block>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. var util = require('../../../utils/util.js');
  71. var api = require('../../../config/api.js');
  72. var app = getApp();
  73. export default {
  74. data() {
  75. return {
  76. addressInfo: {},
  77. bannerInfo: {
  78. imgUrl: 'https://mall.zhaijieshi.cc/file/jzmall/weixin/new/img-hot.png',
  79. name: '大家都在买的'
  80. },
  81. categoryFilter: false,
  82. filterCategory: [],
  83. goodsList: [],
  84. categoryId: 0,
  85. currentSortType: 'default',
  86. currentSort: 'create_time',
  87. currentSortOrder: 'desc',
  88. page: 1,
  89. limit: 10,
  90. iindex: 0,
  91. iitem: {
  92. id: '',
  93. picUrl: '',
  94. name: '',
  95. activited: '',
  96. counterPrice: '',
  97. retailPrice: ''
  98. }
  99. };
  100. },
  101. onLoad: function (options) {
  102. // 页面初始化 options为页面跳转所带来的参数
  103. var addressInfo = uni.getStorageSync('addressInfo');
  104. if (addressInfo) {
  105. this.setData({
  106. addressInfo: addressInfo
  107. });
  108. }
  109. this.getGoodsList();
  110. },
  111. onReady: function () {
  112. // 页面渲染完成
  113. },
  114. onShow: function () {
  115. // 页面显示
  116. },
  117. onHide: function () {
  118. // 页面隐藏
  119. },
  120. onUnload: function () {
  121. // 页面关闭
  122. },
  123. methods: {
  124. getCategoryList: function () {
  125. var that = this;
  126. util.request(api.GoodsFilter, {
  127. isHot: 1
  128. }).then(function (res) {
  129. if (res.errno === 0) {
  130. that.setData({
  131. filterCategory: res.data.filterCategoryList
  132. });
  133. }
  134. });
  135. },
  136. getGoodsList: function () {
  137. var that = this;
  138. util.request(api.GoodsList, {
  139. isHot: true,
  140. page: that.page,
  141. limit: that.limit,
  142. order: that.currentSortOrder,
  143. sort: that.currentSort,
  144. categoryId: that.categoryId,
  145. city: that.addressInfo.city,
  146. shopId: that.addressInfo.shopId
  147. }).then(function (res) {
  148. console.info(res);
  149. if (res.errno === 0) {
  150. that.setData({
  151. goodsList: res.data.list,
  152. filterCategory: res.data.filterCategoryList
  153. });
  154. }
  155. });
  156. },
  157. openSortFilter: function (event) {
  158. let currentId = event.currentTarget.id;
  159. switch (currentId) {
  160. case 'categoryFilter':
  161. this.setData({
  162. categoryFilter: !this.categoryFilter,
  163. currentSortType: 'category',
  164. currentSort: 'create_time',
  165. currentSortOrder: 'desc'
  166. });
  167. break;
  168. case 'priceSort':
  169. let tmpSortOrder = 'asc';
  170. if (this.currentSortOrder == 'asc') {
  171. tmpSortOrder = 'desc';
  172. }
  173. this.setData({
  174. currentSortType: 'price',
  175. currentSort: 'retail_price',
  176. currentSortOrder: tmpSortOrder,
  177. categoryFilter: false
  178. });
  179. this.getGoodsList();
  180. break;
  181. default:
  182. //综合排序
  183. this.setData({
  184. currentSortType: 'default',
  185. currentSort: 'create_time',
  186. currentSortOrder: 'desc',
  187. categoryFilter: false,
  188. categoryId: 0
  189. });
  190. this.getGoodsList();
  191. }
  192. },
  193. selectCategory: function (event) {
  194. let currentIndex = event.target.dataset.categoryIndex;
  195. this.setData({
  196. categoryFilter: false,
  197. categoryId: this.filterCategory[currentIndex].id
  198. });
  199. this.getGoodsList();
  200. }
  201. }
  202. };
  203. </script>
  204. <style>
  205. page {
  206. background: #f4f4f4;
  207. }
  208. .brand-info .name {
  209. width: 750rpx;
  210. height: 184rpx;
  211. /* position: relative; */
  212. }
  213. .brand-info .img {
  214. /* position: absolute;
  215. top: 0;
  216. left: 0; */
  217. width: 750rpx;
  218. height: 184rpx;
  219. }
  220. .price-unit {
  221. font-size: 23rpx;
  222. font-weight: 400;
  223. color: #202020;
  224. }
  225. .brand-info .info-box {
  226. position: absolute;
  227. top: 0;
  228. left: 0;
  229. width: 100%;
  230. height: 278rpx;
  231. text-align: center;
  232. display: flex;
  233. justify-content: center;
  234. align-items: center;
  235. }
  236. .brand-info .info {
  237. display: block;
  238. }
  239. .brand-info .txt {
  240. display: block;
  241. height: 40rpx;
  242. font-size: 37.5rpx;
  243. /* color: #fff; */
  244. }
  245. .brand-info .line {
  246. margin: 0 auto;
  247. margin-top: 16rpx;
  248. display: block;
  249. height: 2rpx;
  250. width: 145rpx;
  251. background: #fff;
  252. }
  253. .sort {
  254. position: relative;
  255. background: #fff;
  256. width: 100%;
  257. height: 78rpx;
  258. }
  259. .sort-box {
  260. background: #fff;
  261. width: 100%;
  262. height: 78rpx;
  263. overflow: hidden;
  264. padding: 0 30rpx;
  265. display: flex;
  266. align-items: center;
  267. border-bottom: 1px solid #d9d9d9;
  268. }
  269. .sort-box .item {
  270. height: 78rpx;
  271. line-height: 78rpx;
  272. text-align: center;
  273. flex: 1;
  274. color: #333;
  275. font-size: 30rpx;
  276. }
  277. .sort-box .item .txt {
  278. color: #333;
  279. }
  280. .sort-box .item.active .txt {
  281. color: #b4282d;
  282. }
  283. .sort-box .item .van-icon {
  284. margin-left: 6rpx;
  285. }
  286. .sort-box-category {
  287. background: #fff;
  288. width: 100%;
  289. height: auto;
  290. overflow: hidden;
  291. padding: 40rpx 40rpx 0 0;
  292. border-bottom: 1px solid #d9d9d9;
  293. }
  294. .sort-box-category .item {
  295. height: 54rpx;
  296. line-height: 54rpx;
  297. text-align: center;
  298. float: left;
  299. padding: 0 16rpx;
  300. margin: 0 0 40rpx 40rpx;
  301. border: 1px solid #666;
  302. color: #333;
  303. font-size: 24rpx;
  304. }
  305. .sort-box-category .item.active {
  306. color: #b4282d;
  307. border: 1px solid #b4282d;
  308. }
  309. .cate-item .b {
  310. /* width: 750rpx;
  311. height: auto;
  312. overflow: hidden;
  313. border-top: 1rpx solid #f4f4f4;
  314. margin-top: 20rpx; */
  315. width: 750rpx;
  316. /* padding: 0 6.25rpx; */
  317. height: auto;
  318. overflow: hidden;
  319. }
  320. .cate-item .b .item {
  321. /* float: left;
  322. background: #fff;
  323. width: 375rpx;
  324. padding-bottom: 33.333rpx;
  325. border-bottom: 1rpx solid #f4f4f4;
  326. height: auto;
  327. overflow: hidden;
  328. text-align: center; */
  329. float: left;
  330. background: #fff;
  331. width: 342rpx;
  332. height: auto;
  333. overflow: hidden;
  334. padding: 15rpx;
  335. border-radius: 15rpx;
  336. margin: 16.5rpx 16.5rpx 8.5rpx 16.5rpx;
  337. }
  338. .cate-item .b .item-b {
  339. border-right: 1rpx solid #f4f4f4;
  340. }
  341. .cate-item .item .img {
  342. width: 312rpx;
  343. height: 312rpx;
  344. border-radius: 15rpx;
  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. text-align: left;
  358. }
  359. .cate-item .item .price {
  360. height: 40rpx;
  361. /* justify-content: center; */
  362. display: flex;
  363. align-items: flex-end;
  364. justify-content: flex-start;
  365. margin-top: 10rpx;
  366. }
  367. .counterPrice {
  368. text-decoration: line-through;
  369. font-size: 24rpx;
  370. margin: 0 0 0 20rpx;
  371. color: #c7c7c7;
  372. }
  373. .retailPrice {
  374. font-size: 40rpx;
  375. height: 40rpx;
  376. line-height: 40rpx;
  377. font-weight: bold;
  378. color: #202020;
  379. }
  380. .memberPrice {
  381. font-size: 22rpx;
  382. color: #dd483e;
  383. margin: 0 10rpx 0 20rpx;
  384. }
  385. .member-price-tag {
  386. width: 88rpx;
  387. height: 26rpx;
  388. line-height: 26rpx;
  389. background: url('https://mall.zhaijieshi.cc/file/jzmall/weixin/member/member-price-bg.png') no-repeat center center;
  390. background-size: 100% 100%;
  391. color: #5e3a11;
  392. font-size: 16rpx;
  393. padding: 0 8rpx 0 0;
  394. text-align: right;
  395. margin: 0 0 6rpx 0;
  396. }
  397. </style>