shopDetails.vue 11 KB

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