shopDetails.vue 11 KB

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