shopDetail.vue 15 KB

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