shopDetails.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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" :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%;border-radius: 10px;" :style="{height: (swiperHeight / 2)+'px'}"></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="#56a83a"
  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 - 30
  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. float: left;
  311. box-sizing: border-box;
  312. padding: 10px 15px 20px 15px;
  313. background-color: #f7f7f7;
  314. // .swiper {
  315. // height: 140px;
  316. // }
  317. }
  318. .shop-tab {
  319. width: 100%;
  320. height: 45px;
  321. float: left;
  322. background-color: #FFFFFF;
  323. }
  324. .shop-sort {
  325. width: 100%;
  326. height: 40px;
  327. float: left;
  328. background-color: #FFFFFF;
  329. /deep/.u-dropdown__content__mask {
  330. visibility: hidden;
  331. }
  332. }
  333. .visibility-drop {
  334. /deep/.u-dropdown__content {
  335. z-index: 100 !important;
  336. min-height: 106px;
  337. }
  338. }
  339. .hidden-drop {
  340. /deep/.u-dropdown__content {
  341. display: none;
  342. }
  343. }
  344. .shop-category {
  345. width: 100%;
  346. float: left;
  347. background-color: #FFFFFF;
  348. .category-col {
  349. min-width: 33%;
  350. height: 26px;
  351. float: left;
  352. margin: 6px 0;
  353. box-sizing: content-box;
  354. .category-button {
  355. height: 24px;
  356. float: left;
  357. border-radius: 13px;
  358. box-sizing: content-box;
  359. border: 1px solid #51A539;
  360. padding: 0 16px;
  361. position: relative;
  362. left: 50%;
  363. transform: translateX(-50%);
  364. line-height: 24px;
  365. font-size: 12px;
  366. font-family: PingFang SC;
  367. color: #52A539;
  368. }
  369. .category-button-active {
  370. background-color: #52A539;
  371. color: #FFFFFF;
  372. }
  373. }
  374. }
  375. .shop-all-goods {
  376. width: 100%;
  377. float: left;
  378. padding: 6px 0 0px 0;
  379. box-sizing: border-box;
  380. overflow-y: auto;
  381. background-color: #f7f7f7;
  382. .goods-row {
  383. width: calc(100% - 24px);
  384. height: 104px;
  385. float: left;
  386. margin: 6px 0 12px 12px;
  387. background: #FFFFFF;
  388. box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.09);
  389. border-radius: 5px;
  390. overflow: hidden;
  391. display: flex;
  392. .goods-img {
  393. width: 104px;
  394. height: 104px;
  395. object-fit: cover;
  396. }
  397. .goods-info {
  398. width: calc(100% - 104px);
  399. padding: 10px 10px 10px 12px;
  400. box-sizing: border-box;
  401. .goods-name {
  402. height: 36px;
  403. font-size: 15px;
  404. font-family: PingFang SC;
  405. color: #333333;
  406. line-height: 18px;
  407. overflow: hidden;
  408. text-overflow: ellipsis;
  409. display: -webkit-box;
  410. -webkit-line-clamp: 2;
  411. -webkit-box-orient: vertical;
  412. word-wrap: break-word;
  413. }
  414. .goods-number {
  415. height: 16px;
  416. font-size: 12px;
  417. font-family: PingFang SC;
  418. color: #666666;
  419. line-height: 16px;
  420. margin: 6px 0 4px 0;
  421. }
  422. .goods-price {
  423. height: 24px;
  424. line-height: 24px;
  425. font-family: PingFang SC;
  426. .sale-icon {
  427. font-size: 12px;
  428. color: #56a83a;
  429. margin-left: -2px;
  430. }
  431. .sale-price {
  432. font-size: 22px;
  433. color: #6CA63A;
  434. margin-right: 6px;
  435. }
  436. .price {
  437. font-size: 12px;
  438. text-decoration: line-through;
  439. color: #A67954;
  440. }
  441. .iconfont {
  442. float: right;
  443. color: #999999;
  444. font-size: 32px;
  445. line-height: 28px;
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. </style>