integralGoodsDetails.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <template>
  2. <view class="content">
  3. <view class="cont-box">
  4. <view class="goods-banner" @click="showImg()">
  5. <view class="cartbox x-c" @click.stop="goCart()">
  6. <view class="box">
  7. <u-badge type="error" max="99" :value="cartNum" bgColor="#2583EB"></u-badge>
  8. </view>
  9. <u-icon name="shopping-cart" color="#2583EB" size="68rpx"></u-icon>
  10. </view>
  11. <swiper
  12. class="swiper"
  13. :indicator-dots="false"
  14. :circular="true"
  15. :autoplay="true"
  16. :interval="3000"
  17. :duration="1000"
  18. indicator-color="rgba(255, 255, 255, 0.6)"
  19. indicator-active-color="#ffffff"
  20. @change="swiperChange"
  21. >
  22. <swiper-item class="swiper-item" v-for="(item,index) in imgs" :key="index">
  23. <image :src="item" mode="aspectFit"></image>
  24. </swiper-item>
  25. </swiper>
  26. <!-- 数量 -->
  27. <view class="num-box">{{ activeImg }}/{{ imgs.length }}</view>
  28. </view>
  29. <view class="integral-box">
  30. <view class="title">{{item.goodsName}}</view>
  31. <view class="num-box">
  32. <view class="price" >{{item.integral}} 健康币</view>
  33. <view class="count">原价:{{item.otPrice.toFixed(2)}}元</view>
  34. </view>
  35. </view>
  36. <view class="desc-box">
  37. <view class="desc" v-html="item.descs" >
  38. </view>
  39. </view>
  40. </view>
  41. <view class="btn-foot">
  42. <view class="p-price-box">
  43. <view class="p-name">兑换健康币</view>
  44. <view class="p-price" >{{item.integral}}</view>
  45. </view>
  46. <view class="btn-box">
  47. <view class="btn add" @click="openPop">
  48. 加入购物车
  49. </view>
  50. <view class="btn buy" @click="submit()" >
  51. 立即兑换
  52. </view>
  53. </view>
  54. </view>
  55. <u-popup :show="show" mode="bottom" closeable @close="close">
  56. <view class="popbox">
  57. <view class="x-f">
  58. <image class="popbox-img" :src="item.imgUrl" mode="aspectFill"></image>
  59. <view class="info-text">
  60. <view class="price">
  61. <text class="unit">¥</text>
  62. <text class="num">{{item.otPrice}}</text>
  63. <!-- <text class="oldprice"> ¥{{item.otPrice}}</text> -->
  64. </view>
  65. <view class="text es-mt-16">所需积分:{{item.integral}}</view>
  66. <view class="desc-box es-mt-16">
  67. <text class="text">库存:{{item.stock>0?item.stock:'售罄'}} </text>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 数量 -->
  72. <view class="price-num x-bc" style="margin-top: 30rpx;">
  73. <view class="label">数量</view>
  74. <view class="num-box">
  75. <u-number-box v-model="num" integer :step="1" :min="1" :max="100000"></u-number-box>
  76. </view>
  77. </view>
  78. <view class="es-max-btn x-c" @click="addCart">
  79. 加入购物车
  80. </view>
  81. </view>
  82. </u-popup>
  83. </view>
  84. </template>
  85. <script>
  86. import {getIntegralGoodsById,createOrder,addGoodsIntoCart,getFsIntegralCartList} from '@/api/integral.js'
  87. export default {
  88. data() {
  89. return {
  90. imgs:[],
  91. activeImg: 1,
  92. goodsId:null,
  93. item: {
  94. cash: 0,
  95. otPrice: 0,
  96. integral: 0,
  97. goodsName: '',
  98. imgUrl: '',
  99. stock: 0,
  100. descs: ''
  101. },
  102. show: false,
  103. num: 1,
  104. cartNum: 0
  105. };
  106. },
  107. onLoad(option) {
  108. this.goodsId=option.goodsId;
  109. },
  110. onShow() {
  111. this.getIntegralGoodsById();
  112. this.getcartNum()
  113. },
  114. methods:{
  115. goCart() {
  116. uni.navigateTo({
  117. url: '/pages/user/integral/cart'
  118. })
  119. },
  120. getcartNum() {
  121. var data={
  122. pageNum: 1,
  123. pageSize: 10
  124. }
  125. getFsIntegralCartList().then(res => {
  126. if (res.code == 200) {
  127. this.cartNum = res.data.total ||0
  128. }
  129. })
  130. },
  131. close() {
  132. this.show = false
  133. },
  134. openPop() {
  135. this.num = 1
  136. this.show = true
  137. },
  138. addCart() {
  139. if(this.cartNum>=this.item.stock){
  140. uni.showToast({
  141. title: '库存不足',
  142. icon: 'none'
  143. })
  144. this.show = false
  145. return;
  146. }
  147. uni.showLoading({
  148. title: '处理中'
  149. })
  150. addGoodsIntoCart({
  151. quantity: this.num,
  152. goodsId: this.goodsId,
  153. isSelected: 0
  154. }).then(res => {
  155. uni.hideLoading()
  156. if (res.code == 200) {
  157. this.show = false
  158. uni.showToast({
  159. title: "添加成功",
  160. icon: 'none'
  161. })
  162. this.getcartNum()
  163. } else {
  164. uni.showToast({
  165. title: res.msg,
  166. icon: 'none'
  167. })
  168. }
  169. })
  170. },
  171. submit(){
  172. uni.navigateTo({
  173. url: "./integralOrderPay?goodsId="+this.goodsId
  174. })
  175. },
  176. swiperChange(event) {
  177. this.activeImg = event.detail.current + 1
  178. },
  179. showImg() {
  180. //预览图片
  181. uni.previewImage({
  182. urls: this.imgs,
  183. current: this.imgs[0]
  184. });
  185. },
  186. getIntegralGoodsById(){
  187. let data = {goodsId:this.goodsId};
  188. getIntegralGoodsById(data).then(
  189. res => {
  190. if(res.code==200){
  191. this.item=res.data;
  192. if(res.data.images!=null){
  193. this.imgs=res.data.images.split(",")
  194. }
  195. else{
  196. this.activeImg=0;
  197. }
  198. console.log(this.imgs)
  199. }else{
  200. uni.showToast({
  201. icon:'none',
  202. title: "请求失败",
  203. });
  204. }
  205. },
  206. rej => {}
  207. );
  208. },
  209. }
  210. }
  211. </script>
  212. <style lang="scss">
  213. page{
  214. height: 100%;
  215. }
  216. .cartbox {
  217. position: fixed;
  218. bottom: 180rpx;
  219. right: 20rpx;
  220. z-index: 99;
  221. background-color: #fff;
  222. box-shadow: 0 2px 4px rgba(150, 150, 150, 0.6);
  223. padding: 10rpx;
  224. border-radius: 50%;
  225. .box {
  226. position: absolute;
  227. top: -10rpx;
  228. right: 0;
  229. z-index: 99;
  230. }
  231. }
  232. .content{
  233. height: 100%;
  234. display: flex;
  235. flex-direction: column;
  236. .cont-box{
  237. padding-bottom: 121rpx;
  238. .integral-box{
  239. background-color: #fff;
  240. padding: 20rpx;
  241. width: 100%;
  242. display: flex;
  243. flex-direction: column;
  244. align-items: flex-start;
  245. justify-content: flex-start;
  246. .title{
  247. font-weight: bold;
  248. font-size: 34upx;
  249. font-family: PingFang SC;
  250. color: #111;
  251. }
  252. .desc{
  253. margin-top: 15rpx;
  254. display: flex;
  255. align-items: flex-start;
  256. justify-content: flex-start;
  257. .cycle{
  258. background-color: #eee;
  259. border-radius: 30rpx;
  260. padding: 5rpx 15rpx;
  261. font-size: 26upx;
  262. font-family: PingFang SC;
  263. color: #2583EB;
  264. }
  265. .duration{
  266. margin-left: 10rpx;
  267. background-color: #eee;
  268. border-radius: 30rpx;
  269. padding: 5rpx 15rpx;
  270. font-size: 26upx;
  271. font-family: PingFang SC;
  272. color: #2583EB;
  273. }
  274. }
  275. .num-box{
  276. margin-top: 15rpx;
  277. flex: 1;
  278. display: flex;
  279. align-items: flex-end;
  280. justify-content: space-between;
  281. width: 100%;
  282. .price{
  283. padding: 5rpx 10rpx;
  284. background-color: #2583EB;
  285. border-radius: 30rpx;
  286. font-size: 20upx;
  287. font-family: PingFang SC;
  288. color: #ffffff;
  289. }
  290. .count{
  291. font-size: 24upx;
  292. font-family: PingFang SC;
  293. color: #333333;
  294. }
  295. }
  296. }
  297. .desc-box{
  298. background-color: #fff;
  299. padding: 20rpx;
  300. margin-top: 10rpx;
  301. .title-box{
  302. display: flex;
  303. flex-direction: row;
  304. align-items: center;
  305. justify-content: flex-start;
  306. .title{
  307. font-size: 32upx;
  308. font-family: PingFang SC;
  309. font-weight: bold;
  310. color: #111111;
  311. }
  312. .line{
  313. margin-right: 15rpx;
  314. height: 30rpx;
  315. width: 6rpx;
  316. background-color: #2583EB;
  317. }
  318. }
  319. .desc{
  320. margin-top: 15rpx;
  321. font-size: 28upx;
  322. font-family: PingFang SC;
  323. color: #9a9a9c;
  324. }
  325. }
  326. }
  327. }
  328. .btn-foot{
  329. box-sizing: border-box;
  330. width: 100%;
  331. height: 121upx;
  332. background: #FFFFFF;
  333. padding: 0 32upx 0 28upx;
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. position: fixed;
  338. left: 0;
  339. bottom: 0;
  340. z-index: 99;
  341. .p-price-box{
  342. display: flex;
  343. align-items:flex-start;
  344. flex-direction: column;
  345. .p-name{
  346. font-size: 28upx;
  347. font-family: PingFang SC;
  348. font-weight: 500;
  349. color: #666666;
  350. }
  351. .p-price{
  352. //margin-left: 10rpx;
  353. color: #FF6633;
  354. font-size: 32upx;
  355. font-family: PingFang SC;
  356. font-weight: bold;
  357. }
  358. }
  359. .btn-box{
  360. display: flex;
  361. align-items: center;
  362. .btn{
  363. width: 200upx;
  364. height: 88upx;
  365. line-height: 88upx;
  366. text-align: center;
  367. border-radius: 44upx;
  368. margin-left: 20upx;
  369. font-size: 30upx;
  370. font-family: PingFang SC;
  371. font-weight: bold;
  372. color: #FFFFFF;
  373. &:first-child{
  374. margin-left: 0;
  375. }
  376. &.buy{
  377. background: #2583EB;
  378. }
  379. &.add{
  380. color:#2583EB !important;
  381. border: 1rpx solid #2583EB;
  382. }
  383. }
  384. }
  385. }
  386. .goods-banner{
  387. height: 756upx;
  388. background-color: #FFFFFF;
  389. position: relative;
  390. .swiper-item{
  391. box-sizing: border-box;
  392. }
  393. .swiper,
  394. .swiper-item,
  395. .swiper-item image{
  396. width: 100%;
  397. height: 100%;
  398. }
  399. .num-box{
  400. width: 80upx;
  401. height: 44upx;
  402. line-height: 44upx;
  403. text-align: center;
  404. font-size: 24upx;
  405. font-family: PingFang SC;
  406. font-weight: 500;
  407. color: #FFFFFF;
  408. background: rgba(0, 0, 0, .3);
  409. border-radius: 22upx;
  410. position: absolute;
  411. right: 30upx;
  412. bottom: 30upx;
  413. z-index: 10;
  414. }
  415. }
  416. .popbox {
  417. padding: 40rpx 32rpx;
  418. &-img {
  419. width: 200rpx;
  420. height: 200rpx;
  421. border-radius: 20rpx;
  422. margin-right: 24rpx;
  423. }
  424. .oldprice {
  425. font-size: 28rpx;
  426. font-family: PingFang SC;
  427. font-weight: 500;
  428. color: #999999;
  429. margin-top: 27rpx;
  430. line-height: 1;
  431. text-decoration: line-through;
  432. margin-left: 24rpx;
  433. }
  434. .info-text {
  435. height: 200rpx;
  436. .price {
  437. display: flex;
  438. align-items: flex-end;
  439. .unit {
  440. font-size: 32rpx;
  441. font-family: PingFang SC;
  442. font-weight: bold;
  443. color: #2583EB;
  444. line-height: 1.2;
  445. margin-right: 10rpx;
  446. }
  447. .num {
  448. font-size: 50rpx;
  449. font-family: PingFang SC;
  450. font-weight: bold;
  451. color: #2583EB;
  452. line-height: 1;
  453. }
  454. }
  455. .text {
  456. font-size: 28rpx;
  457. font-family: PingFang SC;
  458. font-weight: 400;
  459. color: #2583EB;
  460. }
  461. .desc-box {
  462. display: flex;
  463. flex-direction: column;
  464. padding-bottom: 9rpx;
  465. .text {
  466. font-size: 28rpx;
  467. font-family: PingFang SC;
  468. font-weight: 500;
  469. color: #999999;
  470. margin-top: 27rpx;
  471. line-height: 1;
  472. &:first-child {
  473. margin-top: 0;
  474. }
  475. }
  476. }
  477. }
  478. }
  479. .es-max-btn {
  480. width: 100%;
  481. background-color: #2583EB;
  482. border-radius: 60rpx;
  483. margin-top: 50rpx;
  484. color: #fff;
  485. padding: 20rpx 0;
  486. box-sizing: border-box;
  487. }
  488. </style>