detail.vue 8.8 KB

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