integralGoodsDetails.vue 11 KB

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