shopDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <view class="shopDetail">
  3. <view class="top-box">
  4. <image class="bg target" :src="info.detailImg" mode="aspectFill"></image>
  5. <view class="shop-info">
  6. <image class="shop-logo" :src="info.logoPath" mode=""></image>
  7. <view class="info-box">
  8. <view class="title-box">
  9. <view class="title">
  10. {{info.shopVo.shopName}}
  11. </view>
  12. </view>
  13. <view class="address-box">
  14. <view class="distance">
  15. <image class="address-icon" src="../../static/address-icon.png" mode=""></image> 距你直线距离{{(info.shopVo.distance/1000).toFixed(2)}}km &nbsp;·&nbsp;{{info.district}}
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="card-box">
  21. <view class="card" v-for="(item,index) in freeList" :key="index" @click="openPop">
  22. {{item | filterCard}}
  23. </view>
  24. </view>
  25. <view class="desc-box" :class="[showDesc?'':'hidden']" v-if="info.detailContent">
  26. <view class="shop-desc">
  27. {{info.detailContent|| ''}}
  28. </view>
  29. <image class="icon" @click="handleDesc" src="../../static/shop-desc.png" mode=""></image>
  30. </view>
  31. </view>
  32. <zs-list class="goods-list" mt="0" @load="loadMore" :status="status">
  33. <!-- <view class="goods-list"> -->
  34. <view class="goods-item" v-for="item in buyList" :key="item.goodsId" @click="goDetail(item)">
  35. <zs-img :src="item.goodsImg" width="200rpx" height="200rpx" radius="full" mode="" ></zs-img>
  36. <view class="info">
  37. <view class="title">
  38. {{item.goodsName}}
  39. </view>
  40. <view class="desc">
  41. {{item.goodsDescribe}}
  42. </view>
  43. <view class="price-box">
  44. <view class="left">
  45. <view class="unit">
  46. </view>
  47. <view class="price">
  48. {{item.realPrice}}
  49. </view>
  50. <view class="old-price">
  51. 市场价 ¥{{item.marketPrice}}
  52. </view>
  53. </view>
  54. <view class="right">
  55. 销量{{item.saleNum}}
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- </view> -->
  61. </zs-list>
  62. <u-empty marginTop="100" textSize="20" v-if="!buyList.length" mode="data"></u-empty>
  63. <u-popup :show="show" round="32rpx" mode="bottom" @close="show = false" @open="openPop">
  64. <view class="discounts">
  65. <view class="title">
  66. 免费领取
  67. </view>
  68. <u-empty marginTop="100" textSize="20" v-if="!freeList.length" mode="data"></u-empty>
  69. <view class="discounts-item" v-for="(item,index) in freeList" :key="index" >
  70. <view class="card-content" :class="item.buySet == 2&&item.useCount==0?'card-used':''">
  71. <view class="price">
  72. {{item | filterCard}}
  73. </view>
  74. <view class="info">
  75. <view class="card-title">
  76. {{item.goodsName}}
  77. </view>
  78. <view class="limit">
  79. {{item.useType | filterType(item)}}
  80. </view>
  81. <view class="desc">
  82. {{item.validType | filterType1(item)}}
  83. </view>
  84. <!-- <view class="desc" :class="[open == index?'open':'']" @click="handleOpen(index,'open')">
  85. 展开详情 <image class="jiantou" src="../../static/jiantou-icon.png" mode=""></image>
  86. </view> -->
  87. </view>
  88. <view class="btn-box">
  89. <view class="btn" @click="handleBuy(item)">
  90. 领取
  91. </view>
  92. </view>
  93. <view class="num" v-if="item.buySet == 2">
  94. 剩余领取次数:{{item.useCount}}次
  95. </view>
  96. </view>
  97. <view class="card-desc" v-show="open == index">
  98. <view class="time">
  99. {{item.validType | filterType1(item)}}
  100. </view>
  101. <view class="desc" v-html="item.goodsDescribe">
  102. {{item.goodsDescribe}}
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. </u-popup>
  108. <!-- 地图 -->
  109. <map v-show="false" class="map" id="map"></map>
  110. </view>
  111. </template>
  112. <script>
  113. import { allCouponByUser,creat,getGoods } from '@/api/goods.js';
  114. import {shopDetail} from '@/api/shop.js'
  115. import guid from '@/utils/guid.js'
  116. import {rpxTopx} from '@/utils/tool.js'
  117. export default {
  118. data() {
  119. return {
  120. open:999,
  121. info: null,
  122. status: 'more',
  123. _mapContext: null,
  124. query:{
  125. currentPage:1,
  126. pageSize:99,
  127. setMealId:0,
  128. goodsType:2,
  129. shopId:'',
  130. userId:''
  131. },
  132. freeList:[],
  133. buyList:[],
  134. goodsTypeObj:{},
  135. showDesc:false,
  136. show:false,
  137. currentPage:1
  138. };
  139. },
  140. filters: {
  141. filterType: function(val,item) {
  142. if(val == 1){
  143. return '无使用限制'
  144. }else if(val == 2){
  145. return '使用期至' + item.useEndTime
  146. }else if(val == 3){
  147. return '每周'+ item.day +'可用'
  148. }else if(val == 4){
  149. return '每月'+ item.day +'可用'
  150. }
  151. },
  152. filterType1: function(val,item) {
  153. if(val == 1){
  154. return '有效期:无限制'
  155. }else if(val == 2){
  156. return '有效期:' + item.validStartTime + '-' + item.validEndTime
  157. }
  158. },
  159. filterCard:function(val){
  160. if(val.goodsCode == '102'){
  161. return `减${val.discount}`
  162. }else if(val.goodsCode == '103'){
  163. return `${val.discount/10}折`
  164. }else if(val.goodsCode == '104'){
  165. return `满${val.condition}减${val.discount}`
  166. }
  167. }
  168. },
  169. methods: {
  170. openPop(){
  171. this.show = true
  172. },
  173. handleDesc(){
  174. this.showDesc = !this.showDesc
  175. },
  176. // 地图中打开商家
  177. handleAdress(item) {
  178. this._mapContext.openMapApp({
  179. longitude: Number(item.longitude) ,
  180. latitude: Number(item.latitude),
  181. destination: item.shopVo.shopName,
  182. complete(r) {
  183. console.log(r);
  184. }
  185. })
  186. },
  187. init(){
  188. let userInfo
  189. if(uni.getStorageSync('userInfo')){
  190. userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  191. }else{
  192. userInfo = {setMealId:0,userId:''}
  193. }
  194. this.info = JSON.parse(uni.getStorageSync('shopInfo'))
  195. this.shopDetail(this.info.shopVo.id)
  196. this.query.shopId = this.info.shopVo.id
  197. this.query.setMealId = userInfo.setMealId
  198. this.query.userId = userInfo.userId
  199. this.getGoods()
  200. this.allCouponByUser(2)//商品1 优惠券 2
  201. },
  202. handleOpen(val,open){
  203. if(val === this[open]){
  204. this[open] = 7
  205. }else{
  206. this[open] = val
  207. }
  208. },
  209. // 点击领取
  210. handleBuy(item) {
  211. if(!uni.getStorageSync('token')){
  212. uni.showModal({
  213. title:'请登录',
  214. confirmText:'去登录',
  215. success(res){
  216. if(res.confirm){
  217. uni.navigateTo({
  218. url:'/login/login/login'
  219. })
  220. }
  221. }
  222. })
  223. }else{
  224. if(item.buySet == 2&&item.useCount == 0){
  225. return uni.showToast({
  226. title:'领取次数不足',
  227. icon:'none'
  228. })
  229. }
  230. creat({
  231. "discountId": [
  232. ],
  233. "goodsList": [
  234. item.goodsId
  235. ],
  236. "idempotent": guid(),
  237. "shopId": this.query.shopId
  238. }).then(res=>{
  239. if(res.state == 'Success'){
  240. uni.showToast({
  241. title:'领取成功'
  242. })
  243. this.allCouponByUser(2)//优惠券
  244. }
  245. })
  246. // uni.navigateTo({
  247. // url: '../qrcode/index'
  248. // })
  249. }
  250. },
  251. goDetail(item){
  252. let data = item
  253. // data.shopName = this.info.shopVo.shopName
  254. // data.address = this.info.district
  255. // uni.setStorageSync('goodsInfo', JSON.stringify(data))
  256. uni.navigateTo({
  257. url: `../goodsDetail/index?id=${item.goodsId}`,
  258. // success: function(res) {
  259. // // 通过eventChannel向被打开页面传送数据
  260. // res.eventChannel.emit('goodsInfo', data)
  261. // }
  262. })
  263. },
  264. loadMore(){
  265. this.getGoods()
  266. },
  267. allCouponByUser(val){
  268. allCouponByUser(this.query).then(res=>{
  269. if(res.state == 'Success'){
  270. this.freeList = res.content.records
  271. uni.stopPullDownRefresh()
  272. }
  273. })
  274. },
  275. getGoods(){
  276. if(this.status == 'noMore') return
  277. this.status = 'loading'
  278. getGoods({currentPage:this.currentPage,status:3,shopId:this.info.shopVo.id}).then(res=>{
  279. if(res.state == 'Success'){
  280. this.buyList = this.buyList.concat(res.content.records)
  281. console.log(res.content.total,this.buyList.length);
  282. if(res.content.total>this.buyList.length){
  283. this.status = 'more'
  284. this.currentPage++
  285. }else{
  286. this.status = 'noMore'
  287. }
  288. }
  289. })
  290. },
  291. shopDetail(shopId){
  292. shopDetail({shopId}).then(res=>{
  293. if(res.state == 'Success'){
  294. this.info.detailImg = res.content.detailImg
  295. }
  296. })
  297. }
  298. },
  299. onPullDownRefresh() {
  300. this.init()
  301. },
  302. onReady() {
  303. this._mapContext = uni.createMapContext("map", this);
  304. },
  305. onPageScroll(e) {
  306. // if(e.scrollTop >= rpxTopx(658)-84-rpxTopx(80)){
  307. // this.background = true
  308. // }else{
  309. // this.background = false
  310. // }
  311. },
  312. onShow() {
  313. this.init()
  314. },
  315. onLoad(options) {
  316. this.goodsTypeObj = JSON.parse(uni.getStorageSync('goodsTypeObj'))
  317. },
  318. }
  319. </script>
  320. <style lang="scss">
  321. .shopDetail {
  322. min-height: 100vh;
  323. background: #F9F9F9;
  324. .top-box{
  325. .bg {
  326. width: 100%;
  327. height: 240rpx;
  328. object-fit: cover;
  329. vertical-align: bottom;
  330. }
  331. .shop-info {
  332. padding: 16rpx 24rpx;
  333. margin-top: -30rpx;
  334. box-sizing: border-box;
  335. background: #fff;
  336. border-radius: 32rpx;
  337. position: relative;
  338. z-index: 2;
  339. display: flex;
  340. .shop-logo{
  341. width: 120rpx;
  342. height: 120rpx;
  343. border-radius: 16rpx 16rpx 16rpx 16rpx;
  344. margin-top: -28rpx;
  345. }
  346. .info-box{
  347. margin-left: 20rpx;
  348. color: #222222;
  349. .title-box{
  350. display: flex;
  351. justify-content: space-between;
  352. .title {
  353. font-size: 32rpx;
  354. font-weight: bold;
  355. }
  356. }
  357. .address-box{
  358. width: 100%;
  359. display: flex;
  360. align-items: center;
  361. // padding: 30rpx 0;
  362. margin-top: 12rpx;
  363. box-sizing: border-box;
  364. font-weight: 300;
  365. font-size: 22rpx;
  366. color: #222222;
  367. .distance{
  368. display: flex;
  369. align-items: center;
  370. .address-icon{
  371. width: 32rpx;
  372. height: 32rpx;
  373. margin-right: 10rpx;
  374. }
  375. }
  376. }
  377. }
  378. }
  379. .card-box{
  380. display: flex;
  381. align-items: center;
  382. padding: 12rpx 24rpx;
  383. background: #fff;
  384. .card{
  385. height: 40rpx;
  386. line-height: 40rpx;
  387. padding: 0 14rpx;
  388. border-radius: 8rpx 8rpx 8rpx 8rpx;
  389. border: 1rpx solid #FF4C39;
  390. color: #FF4C39;
  391. font-size: 20rpx;
  392. margin-right: 12rpx;
  393. }
  394. }
  395. .desc-box.hidden{
  396. .shop-desc{
  397. overflow: hidden;
  398. white-space: nowrap;
  399. text-overflow: ellipsis;
  400. }
  401. .icon{
  402. transform: rotateZ(0deg);
  403. }
  404. }
  405. .desc-box{
  406. position: relative;
  407. padding-right: 30rpx;
  408. background: #fff;
  409. padding-bottom: 24rpx;
  410. .shop-desc{
  411. font-size: 20rpx;
  412. color: #AAAAAA;
  413. padding: 0 24rpx;
  414. width: 100%;
  415. box-sizing: border-box;
  416. }
  417. .icon{
  418. position: absolute;
  419. right: 0;
  420. top: 0;
  421. transform-origin: center;
  422. transform: rotateZ(180deg);
  423. transition: transform .3s;
  424. width: 32rpx;
  425. height: 32rpx;
  426. }
  427. }
  428. }
  429. .goods-list{
  430. .goods-item{
  431. display: flex;
  432. padding: 24rpx;
  433. background: #fff;
  434. border-radius: 16rpx;
  435. margin: 20rpx 24rpx 0;
  436. .info{
  437. flex: 1;
  438. padding-left: 20rpx;
  439. display: flex;
  440. flex-direction: column;
  441. justify-content: space-between;
  442. position: relative;
  443. .title{
  444. font-size: 28rpx;
  445. font-weight: bold;
  446. width: 340rpx;
  447. white-space: nowrap;
  448. overflow: hidden;
  449. text-overflow: ellipsis;
  450. margin-top: 10rpx;
  451. }
  452. .desc{
  453. font-size: 24rpx;
  454. color: #AAAAAA;
  455. overflow: hidden;
  456. text-overflow: ellipsis;
  457. /* 弹性伸缩盒子模型显示 */
  458. display: -webkit-box;
  459. /* 限制在一个块元素显示的文本的行数 */
  460. -webkit-line-clamp: 2;
  461. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  462. -webkit-box-orient: vertical;
  463. }
  464. .price-box{
  465. display: flex;
  466. justify-content: space-between;
  467. align-items: center;
  468. .left{
  469. display: flex;
  470. align-items: flex-end;
  471. .unit{
  472. font-size: 20rpx;
  473. color: $uni-color-primary;
  474. font-weight: bold;
  475. }
  476. .price{
  477. font-size: 32rpx;
  478. color: $uni-color-primary;
  479. font-weight: bold;
  480. }
  481. .old-price{
  482. font-size: 20rpx;
  483. color: #AAAAAA;
  484. text-decoration: line-through;
  485. margin-left: 12rpx;
  486. }
  487. }
  488. .right{
  489. font-size: 24rpx;
  490. color: #AAAAAA;
  491. }
  492. }
  493. }
  494. }
  495. }
  496. .discounts {
  497. padding: 28rpx 24rpx;
  498. max-height: 1000rpx;
  499. min-height: 600rpx;
  500. .title {
  501. font-weight: bold;
  502. font-size: 32rpx;
  503. color: #222222;
  504. text-align: center;
  505. margin-bottom: 28rpx;
  506. }
  507. .discounts-item {
  508. filter: drop-shadow(0 6rpx 2rpx rgba(0,0,0,.1));
  509. .card-content.card-used{
  510. // background: url('../../static/card-used.png') no-repeat;
  511. // background-size: 100% 144rpx;
  512. }
  513. .card-content{
  514. display: flex;
  515. align-items: center;
  516. justify-content: space-between;
  517. background-color: rgb(239, 239, 239);
  518. background: url('../../static/new-card.png') no-repeat;
  519. background-repeat: no-repeat;
  520. background-size: 100% 144rpx;
  521. filter: drop-shadow(0rpx 0rpx 6rpx 2rpx rgba(0,0,0,0.1));
  522. border-radius: 16rpx;
  523. height: 144rpx;
  524. padding: 0 24rpx;
  525. margin-top: 20rpx;
  526. position: relative;
  527. box-sizing: border-box;
  528. .price{
  529. width: 150rpx;
  530. text-align: center;
  531. font-weight: 400;
  532. font-size: 40rpx;
  533. color: $uni-color-primary;
  534. }
  535. .info {
  536. flex: 1;
  537. padding-left: 28rpx;
  538. .card-title {
  539. font-weight: 400;
  540. font-size: 28rpx;
  541. color: #222222;
  542. }
  543. .desc{
  544. display: flex;
  545. align-items: center;
  546. font-size: 20rpx;
  547. color: #AAAAAA;
  548. .jiantou{
  549. width: 20rpx;
  550. height: 20rpx;
  551. transform: rotateZ(90deg);
  552. display: block;
  553. margin-left: 10rpx;
  554. transition: transform .3s;
  555. }
  556. }
  557. .open{
  558. .jiantou{
  559. transform: rotateZ(270deg)!important;
  560. }
  561. }
  562. .red{
  563. color: $uni-text-primary!important;
  564. }
  565. .limit{
  566. font-size: 20rpx;
  567. color: #AAAAAA;
  568. margin:10rpx 0;
  569. }
  570. .time {
  571. color: #9a9a9a;
  572. font-size: 24rpx;
  573. margin-top: 15rpx;
  574. }
  575. }
  576. .btn-box{
  577. .btn {
  578. width: 120rpx;
  579. height: 48rpx;
  580. border-radius: 24rpx;
  581. background: $uni-color-primary;
  582. line-height: 48rpx;
  583. text-align: center;
  584. font-weight: bold;
  585. font-size: 24rpx;
  586. color: #FFFFFF;
  587. }
  588. }
  589. .num{
  590. position: absolute;
  591. white-space: nowrap;
  592. bottom: 10rpx;
  593. right: 26rpx;
  594. font-size: 18rpx;
  595. color: #222222;
  596. }
  597. }
  598. .card-desc{
  599. font-size: 20rpx;
  600. color: #AAAAAA;
  601. padding: 20rpx 10rpx;
  602. background: #FFFFFF;
  603. border-radius: 0rpx 0rpx 16rpx 16rpx;
  604. .time{
  605. }
  606. .desc{
  607. margin-top: 22rpx;
  608. }
  609. }
  610. }
  611. }
  612. .map {
  613. position: relative;
  614. top: -100000px;
  615. left: -1000000px;
  616. }
  617. }
  618. </style>