shopDetails.vue 12 KB

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