studyGoodsDetail.vue 8.1 KB

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