shopDetails.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <template>
  2. <scroll-view id="shopBox" class="container" scroll-y="true" @scrolltolower="handleLoadMore">
  3. <view class="shop-bg"></view>
  4. <view class="shop-info">
  5. <view class="shop-icon">
  6. <image class="shop-logo" :src="shopData.logo"></image>
  7. </view>
  8. <view class="shop-name">{{shopData.name}}</view>
  9. <view class="shop-sell">已售商品{{shopData.soldCount}}</view>
  10. </view>
  11. <view class="shop-image">
  12. <swiper class="swiper" :style="{height: (swiperHeight/2)+'px'}" :indicator-dots="false" :autoplay="true" :interval="3000" :duration="500">
  13. <swiper-item v-for="(item,index) in shopData.storeImgUrl" :key="index">
  14. <image :src="item" mode="aspectFill" style="width: 100%;height: 100%;"></image>
  15. </swiper-item>
  16. </swiper>
  17. </view>
  18. <view class="shop-tab">
  19. <u-tabs :list="tabList" :is-scroll="false" :current="tabIndex" @change="changeTabs" font-size="30" active-color="#52A63A"
  20. inactive-color="#666666" :bold="false" height="90" bar-width="80"></u-tabs>
  21. </view>
  22. <view class="shop-sort" :class="dropShow ? 'visibility-drop' : 'hidden-drop'" v-show="!tabIndex">
  23. <u-dropdown active-color="#52A63A" @close="dropShow = false" @open="dropShow = true">
  24. <u-dropdown-item v-model="goodSort" title="新品" :options="options1" @change="changeSort()"></u-dropdown-item>
  25. <u-dropdown-item v-model="goodSort" title="价格" :options="options2" @change="changeSort()"></u-dropdown-item>
  26. <u-dropdown-item v-model="goodSort" title="销量" :options="options3" @change="changeSort()"></u-dropdown-item>
  27. </u-dropdown>
  28. </view>
  29. <view class="shop-all-goods" v-show="!tabIndex">
  30. <view class="goods-row" v-for="(item,index) in allGoodsList" :key="index" @click="goToGoodDetails(item)">
  31. <image class="goods-img" :src="item.imgPath" mode="aspectFill"></image>
  32. <view class="goods-info">
  33. <view class="goods-name">{{item.productName}}</view>
  34. <view class="goods-number">{{item.sellCount}}人付款</view>
  35. <text class="goods-price">
  36. <text class="sale-icon">¥</text>
  37. <text class="sale-price">{{item.bizPrice}}</text>
  38. <text class="price">原价:{{item.originalPrice}}</text>
  39. <text class="iconfont icongengduo"></text>
  40. </text>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="shop-category" v-show="tabIndex">
  45. <view class="category-col" v-for="(item,index) in categoryList" :key="index" :style="{width: item.width + '%'}">
  46. <view class="category-button" :class="selectSort == item.productCategoryId ? 'category-button-active' : ''" :id="'categoryCol'+index"
  47. @click="changeCategory(item)">{{item.categoryName}}</view>
  48. </view>
  49. </view>
  50. <view class="shop-all-goods" v-show="tabIndex">
  51. <view class="goods-row" v-for="(item,index) in sortGoodsList" :key="index" @click="goToGoodDetails(item)">
  52. <image class="goods-img" :src="item.imgPath"></image>
  53. <view class="goods-info">
  54. <view class="goods-name">{{item.productName}}</view>
  55. <view class="goods-number">{{item.sellCount}}人付款</view>
  56. <text class="goods-price">
  57. <text class="sale-icon">¥</text>
  58. <text class="sale-price">{{item.bizPrice}}</text>
  59. <text class="price">原价:{{item.originalPrice}}</text>
  60. <text class="iconfont icongengduo"></text>
  61. </text>
  62. </view>
  63. </view>
  64. </view>
  65. <u-top-tips ref="uTips"></u-top-tips>
  66. </scroll-view>
  67. </template>
  68. <script>
  69. const NET = require('@/utils/request')
  70. const API = require('@/config/api')
  71. export default {
  72. data() {
  73. return {
  74. swiperHeight: 140,
  75. shopData: {
  76. name: '',
  77. logo: '',
  78. soldCount: '',
  79. storeImgUrl: [],
  80. },
  81. tabIndex: 0,
  82. tabList: [{
  83. name: '全部商品'
  84. }
  85. // {
  86. // name: '分类查看'
  87. // }
  88. ],
  89. goodSort: 1,
  90. options1: [{
  91. label: '新品',
  92. value: 1
  93. }],
  94. options2: [{
  95. label: '价格升序',
  96. value: 2
  97. },
  98. {
  99. label: '价格降序',
  100. value: 3
  101. }
  102. ],
  103. options3: [{
  104. label: '销量升序',
  105. value: 4
  106. },
  107. {
  108. label: '销量降序',
  109. value: 5
  110. }
  111. ],
  112. dropShow: false,
  113. pageIndex1: 1,
  114. isOver1: false,
  115. allGoodsList: [],
  116. selectSort: '',
  117. categoryList: [],
  118. pageIndex2: 1,
  119. isOver2: false,
  120. sortGoodsList: [],
  121. isSet: false,
  122. }
  123. },
  124. onLoad(options) {
  125. uni.getSystemInfo({
  126. success: (res) => {
  127. this.swiperHeight = res.windowWidth
  128. }
  129. })
  130. this.goodId = options.goodId
  131. NET.request(API.getShopDetail + '/' + this.goodId, {}, 'GET').then(res => {
  132. res.data.storeImgUrl = res.data.storeImgUrl && res.data.storeImgUrl.length ? res.data.storeImgUrl.split(',') : []
  133. this.shopData = res.data
  134. }).catch(res => {
  135. this.$refs.uTips.show({
  136. title: '获取商铺详情失败',
  137. type: 'warning',
  138. })
  139. })
  140. this.getAllGoodsList()
  141. },
  142. onReady() {
  143. let queryNode = uni.createSelectorQuery().in(this);
  144. queryNode.select('#shopBox').boundingClientRect(data => {
  145. this.winWidth = data.width
  146. }).exec();
  147. NET.request(API.getCategoryByShop + this.goodId, {}, 'GET').then(res => {
  148. this.categoryList = res.data
  149. this.selectSort = res.data.length ? res.data[0].productCategoryId : ''
  150. this.getSortGoodsList()
  151. }).catch(res => {
  152. this.$refs.uTips.show({
  153. title: '获取分类失败',
  154. type: 'warning',
  155. })
  156. })
  157. },
  158. methods: {
  159. // 切换tab
  160. changeTabs(index) {
  161. this.tabIndex = index;
  162. if (index && !this.isSet) {
  163. this.$nextTick(() => {
  164. this.isSet = true
  165. this.setWidth()
  166. });
  167. }
  168. },
  169. // 重新查询全部商品
  170. changeSort() {
  171. this.isOver1 = false
  172. this.pageIndex1 = 1
  173. this.allGoodsList = []
  174. this.getAllGoodsList()
  175. },
  176. // 懒加载
  177. handleLoadMore() {
  178. if (this.tabIndex == 0) {
  179. if (!this.isOver1) {
  180. this.pageIndex1++
  181. this.getAllGoodsList()
  182. }
  183. } else {
  184. if (!this.isOver2) {
  185. this.pageIndex2++
  186. this.getSortGoodsList()
  187. }
  188. }
  189. },
  190. // 获取全部商品
  191. getAllGoodsList() {
  192. NET.request(API.getAllGoodsByShop + this.goodId + '/' + this.pageIndex1 + '/10', {
  193. sort: this.goodSort,
  194. }, 'GET').then(res => {
  195. this.isOver1 = res.data.list.length != 10
  196. this.allGoodsList = this.allGoodsList.concat(res.data.list)
  197. }).catch(res => {
  198. this.$refs.uTips.show({
  199. title: '获取商品列表失败',
  200. type: 'warning',
  201. })
  202. })
  203. },
  204. // 获取分类商品
  205. getSortGoodsList() {
  206. NET.request(API.getGoodsByShopAndSort + this.selectSort + '/' + this.pageIndex2 + '/10', {
  207. tenantCode: this.selectSort
  208. }, 'GET').then(res => {
  209. this.isOver2 = res.data.list.length != 10
  210. this.sortGoodsList = this.sortGoodsList.concat(res.data.list)
  211. }).catch(res => {
  212. this.$refs.uTips.show({
  213. title: '获取商品列表失败',
  214. type: 'warning',
  215. })
  216. })
  217. },
  218. // 跳转商品详情
  219. goToGoodDetails(item) {
  220. uni.navigateTo({
  221. url: '/pagesGood/goodDetails?goodId=' + item.productId + '&goodType=' + item.productType
  222. });
  223. },
  224. // 重新查询分类商品
  225. changeCategory(item) {
  226. this.selectSort = item.productCategoryId
  227. this.isOver2 = false
  228. this.pageIndex2 = 1
  229. this.sortGoodsList = []
  230. this.getSortGoodsList()
  231. },
  232. // 动态渲染宽度
  233. setWidth() {
  234. let queryNode = uni.createSelectorQuery().in(this);
  235. this.categoryList.forEach((site, index) => {
  236. queryNode.select('#categoryCol' + index).boundingClientRect(data => {
  237. if (data.width > this.winWidth * 0.66) {
  238. site.width = 100
  239. } else if (data.width > this.winWidth * 0.33) {
  240. site.width = 66
  241. } else {
  242. site.width = 33
  243. }
  244. }).exec();
  245. })
  246. }
  247. },
  248. }
  249. </script>
  250. <style lang="less" scoped>
  251. page {
  252. width: 100%;
  253. height: 100%;
  254. }
  255. .container {
  256. width: 100%;
  257. height: 100%;
  258. float: left;
  259. .shop-bg {
  260. width: 100%;
  261. height: 120px;
  262. float: left;
  263. background-color: #52A63A;
  264. }
  265. .shop-info {
  266. width: 100%;
  267. height: 90px;
  268. float: left;
  269. background: #FFFFFF;
  270. border-radius: 10px 10px 0px 0px;
  271. margin-top: -25px;
  272. .shop-icon {
  273. width: 100%;
  274. height: 60px;
  275. float: left;
  276. margin-top: -30px;
  277. .shop-logo {
  278. width: 60px;
  279. height: 60px;
  280. border-radius: 50%;
  281. overflow: hidden;
  282. position: relative;
  283. left: 50%;
  284. transform: translateX(-50%);
  285. }
  286. }
  287. .shop-name {
  288. width: 100%;
  289. height: 34px;
  290. line-height: 34px;
  291. float: left;
  292. font-size: 15px;
  293. font-family: SimHei;
  294. color: #333333;
  295. text-align: center;
  296. }
  297. .shop-sell {
  298. width: 100%;
  299. height: 16px;
  300. line-height: 16px;
  301. float: left;
  302. font-size: 12px;
  303. font-family: SimHei;
  304. color: #666666;
  305. text-align: center;
  306. }
  307. }
  308. .shop-image {
  309. width: 100%;
  310. height: 170px;
  311. float: left;
  312. box-sizing: border-box;
  313. padding: 10px 15px 20px 15px;
  314. background-color: #f7f7f7;
  315. // .swiper {
  316. // height: 140px;
  317. // }
  318. }
  319. .shop-tab {
  320. width: 100%;
  321. height: 45px;
  322. float: left;
  323. background-color: #FFFFFF;
  324. }
  325. .shop-sort {
  326. width: 100%;
  327. height: 40px;
  328. float: left;
  329. background-color: #FFFFFF;
  330. /deep/.u-dropdown__content__mask {
  331. visibility: hidden;
  332. }
  333. }
  334. .visibility-drop {
  335. /deep/.u-dropdown__content {
  336. z-index: 100 !important;
  337. min-height: 106px;
  338. }
  339. }
  340. .hidden-drop {
  341. /deep/.u-dropdown__content {
  342. display: none;
  343. }
  344. }
  345. .shop-category {
  346. width: 100%;
  347. float: left;
  348. background-color: #FFFFFF;
  349. .category-col {
  350. min-width: 33%;
  351. height: 26px;
  352. float: left;
  353. margin: 6px 0;
  354. box-sizing: content-box;
  355. .category-button {
  356. height: 24px;
  357. float: left;
  358. border-radius: 13px;
  359. box-sizing: content-box;
  360. border: 1px solid #51A539;
  361. padding: 0 16px;
  362. position: relative;
  363. left: 50%;
  364. transform: translateX(-50%);
  365. line-height: 24px;
  366. font-size: 12px;
  367. font-family: PingFang SC;
  368. color: #52A539;
  369. }
  370. .category-button-active {
  371. background-color: #52A539;
  372. color: #FFFFFF;
  373. }
  374. }
  375. }
  376. .shop-all-goods {
  377. width: 100%;
  378. float: left;
  379. padding: 6px 0 0px 0;
  380. box-sizing: border-box;
  381. overflow-y: auto;
  382. background-color: #f7f7f7;
  383. .goods-row {
  384. width: calc(100% - 24px);
  385. height: 104px;
  386. float: left;
  387. margin: 6px 0 12px 12px;
  388. background: #FFFFFF;
  389. box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.09);
  390. border-radius: 5px;
  391. overflow: hidden;
  392. display: flex;
  393. .goods-img {
  394. width: 104px;
  395. height: 104px;
  396. object-fit: cover;
  397. }
  398. .goods-info {
  399. width: calc(100% - 104px);
  400. padding: 10px 10px 10px 12px;
  401. box-sizing: border-box;
  402. .goods-name {
  403. height: 36px;
  404. font-size: 15px;
  405. font-family: PingFang SC;
  406. color: #333333;
  407. line-height: 18px;
  408. overflow: hidden;
  409. text-overflow: ellipsis;
  410. display: -webkit-box;
  411. -webkit-line-clamp: 2;
  412. -webkit-box-orient: vertical;
  413. word-wrap: break-word;
  414. }
  415. .goods-number {
  416. height: 16px;
  417. font-size: 12px;
  418. font-family: PingFang SC;
  419. color: #666666;
  420. line-height: 16px;
  421. margin: 6px 0 4px 0;
  422. }
  423. .goods-price {
  424. height: 24px;
  425. line-height: 24px;
  426. font-family: PingFang SC;
  427. .sale-icon {
  428. font-size: 12px;
  429. color: #56a83a;
  430. margin-left: -2px;
  431. }
  432. .sale-price {
  433. font-size: 22px;
  434. color: #6CA63A;
  435. margin-right: 6px;
  436. }
  437. .price {
  438. font-size: 12px;
  439. text-decoration: line-through;
  440. color: #A67954;
  441. }
  442. .iconfont {
  443. float: right;
  444. color: #999999;
  445. font-size: 32px;
  446. line-height: 28px;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. </style>