detail.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view>
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="奖品详情"></u-navbar>
  4. <view class="detail">
  5. <view class="detail-top">
  6. <u-swiper :list="picUrlArr" height="375" radius="0" :indicator="true" :circular="true"></u-swiper>
  7. </view>
  8. <view class="detail-info">
  9. <view class="content" v-text="info.title"></view>
  10. </view>
  11. <view class="detail-title">商品详情</view>
  12. <view class="detail-description">
  13. <view class="" v-html="description"></view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import env from '../../config/env.js'
  20. import $http from '@/utils/request.js'
  21. export default {
  22. data() {
  23. return {
  24. boxId: '',
  25. picUrlArr: [],
  26. info: {},
  27. prizeList: [],
  28. description:'',
  29. payShow: false,
  30. payInfo: {}
  31. };
  32. },
  33. onLoad(opthios) {
  34. this.getDetail(opthios.id)
  35. },
  36. methods: {
  37. getDetail(id) {
  38. uni.showLoading({
  39. title: '加载中'
  40. });
  41. $http.post('/api/v1/mp/user/exchange/goods/detail', {
  42. noToken: true,
  43. goodsId: id
  44. }).then(res => {
  45. uni.hideLoading();
  46. if (res.code == 0) {
  47. this.info = res.data
  48. let picUrlArr = res.data.picUrl.split(',')
  49. picUrlArr.forEach(item => {
  50. this.picUrlArr.push(env.filePublic + item + '?imageView2/2/w/750')
  51. })
  52. // 处理富文本
  53. 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\"");
  54. this.description = this.formatRichText(description);
  55. }
  56. }).catch(() => {
  57. uni.hideLoading();
  58. })
  59. },
  60. close() {
  61. this.payShow = false
  62. },
  63. exchange() {
  64. let data = {
  65. couponIds: [],
  66. autoCoupon: 1,
  67. boxId: this.info.boxId,
  68. ticketId: this.info.ticketId,
  69. orderNum: 1
  70. }
  71. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  72. if (res.code == 0) {
  73. let info = {
  74. ...res.data,
  75. ...this.info,
  76. picUrl: env.filePublic + res.data.picUrl,
  77. }
  78. this.payInfo = info
  79. this.payShow = true
  80. }
  81. })
  82. },
  83. /**
  84. * 处理富文本里的图片宽度自适应
  85. * 1.去掉img标签里的style、width、height属性
  86. * 2.img标签添加style属性:max-width:100%;height:auto
  87. * 3.修改所有style里的width属性为max-width:100%
  88. * 4.去掉<br/>标签
  89. * @param html
  90. * @returns {void|string|*}
  91. */
  92. formatRichText(html) { //控制小程序中图片大小
  93. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  94. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  95. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  96. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  97. return match;
  98. });
  99. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  100. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
  101. 'max-width:100%;');
  102. return match;
  103. });
  104. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  105. newContent = newContent.replace(/\<img/gi,
  106. '<img style="max-width:100%;height:auto;margin:10rpx auto;"');
  107. return newContent;
  108. },
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .detail {
  114. &-info{
  115. padding: 50rpx 20rpx 50rpx;
  116. margin-bottom: 10rpx;
  117. background-color: #fff;
  118. .content{
  119. font-size: 32rpx;
  120. font-weight: bold;
  121. }
  122. }
  123. &-title{
  124. height: 88rpx;
  125. text-align: center;
  126. line-height: 88rpx;
  127. font-weight: bold;
  128. background-color: #FFFFFF;
  129. }
  130. &-description {
  131. image {
  132. width: 100%;
  133. }
  134. }
  135. }
  136. </style>