index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <view class="goodsDetail">
  3. <image class="good-img" :src="info.goodsPath" mode="aspectFit"></image>
  4. <view class="price-box">
  5. <view class="left">
  6. <view class="unit">
  7. </view>
  8. <view class="price">
  9. {{info.realPrice}}
  10. </view>
  11. <view class="old-price">
  12. 市场价 ¥{{info.marketPrice}}
  13. </view>
  14. </view>
  15. <view class="right">
  16. 销量{{info.saleNum}}
  17. </view>
  18. </view>
  19. <view class="goods-info">
  20. <view class="goods-name">
  21. {{info.goodsName}}
  22. </view>
  23. <view class="desc">
  24. {{info.goodsDescribe}}
  25. </view>
  26. </view>
  27. <template v-if="info.specs[0].specValues.length">
  28. <view class="type-box" v-for="item in info.specs" :key="item.specId">
  29. <view class="type-title">
  30. {{item.specName}}
  31. </view>
  32. <view class="type-list">
  33. <view class="type-item" :class="[active == d?'active':'' ]" v-for="(i,d) in item.specValues" :key="i.specId">
  34. {{i.specValue}}
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <view class="shop-limit" @click="jump('/detail/shopList/index')">
  40. <view class="info">
  41. <view class="shop-name">
  42. <!-- 朱光玉火锅(天河店) -->
  43. {{shopInfo.shopVo.shopName}}
  44. </view>
  45. <view class="address">
  46. <!-- 花溪区天河潭旅游度假区天河潭 22.65km -->
  47. {{shopInfo.district}} {{(shopInfo.shopVo.distance/1000).toFixed(2)}} KM
  48. </view>
  49. </view>
  50. <view class="num">
  51. {{shopList.length}}家店适用
  52. <image class="icon" src="../../static/shop-desc.png" mode=""></image>
  53. </view>
  54. </view>
  55. <view class="tab-group">
  56. <view class="tab" :class="[tab == 1 ? 'active':'']" @click="handleTab(1)">
  57. 商品详情
  58. </view>
  59. <view class="tab" :class="[tab == 2 ? 'active':'']" @click="handleTab(2)">
  60. 购买须知
  61. </view>
  62. </view>
  63. <view class="desc-box" v-show="tab == 1">
  64. <rich-text class="goods-desc" :nodes="info.goodsDetail"></rich-text>
  65. </view>
  66. <view class="list" v-show="tab == 2">
  67. <view class="item" v-for="(item,index) in info.attrs" :key="index">
  68. <view class="label">
  69. {{item.attrName == 'validDay'?'有效期':item.attrName}}
  70. </view>
  71. <view class="value" v-html="filterMsg(item.attrValue,item.attrName)">
  72. </view>
  73. </view>
  74. <!-- <view class="item">
  75. <view class="label">
  76. 使用时间
  77. </view>
  78. <view class="value">
  79. 营业时间内可用
  80. </view>
  81. </view> -->
  82. </view>
  83. <view class="buy-box">
  84. <image class="head" :src="shopInfo.logoPath" @click="goShopDetail(shopInfo)" mode=""></image>
  85. <view class="btn-box">
  86. <!-- <view class="group-btn" @click="handleBuy">
  87. <view class="label">
  88. 团购
  89. </view>
  90. <view class="price">
  91. ¥{{info.realPrice}}
  92. </view>
  93. </view> -->
  94. <view class="buy-btn" :class="[info.realStockNum?'':'none']" @click="handleBuy">
  95. <view class="label">
  96. {{info.realStockNum?'会员专享价':'售罄'}}
  97. </view>
  98. <view class="price">
  99. ¥{{info.realPrice}}
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. </template>
  106. <script>
  107. import {detail} from '@/api/goods.js'
  108. import {search} from '@/api/shop.js'
  109. export default {
  110. data() {
  111. return {
  112. active:0,
  113. tab:1,
  114. shopList:[],
  115. info: {},
  116. shopInfo:{}
  117. }
  118. },
  119. methods: {
  120. filterMsg(val,name){
  121. let msg = val.replace(/\n/g, "<br>")
  122. if(name == 'validDay'){
  123. msg = val + '天'
  124. }
  125. return msg
  126. },
  127. jump(url){
  128. uni.navigateTo({
  129. url
  130. })
  131. },
  132. handleTab(val){
  133. this.tab = val
  134. },
  135. handleBuy() {
  136. if(!this.info.realStockNum) return
  137. let that = this
  138. if (uni.getStorageSync('token')) {
  139. uni.navigateTo({
  140. url:`/pay/pay`,
  141. success: function(res) {
  142. // 通过eventChannel向被打开页面传送数据
  143. res.eventChannel.emit('pay', that.info)
  144. }
  145. })
  146. } else {
  147. uni.showModal({
  148. title:'请登录',
  149. confirmText:'去登录',
  150. success(res){
  151. console.log(res);
  152. if(res.confirm){
  153. uni.navigateTo({
  154. url:`/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`
  155. })
  156. }
  157. }
  158. })
  159. }
  160. },
  161. detail(goodsId){
  162. detail({goodsId,resource:2}).then(res=>{
  163. if(res.state == 'Success'){
  164. this.info = res.content
  165. this.info.goodsDetail = res.content.goodsDetail.replace(/<img/gi, '<img class="img_class" ')
  166. }
  167. })
  168. },
  169. goShopDetail(shopInfo) {
  170. uni.setStorageSync('shopInfo', JSON.stringify(shopInfo))
  171. uni.navigateTo({
  172. url: `../../detail/shopDetail/shopDetail`
  173. })
  174. },
  175. getShopList(goodsId){
  176. let location = JSON.parse(uni.getStorageSync('location'))
  177. let obj = {
  178. goodsId,
  179. pageCurrent:1,
  180. pageSize:99
  181. }
  182. obj['location.lat'] = location.latitude
  183. obj['location.lon'] = location.longitude
  184. search(obj).then(res=>{
  185. if(res.state == 'Success'){
  186. this.shopList = res.content.records
  187. uni.setStorageSync('shopList',JSON.stringify(this.shopList))
  188. }
  189. })
  190. }
  191. },
  192. onLoad(option) {
  193. this.shopInfo = JSON.parse(uni.getStorageSync('shopInfo'))
  194. this.detail(option.id)
  195. this.getShopList(option.id)
  196. let that = this
  197. // this.info = JSON.parse(uni.getStorageSync('goodsInfo'))
  198. // const eventChannel = this.getOpenerEventChannel();
  199. // if(JSON.stringify(eventChannel) !=='{}'){
  200. // eventChannel.on('goodsInfo', function(data) {
  201. // that.info = data
  202. // })
  203. // }
  204. }
  205. }
  206. </script>
  207. <style lang="scss" >
  208. .goodsDetail{
  209. background: #F9F9F9;
  210. padding-bottom: 200rpx;
  211. min-height: 100vh;
  212. .good-img{
  213. width: 100%;
  214. height: 750rpx;
  215. vertical-align: bottom;
  216. }
  217. .price-box{
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. width: 100%;
  222. height: 116rpx;
  223. box-sizing: border-box;
  224. background-image: url('../../static/price-bg.png');
  225. background-repeat: no-repeat;
  226. background-size: 100% 116rpx;
  227. padding: 24rpx;
  228. color: #fff;
  229. position: relative;
  230. margin-top: -116rpx;
  231. z-index: 2;
  232. .left{
  233. display: flex;
  234. align-items: center;
  235. .unit{
  236. font-size: 20rpx;
  237. font-weight: bold;
  238. align-self: flex-end;
  239. }
  240. .price{
  241. font-weight: 600;
  242. font-size: 48rpx;
  243. }
  244. .old-price{
  245. text-decoration: line-through;
  246. margin-left: 12rpx;
  247. font-weight: 300;
  248. font-size: 20rpx;
  249. }
  250. }
  251. .right{
  252. font-size: 24rpx;
  253. font-weight: 300;
  254. font-size: 24rpx;
  255. }
  256. }
  257. .goods-info{
  258. padding: 24rpx;
  259. margin-bottom: 20rpx;
  260. background: #fff;
  261. .goods-name{
  262. font-size: 32rpx;
  263. color: #222222;
  264. font-weight: bold;
  265. }
  266. .desc{
  267. font-size: 24rpx;
  268. color: #AAAAAA;
  269. overflow: hidden;
  270. text-overflow: ellipsis;
  271. white-space: nowrap;
  272. margin-top: 12rpx;
  273. }
  274. }
  275. .type-box{
  276. padding: 24rpx;
  277. background: #fff;
  278. margin-bottom: 20rpx;
  279. .type-title{
  280. font-size: 28rpx;
  281. color: #222222;
  282. }
  283. .type-list{
  284. display: flex;
  285. flex-wrap: wrap;
  286. justify-content: space-between;
  287. .type-item{
  288. width: 316rpx;
  289. height: 52rpx;
  290. text-align: center;
  291. line-height: 52rpx;
  292. background: #F0F0F0;
  293. border-radius: 26rpx 26rpx 26rpx 26rpx;
  294. font-weight: 300;
  295. font-size: 24rpx;
  296. color: #AAAAAA;
  297. margin-top: 28rpx;
  298. }
  299. .type-item.active{
  300. background: #EE4320;
  301. color: #FFFFFF;
  302. }
  303. }
  304. }
  305. .shop-limit{
  306. padding: 24rpx;
  307. background: #fff;
  308. display: flex;
  309. align-items: center;
  310. justify-content: space-between;
  311. margin-bottom: 20rpx;
  312. .info{
  313. .shop-name{
  314. font-size: 28rpx;
  315. color: #222222;
  316. }
  317. .address{
  318. font-size: 24rpx;
  319. color: #AAAAAA;
  320. margin-top: 16rpx;
  321. }
  322. }
  323. .num{
  324. display: flex;
  325. align-items: center;
  326. font-size: 24rpx;
  327. color: #AAAAAA;
  328. .icon{
  329. width: 48rpx;
  330. height: 48rpx;
  331. transform: rotate(-90deg);
  332. }
  333. }
  334. }
  335. .tab-group{
  336. display: flex;
  337. background: #fff;
  338. .tab{
  339. flex:1;
  340. padding: 24rpx 0;
  341. text-align: center;
  342. font-size: 28rpx;
  343. color: #222222;
  344. }
  345. .tab.active{
  346. font-weight: 600;
  347. }
  348. }
  349. .desc-box{
  350. .goods-desc{
  351. color: #222222;
  352. font-size: 24rpx;
  353. .img_class{
  354. max-width: 100%!important;
  355. vertical-align: bottom;
  356. }
  357. }
  358. }
  359. .list{
  360. background: #fff;
  361. .item{
  362. padding: 24rpx;
  363. border-top:1rpx solid #F0F0F0;
  364. .label{
  365. font-weight: 600;
  366. font-size: 28rpx;
  367. color: #222222;
  368. }
  369. .value{
  370. font-size: 24rpx;
  371. color: #AAAAAA;
  372. margin-top: 16rpx;
  373. line-height: 40rpx;
  374. }
  375. }
  376. }
  377. .buy-box{
  378. position: fixed;
  379. bottom: 0%;
  380. left: 0%;
  381. width: 100%;
  382. background: #fff;
  383. padding: 10rpx 24rpx 76rpx;
  384. display: flex;
  385. justify-content: space-between;
  386. box-sizing: border-box;
  387. .head{
  388. width: 80rpx;
  389. height: 80rpx;
  390. background: #aaa;
  391. border-radius: 50%;
  392. }
  393. .btn-box{
  394. display: flex;
  395. text-align: center;
  396. .group-btn{
  397. width: 280rpx;
  398. height: 80rpx;
  399. background: #6499FF;
  400. border-radius: 40rpx 0rpx 0rpx 40rpx;
  401. display: flex;
  402. flex-direction: column;
  403. justify-content: space-around;
  404. .label{
  405. font-weight: 600;
  406. font-size: 28rpx;
  407. color: #FFFFFF;
  408. }
  409. .price{
  410. font-size: 24rpx;
  411. color: #FFFFFF;
  412. }
  413. }
  414. .buy-btn.none{
  415. filter: grayscale(1);
  416. }
  417. .buy-btn{
  418. // width: 280rpx;
  419. width: 560rpx;
  420. height: 80rpx;
  421. background: $uni-color-primary;
  422. border-radius: 40rpx;
  423. // border-radius: 0rpx 40rpx 40rpx 0rpx;
  424. display: flex;
  425. flex-direction: column;
  426. justify-content: space-around;
  427. .label{
  428. font-weight: 600;
  429. font-size: 28rpx;
  430. color: #FFFFFF;
  431. }
  432. .price{
  433. font-size: 24rpx;
  434. color: #FFFFFF;
  435. }
  436. }
  437. }
  438. }
  439. }
  440. </style>