detail.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 style="detail-merchant" @click="toCompanyData" v-if="info.merchantInfo?true:false">
  16. <view class="detail-merchant-warp">
  17. <view class="detail-merchant-warp-one">商家信息</view>
  18. <view class="detail-merchant-warp-two">
  19. <view style="float: left;">前往查看</view>
  20. <u-icon style="float: right;" name="arrow-right" size="18"></u-icon>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import env from '../../config/env.js'
  29. import $http from '@/utils/request.js'
  30. export default {
  31. data() {
  32. return {
  33. boxId: '',
  34. picUrlArr: [],
  35. info: {},
  36. prizeList: [],
  37. description: '',
  38. goodsId: '',
  39. payShow: false,
  40. payInfo: {}
  41. };
  42. },
  43. onLoad(opthios) {
  44. this.getDetail(opthios.id)
  45. this.goodsId = opthios.id
  46. },
  47. methods: {
  48. getDetail(id) {
  49. uni.showLoading({
  50. title: '加载中'
  51. });
  52. $http.post('/api/v1/mp/user/exchange/goods/detail', {
  53. noToken: true,
  54. goodsId: id
  55. }).then(res => {
  56. uni.hideLoading();
  57. if (res.code == 0) {
  58. this.info = res.data
  59. let picUrlArr = res.data.picUrl.split(',')
  60. picUrlArr.forEach(item => {
  61. this.picUrlArr.push(env.filePublic + item + '?imageView2/2/w/750')
  62. })
  63. // 处理富文本
  64. const description = res.data.description.replaceAll(".jpg\"", ".jpg?imageView2/2/w/750\"")
  65. .replaceAll(".jpeg\"", ".jpeg?imageView2/2/w/750\"").replaceAll(".png\"",
  66. ".png?imageView2/2/w/750\"");
  67. this.description = this.formatRichText(description);
  68. }
  69. }).catch(() => {
  70. uni.hideLoading();
  71. })
  72. },
  73. close() {
  74. this.payShow = false
  75. },
  76. exchange() {
  77. let data = {
  78. couponIds: [],
  79. autoCoupon: 1,
  80. boxId: this.info.boxId,
  81. ticketId: this.info.ticketId,
  82. orderNum: 1
  83. }
  84. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  85. if (res.code == 0) {
  86. let info = {
  87. ...res.data,
  88. ...this.info,
  89. picUrl: env.filePublic + res.data.picUrl,
  90. }
  91. this.payInfo = info
  92. this.payShow = true
  93. }
  94. })
  95. },
  96. toCompanyData(){
  97. uni.navigateTo({
  98. url:`/pages/goods/company?goodsId=${ this.goodsId }`
  99. })
  100. },
  101. /**
  102. * 处理富文本里的图片宽度自适应
  103. * 1.去掉img标签里的style、width、height属性
  104. * 2.img标签添加style属性:max-width:100%;height:auto
  105. * 3.修改所有style里的width属性为max-width:100%
  106. * 4.去掉<br/>标签
  107. * @param html
  108. * @returns {void|string|*}
  109. */
  110. formatRichText(html) { //控制小程序中图片大小
  111. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  112. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  113. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  114. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  115. return match;
  116. });
  117. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  118. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
  119. 'max-width:100%;');
  120. return match;
  121. });
  122. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  123. newContent = newContent.replace(/\<img/gi,
  124. '<img style="max-width:100%;height:auto;margin:10rpx auto;"');
  125. return newContent;
  126. },
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .detail {
  132. &-info {
  133. padding: 50rpx 20rpx 50rpx;
  134. margin-bottom: 10rpx;
  135. background-color: #fff;
  136. .content {
  137. font-size: 32rpx;
  138. font-weight: bold;
  139. }
  140. }
  141. &-title {
  142. height: 88rpx;
  143. text-align: center;
  144. line-height: 88rpx;
  145. font-weight: bold;
  146. background-color: #FFFFFF;
  147. }
  148. &-description {
  149. image {
  150. width: 100%;
  151. }
  152. }
  153. &-merchant {
  154. height: 88rpx;
  155. // text-align: center;
  156. line-height: 88rpx;
  157. font-weight: bold;
  158. background-color: #FFFFFF;
  159. &-warp {
  160. height: 88rpx;
  161. width: 100%;
  162. background-color: #ffffff;
  163. &-one {
  164. float: left;
  165. margin: 20rpx;
  166. font-weight: 600;
  167. }
  168. &-two {
  169. float: right;
  170. margin: 20rpx;
  171. font-weight: 600;
  172. }
  173. }
  174. }
  175. // 设置ios刘海屏底部横线安全区域
  176. padding-bottom: constant(safe-area-inset-bottom);
  177. padding-bottom: env(safe-area-inset-bottom);
  178. }
  179. </style>