detail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view>
  3. <u-navbar title="兑换详情" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <view class="detail">
  5. <view class="detail-top">
  6. <u-swiper :list="picUrlArr" height="348" :indicator="true" :circular="true"></u-swiper>
  7. </view>
  8. <view class="detail-title">
  9. <view class="txt">{{ info.title }}</view>
  10. <view class="coin">
  11. <image src="../../static/logo.png" mode=""></image>
  12. <view>x {{ info.exchangePrice }}</view>
  13. </view>
  14. </view>
  15. <view class="detail-goods">商品详情</view>
  16. <view class="detail-description">
  17. <view class="" v-html="description"></view>
  18. </view>
  19. </view>
  20. <view class="footer-fixed">
  21. <view class="flex btn">
  22. <button type="default" @click="exChange">立即兑换</button>
  23. </view>
  24. </view>
  25. <!-- 兑换选择 -->
  26. <u-popup :show="choiceShow" mode="bottom" @close="close" :closeable="true">
  27. <view class="choiceShow-wrap">
  28. <view class="flex goods">
  29. <view class="flex image-wrap">
  30. <image src="../../static/logo.png" mode="aspectFill"></image>
  31. </view>
  32. <view class="info">
  33. <view class="info-title">Apple iPhone 13 (A2634) 128GB 星光色 支持移动联通电信5G 双卡双待手机</view>
  34. <view class="info-coin">
  35. <image src="../../static/logo.png" mode=""></image>
  36. <view>x 6800</view>
  37. </view>
  38. <view class="info-stock">库存:234</view>
  39. </view>
  40. </view>
  41. <view class="sku">
  42. <view class="sku-title">颜色</view>
  43. <view class="flex sku-list">
  44. <view class="sku-list-item">红色</view>
  45. <view class="sku-list-item">黑色</view>
  46. </view>
  47. </view>
  48. <view class="sku">
  49. <view class="sku-title">颜色</view>
  50. <view class="flex sku-list">
  51. <view class="sku-list-item">红色</view>
  52. <view class="sku-list-item">黑色</view>
  53. </view>
  54. </view>
  55. <view class="flex quantity">
  56. <view class="quantity-title">兑换数量</view>
  57. <view class="quantity-title">
  58. <u-number-box v-model="value" :min="1" @change="valChange"></u-number-box>
  59. </view>
  60. </view>
  61. <view class="flex btn">
  62. <view class="flex btn-left">
  63. <view class="title">应付:</view>
  64. <view class="flex coin">
  65. <image src="../../static/logo.png" mode=""></image>
  66. <view>x 6800</view>
  67. </view>
  68. </view>
  69. <view class="btn-right">
  70. <view class="confirm">立即兑换</view>
  71. </view>
  72. </view>
  73. </view>
  74. </u-popup>
  75. </view>
  76. </template>
  77. <script>
  78. import env from '../../config/env.js'
  79. import $http from '@/utils/request.js'
  80. export default {
  81. data() {
  82. return {
  83. boxId: '',
  84. picUrlArr: [],
  85. info: {},
  86. prizeList: [],
  87. description: '',
  88. choiceShow: false,
  89. value: 1,
  90. };
  91. },
  92. onLoad(opthios) {
  93. this.getDetail(opthios.id)
  94. },
  95. methods: {
  96. getDetail(id) {
  97. $http.post('/api/v1/mp/user/exchange/goods/detail', {
  98. goodsId: id
  99. }).then(res => {
  100. if (res.code == 0) {
  101. this.info = res.data
  102. let picUrlArr = res.data.picUrl.split(',')
  103. picUrlArr.forEach(item => {
  104. this.picUrlArr.push(env.filePublic + item)
  105. })
  106. // 处理富文本
  107. this.description = this.formatRichText(res.data.description);
  108. }
  109. })
  110. },
  111. exChange() {
  112. this.choiceShow = true
  113. },
  114. close() {
  115. this.choiceShow = false
  116. },
  117. valChange(e) {
  118. console.log(e);
  119. },
  120. /**
  121. * 处理富文本里的图片宽度自适应
  122. * 1.去掉img标签里的style、width、height属性
  123. * 2.img标签添加style属性:max-width:100%;height:auto
  124. * 3.修改所有style里的width属性为max-width:100%
  125. * 4.去掉<br/>标签
  126. * @param html
  127. * @returns {void|string|*}
  128. */
  129. formatRichText(html) { //控制小程序中图片大小
  130. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  131. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  132. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  133. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  134. return match;
  135. });
  136. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  137. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
  138. 'max-width:100%;');
  139. return match;
  140. });
  141. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  142. newContent = newContent.replace(/\<img/gi,
  143. '<img style="max-width:100%;height:auto;margin:10rpx auto;"');
  144. return newContent;
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. </style>
  151. <style lang="scss" scoped>
  152. .detail {
  153. padding-bottom: 100rpx;
  154. &-top {
  155. height: 696rpx;
  156. background-color: #FFFFFF;
  157. }
  158. &-title {
  159. padding: 24rpx;
  160. background-color: #FFFFFF;
  161. margin-bottom: 10rpx;
  162. .txt {
  163. font-size: 32rpx;
  164. line-height: 44rpx;
  165. overflow: hidden;
  166. text-overflow: ellipsis;
  167. display: -webkit-box;
  168. -webkit-box-orient: vertical;
  169. -webkit-line-clamp: 2;
  170. margin-bottom: 24rpx;
  171. font-weight: bold;
  172. }
  173. .coin {
  174. display: flex;
  175. align-items: center;
  176. font-size: 32rpx;
  177. line-height: 44rpx;
  178. color: rgba(235, 112, 9, 100);
  179. }
  180. image {
  181. width: 42rpx;
  182. height: 42rpx;
  183. margin-right: 20rpx;
  184. }
  185. }
  186. &-goods {
  187. height: 88rpx;
  188. text-align: center;
  189. line-height: 88rpx;
  190. font-weight: bold;
  191. background-color: #FFFFFF;
  192. }
  193. &-description {
  194. image{
  195. width: 100%;
  196. }
  197. }
  198. }
  199. .choiceShow-wrap {
  200. min-height: 400rpx;
  201. padding: 80rpx 20rpx 60rpx;
  202. .goods {
  203. justify-content: space-between;
  204. margin-bottom: 20rpx;
  205. .image-wrap {
  206. width: 220rpx;
  207. height: 220rpx;
  208. border: 1px solid rgba(236, 236, 236, 100);
  209. border-radius: 10rpx;
  210. image {
  211. width: 174rpx;
  212. height: 174rpx;
  213. }
  214. }
  215. .info {
  216. flex: 1;
  217. display: flex;
  218. flex-direction: column;
  219. justify-content: space-between;
  220. padding-left: 26rpx;
  221. &-title {
  222. font-size: 32rpx;
  223. line-height: 44rpx;
  224. font-weight: bold;
  225. }
  226. &-coin {
  227. display: flex;
  228. align-items: center;
  229. font-size: 32rpx;
  230. line-height: 44rpx;
  231. color: rgba(235, 112, 9, 100);
  232. font-weight: bold;
  233. image {
  234. width: 42rpx;
  235. height: 42rpx;
  236. margin-right: 20rpx;
  237. }
  238. }
  239. &-stock {
  240. line-height: 44rpx;
  241. }
  242. }
  243. }
  244. .sku {
  245. margin-bottom: 30rpx;
  246. &-title {
  247. line-height: 42rpx;
  248. }
  249. &-list {
  250. justify-content: flex-start;
  251. &-item {
  252. line-height: 44rpx;
  253. padding: 0 20rpx;
  254. border: 1px solid rgba(187, 187, 187, 100);
  255. margin-left: 36rpx;
  256. }
  257. &-item:first-child {
  258. margin-left: 0;
  259. }
  260. }
  261. }
  262. .quantity {
  263. justify-content: space-between;
  264. margin-bottom: 40rpx;
  265. }
  266. .btn {
  267. justify-content: space-between;
  268. &-left {
  269. .coin {
  270. display: flex;
  271. align-items: center;
  272. font-size: 32rpx;
  273. line-height: 44rpx;
  274. color: rgba(235, 112, 9, 100);
  275. font-weight: bold;
  276. margin-left: 20rpx;
  277. image {
  278. width: 42rpx;
  279. height: 42rpx;
  280. margin-right: 20rpx;
  281. }
  282. }
  283. }
  284. &-right {
  285. .confirm {
  286. width: 250rpx;
  287. height: 60rpx;
  288. line-height: 60rpx;
  289. border-radius: 8px;
  290. background-color: rgba(235, 112, 9, 100);
  291. color: rgba(255, 255, 255, 100);
  292. font-size: 28rpx;
  293. text-align: center;
  294. }
  295. }
  296. }
  297. }
  298. .footer-fixed {
  299. position: fixed;
  300. bottom: var(--window-bottom);
  301. left: 0;
  302. right: 0;
  303. z-index: 11;
  304. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  305. background: #fff;
  306. // 设置ios刘海屏底部横线安全区域
  307. padding-bottom: constant(safe-area-inset-bottom);
  308. padding-bottom: env(safe-area-inset-bottom);
  309. .btn {
  310. padding: 20rpx 40rpx;
  311. /deep/ button {
  312. width: 100%;
  313. line-height: 60rpx;
  314. font-size: 28rpx;
  315. height: 60rpx;
  316. color: #fff;
  317. background-color: $uni-bg-color;
  318. border: none;
  319. border-radius: 100rpx;
  320. }
  321. }
  322. }
  323. </style>