detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar title="商品详情" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0"/>
  5. <!-- #endif -->
  6. <!-- #ifdef MP-WEIXIN -->
  7. <u-navbar title="商品详情" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  8. <!-- #endif -->
  9. <!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
  10. <view v-if="$pagesNum() > 1">
  11. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="商品详情" />
  12. </view>
  13. <view v-else>
  14. <u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff" :border="true" title="商品详情">
  15. <view class="nav-left flex" slot="left" @click="$toIndex()">
  16. <u-icon name="arrow-left" size="20" color="#333"></u-icon>
  17. </view>
  18. </u-navbar>
  19. </view>
  20. <!-- #endif -->
  21. <view class="detail">
  22. <!-- 商品轮播 -->
  23. <view class="detail-swiper">
  24. <u-swiper :list="picUrlArr" height="375" radius="0" :indicator="true" :circular="true" indicatorMode="dot" indicatorActiveColor="#FA822C"></u-swiper>
  25. </view>
  26. <!-- 详情 -->
  27. <view class="detail-info flex">
  28. <view class="detail-info-left">
  29. <view class="detail-info-left__title ells">{{ info.title }}</view>
  30. <view class="detail-info-left__coin">
  31. <view class="content flex">
  32. <image src="../../static/public/goods_coin.png" mode="scaleToFill"></image>
  33. <view class="coin"><text>×</text>{{ info.exchangePrice }}</view>
  34. </view>
  35. <view class="txt" v-if="info.originPrice">原盲豆:<text>{{ info.originPrice }}</text></view>
  36. </view>
  37. <view class="detail-info-left__price">¥{{ $numberFormat(info.value) }}</view>
  38. </view>
  39. <!-- <view class="detail-info-right" v-show="false">销量:30个</view> -->
  40. </view>
  41. <view class="detail-goods">产品介绍</view>
  42. <view class="detail-description">
  43. <u-parse :content="description" :selectable="true"></u-parse>
  44. </view>
  45. <view style="detail-merchant" @click="toCompanyData" v-if="info.merchantInfo?true:false">
  46. <view class="detail-merchant-warp">
  47. <view class="detail-merchant-warp-one">商家信息</view>
  48. <view class="detail-merchant-warp-two">
  49. <view style="float: left;">前往查看</view>
  50. <u-icon style="float: right;" name="arrow-right" size="18"></u-icon>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="footer-fixed">
  56. <view class="footer-fixed-content flex">
  57. <!-- <button type="default">立即兑换</button> -->
  58. <view class="footer-fixed-content__coin flex">
  59. <text>我的盲豆:</text>
  60. <text>{{ initData.coinNum ? `${ initData.coinNum }个` : '--' }}</text>
  61. </view>
  62. <view class="footer-fixed-content__exchange flex" @click="exChange">
  63. <text>{{ info.exchangePrice }}个</text>
  64. <text>盲豆兑换</text>
  65. </view>
  66. <!-- #ifndef MP-ALIPAY -->
  67. <view class="footer-fixed-content__price flex" @click="purchase">
  68. <text>立即购买</text>
  69. </view>
  70. <!-- #endif -->
  71. </view>
  72. </view>
  73. <!-- 兑换选择 -->
  74. <!-- 兑换成功 -->
  75. <u-popup :show="tipShow" mode="center">
  76. <view class="tip-show">
  77. <view class="flex tip-show-title">
  78. <u-icon name="checkmark-circle" color="#EB7009" size="24"></u-icon>
  79. <text>兑换成功,已放入仓库</text>
  80. </view>
  81. <view class="flex tip-show-btn">
  82. <view class="close" @click="tipShow = false">关闭</view>
  83. <navigator class="prize" :url="`/packagePrize/prize/index`" hover-class="navigator-hover"
  84. @click="tipShow = false">前往查看</navigator>
  85. </view>
  86. </view>
  87. </u-popup>
  88. <!-- 商品兑换 -->
  89. <exchange-popop
  90. :popup-show="exchangePopupShow"
  91. :detailInfo="info"
  92. :popup-info="payInfo"
  93. :sku-list-init="skuListInit"
  94. :sku-list-popup="skuList"
  95. @close="close"
  96. @success="exchangeSuccess"
  97. v-if="exchangePopupShow"
  98. />
  99. <!-- 商品购买 -->
  100. <purchase-popup
  101. :popup-show="purchasePopupShow"
  102. :detailInfo="info"
  103. :popup-info="payInfo"
  104. :sku-list-init="skuListInit"
  105. :sku-list-popup="skuList"
  106. @close="close"
  107. @success="purchaseSuccess"
  108. v-if="purchasePopupShow"
  109. />
  110. </view>
  111. </template>
  112. <script>
  113. import env from '../../config/env.js'
  114. import $http from '@/utils/request.js'
  115. import { formatRichText } from '@/utils/util.js'
  116. import ExchangePopop from '../components/exchange-popup/exchange-popup.vue'
  117. import PurchasePopup from '../components/purchase-popup/purchase-popup.vue'
  118. export default {
  119. components: {
  120. ExchangePopop,
  121. PurchasePopup
  122. },
  123. data() {
  124. return {
  125. goodsId: '',
  126. boxId: '',
  127. picUrlArr: [],
  128. info: {},
  129. prizeList: [],
  130. description: '',
  131. choiceShow: false,
  132. initData: {},
  133. orderNum: 1,
  134. skuList: [],
  135. skuListInit: [],
  136. payInfo: {},
  137. tipShow: false,
  138. exchangePopupShow: false,
  139. purchasePopupShow: false
  140. };
  141. },
  142. onLoad(opthios) {
  143. this.goodsId = opthios.id
  144. },
  145. onShow() {
  146. this.getDetail()
  147. if(uni.getStorageSync('token')) {
  148. this.getBean()
  149. }
  150. },
  151. methods: {
  152. getDetail() {
  153. uni.showLoading({
  154. title: '加载中'
  155. });
  156. $http.post('/api/v1/mp/user/exchange/goods/detail', {
  157. goodsId: this.goodsId,
  158. noToken: true
  159. }).then(res => {
  160. uni.hideLoading();
  161. if (res.code == 0) {
  162. this.info = res.data
  163. let picUrlArr = res.data.picUrl.split(',')
  164. picUrlArr.forEach(item => {
  165. this.picUrlArr.push(env.filePublic + item + '?imageView2/2/w/750')
  166. })
  167. // 处理富文本
  168. // #ifndef MP-ALIPAY
  169. const description = res.data.description.replaceAll(".jpg\"", ".jpg?imageView2/2/w/750\"").replaceAll(".jpeg\"", ".jpeg?imageView2/2/w/750\"").replaceAll(".png\"",".png?imageView2/2/w/750\"");
  170. this.description = formatRichText(description);
  171. // #endif
  172. // #ifdef MP-ALIPAY
  173. res.data.description.split(".jpg\"").join(".jpg?imageView2/2/w/750\"")
  174. res.data.description.split(".jpeg\"").join(".jpeg?imageView2/2/w/750\"")
  175. res.data.description.split(".png\"").join(".png?imageView2/2/w/750\"")
  176. this.description = formatRichText(res.data.description);
  177. // #endif
  178. this.skuListInit = res.data.skuList
  179. if (res.data.skuList.length) {
  180. let skuProp = JSON.parse(res.data.skuProp)
  181. skuProp.forEach(item => {
  182. item.actionIndex = 0,
  183. item.txt = `${item.name}:${item.value[0]}`
  184. })
  185. let actionSku = skuProp.map(item => {
  186. return item.txt
  187. }).join(';')
  188. let sku = res.data.skuList.find(item => {
  189. return item.properties == actionSku
  190. })
  191. this.payInfo = {
  192. ...sku,
  193. exValue: sku.exchangePrice,
  194. price: sku.value,
  195. picUrl: env.filePublic + sku.picUrl
  196. }
  197. this.skuList = skuProp
  198. } else {
  199. this.payInfo = {
  200. ...res.data,
  201. price: this.info.value,
  202. exValue: this.info.exchangePrice,
  203. picUrl: this.picUrlArr[0]
  204. }
  205. }
  206. }
  207. }).catch(() => {
  208. uni.hideLoading();
  209. })
  210. },
  211. getBean() {
  212. uni.showLoading({
  213. title: '加载中'
  214. });
  215. $http.post('/api/v1/mp/user/mine/init', {}).then(res => {
  216. uni.hideLoading();
  217. if (res.code == 0) {
  218. this.initData = res.data
  219. }
  220. }).catch(() => {
  221. uni.hideLoading();
  222. })
  223. },
  224. exChange() {
  225. this.exchangePopupShow = true
  226. this.getBean()
  227. },
  228. purchase() {
  229. this.purchasePopupShow = true
  230. },
  231. close() {
  232. this.exchangePopupShow = false
  233. this.purchasePopupShow = false
  234. },
  235. exchangeSuccess() {
  236. this.close()
  237. this.tipShow = true
  238. this.getBean()
  239. this.getDetail()
  240. },
  241. purchaseSuccess() {
  242. this.close()
  243. },
  244. toCompanyData(){
  245. uni.navigateTo({
  246. url:`/packageGoods/goods/company?goodsId=${ this.goodsId }`
  247. })
  248. },
  249. }
  250. }
  251. </script>
  252. <style lang="scss" scoped>
  253. </style>
  254. <style lang="scss" scoped>
  255. .detail {
  256. padding-bottom: 180rpx;
  257. // 商品轮播
  258. &-swiper {
  259. background-color: #FFFFFF;
  260. }
  261. // 详情
  262. &-info {
  263. background-color: #fff;
  264. justify-content: space-between;
  265. padding: 34rpx;
  266. margin-bottom: 22rpx;
  267. &-left {
  268. width: 100%;
  269. flex: 1;
  270. &__title {
  271. width: 100%;
  272. font-size: 34rpx;
  273. line-height: 40rpx;
  274. margin-bottom: 26rpx;
  275. font-weight: bold;
  276. }
  277. &__coin {
  278. display: flex;
  279. line-height: 30rpx;
  280. margin-bottom: 26rpx;
  281. font-size: 26rpx;
  282. .content {
  283. color: #FA822C;
  284. margin-right: 34rpx;
  285. font-weight: bold;
  286. image {
  287. width: 34rpx;
  288. height: 30rpx;
  289. }
  290. text {
  291. font-weight: normal;
  292. }
  293. .coin {
  294. font-size: 30rpx;
  295. }
  296. }
  297. .txt {
  298. font-size: 26rpx;
  299. color: #666666;
  300. text-decoration: line-through;
  301. }
  302. }
  303. &__price {
  304. line-height: 24rpx;
  305. color: #666666;
  306. }
  307. }
  308. &-right {
  309. color: #666666;
  310. }
  311. }
  312. &-goods {
  313. height: 90rpx;
  314. text-align: center;
  315. line-height: 90rpx;
  316. font-weight: bold;
  317. font-size: 30rpx;
  318. background-color: #FFFFFF;
  319. }
  320. &-merchant {
  321. height: 88rpx;
  322. // text-align: center;
  323. line-height: 88rpx;
  324. font-weight: bold;
  325. background-color: #FFFFFF;
  326. &-warp {
  327. height: 88rpx;
  328. width: 100%;
  329. background-color: #ffffff;
  330. // margin-top: 10rpx;
  331. &-one {
  332. float: left;
  333. margin: 20rpx;
  334. font-weight: 600;
  335. }
  336. &-two {
  337. float: right;
  338. margin: 20rpx;
  339. font-weight: 600;
  340. }
  341. }
  342. }
  343. &-description {
  344. image {
  345. width: 100%;
  346. }
  347. }
  348. }
  349. .tip-show {
  350. width: 80vw;
  351. background-color: #FFFFFF;
  352. border-radius: 10rpx;
  353. padding: 60rpx 40rpx;
  354. &-title {
  355. margin-bottom: 64rpx;
  356. text {
  357. margin-left: 20rpx;
  358. }
  359. }
  360. &-btn {
  361. justify-content: space-around;
  362. .close {
  363. width: 160rpx;
  364. height: 60rpx;
  365. line-height: 60rpx;
  366. border-radius: 8rpx;
  367. color: rgba(235, 112, 9, 100);
  368. font-size: 28rpx;
  369. text-align: center;
  370. border: 1px solid rgba(235, 112, 9, 100);
  371. }
  372. .prize {
  373. width: 160rpx;
  374. height: 60rpx;
  375. line-height: 60rpx;
  376. border-radius: 8rpx;
  377. color: rgba(235, 112, 9, 100);
  378. font-size: 28rpx;
  379. text-align: center;
  380. background-color: rgba(235, 112, 9, 100);
  381. color: rgba(255, 255, 255, 100);
  382. font-size: 14px;
  383. }
  384. }
  385. }
  386. .footer-fixed {
  387. position: fixed;
  388. bottom: var(--window-bottom);
  389. left: 0;
  390. right: 0;
  391. z-index: 11;
  392. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  393. background: #fff;
  394. // 设置ios刘海屏底部横线安全区域
  395. padding-bottom: constant(safe-area-inset-bottom);
  396. padding-bottom: env(safe-area-inset-bottom);
  397. &-content {
  398. justify-content: flex-start;
  399. height: 132rpx;
  400. background-color: #fff;
  401. &__coin {
  402. height: 100%;
  403. flex: 1;
  404. font-size: 30rpx;
  405. text:first-child {
  406. color: #999;
  407. }
  408. }
  409. &__exchange {
  410. height: 100%;
  411. flex-direction: column;
  412. padding: 0 50rpx;
  413. background-color: #FA822C;
  414. color: #fff;
  415. text {
  416. font-weight: normal;
  417. font-size: 26rpx;
  418. }
  419. text:last-child {
  420. font-weight: bold;
  421. font-size: 30rpx;
  422. line-height: 40rpx;
  423. }
  424. }
  425. &__price {
  426. font-size: 30rpx;
  427. font-weight: bold;
  428. height: 100%;
  429. padding: 0 50rpx;
  430. background-color: #FA362C;
  431. color: #fff;
  432. }
  433. }
  434. }
  435. </style>