integralGoodsDetails.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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="#2BC7B9"></u-badge>
  8. </view>
  9. <u-icon name="shopping-cart" color="#2BC7B9" 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. this.utils.isLogin().then(
  171. res => {
  172. if (res) {
  173. uni.navigateTo({
  174. url: "./integralOrderPay?goodsId=" + this.goodsId
  175. })
  176. } else {
  177. uni.navigateTo({
  178. url: '/pages/auth/login'
  179. })
  180. }
  181. }
  182. );
  183. },
  184. swiperChange(event) {
  185. this.activeImg = event.detail.current + 1
  186. },
  187. showImg() {
  188. //预览图片
  189. uni.previewImage({
  190. urls: this.imgs,
  191. current: this.imgs[0]
  192. });
  193. },
  194. getIntegralGoodsById() {
  195. let data = {
  196. goodsId: this.goodsId
  197. };
  198. getIntegralGoodsById(data).then(
  199. res => {
  200. if (res.code == 200) {
  201. this.items = res.data;
  202. console.log("全部是", this.items)
  203. if (res.data.images != null) {
  204. this.imgs = res.data.images.split(",")
  205. } else {
  206. this.activeImg = 0;
  207. }
  208. console.log(this.imgs)
  209. } else {
  210. uni.showToast({
  211. icon: 'none',
  212. title: "请求失败",
  213. });
  214. }
  215. },
  216. rej => {}
  217. );
  218. },
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. page {
  224. height: 100%;
  225. }
  226. .cartbox {
  227. position: fixed;
  228. bottom: 180rpx;
  229. right: 20rpx;
  230. z-index: 99;
  231. background-color: #fff;
  232. box-shadow: 0 2px 4px rgba(150, 150, 150, 0.6);
  233. padding: 10rpx;
  234. border-radius: 50%;
  235. .box {
  236. position: absolute;
  237. top: -10rpx;
  238. right: 0;
  239. z-index: 99;
  240. }
  241. }
  242. .es-mt-16 {
  243. margin-top: 16rpx;
  244. }
  245. .content {
  246. height: 100%;
  247. display: flex;
  248. flex-direction: column;
  249. .cont-box {
  250. padding-bottom: 121rpx;
  251. .integral-box {
  252. background-color: #fff;
  253. padding: 20rpx;
  254. width: 100%;
  255. display: flex;
  256. flex-direction: column;
  257. align-items: flex-start;
  258. justify-content: flex-start;
  259. .title {
  260. font-weight: bold;
  261. font-size: 34rpx;
  262. font-family: PingFang SC;
  263. color: #111;
  264. }
  265. .desc {
  266. margin-top: 15rpx;
  267. display: flex;
  268. align-items: flex-start;
  269. justify-content: flex-start;
  270. .cycle {
  271. background-color: #eee;
  272. border-radius: 30rpx;
  273. padding: 5rpx 15rpx;
  274. font-size: 26rpx;
  275. font-family: PingFang SC;
  276. color: #2BC7B9;
  277. }
  278. .duration {
  279. margin-left: 10rpx;
  280. background-color: #eee;
  281. border-radius: 30rpx;
  282. padding: 5rpx 15rpx;
  283. font-size: 26rpx;
  284. font-family: PingFang SC;
  285. color: #2BC7B9;
  286. }
  287. }
  288. .num-box {
  289. margin-top: 15rpx;
  290. flex: 1;
  291. display: flex;
  292. align-items: flex-end;
  293. justify-content: space-between;
  294. width: 100%;
  295. .price {
  296. padding: 5rpx 10rpx;
  297. background-color: #2BC7B9;
  298. border-radius: 30rpx;
  299. font-size: 20rpx;
  300. font-family: PingFang SC;
  301. color: #ffffff;
  302. }
  303. .price-val {
  304. font-weight: bold;
  305. font-size: 28rpx;
  306. font-family: PingFang SC;
  307. color: #2BC7B9;
  308. }
  309. .count {
  310. font-size: 24rpx;
  311. font-family: PingFang SC;
  312. color: #333333;
  313. }
  314. }
  315. }
  316. .desc-box {
  317. background-color: #fff;
  318. padding: 20rpx;
  319. margin-top: 10rpx;
  320. .title-box {
  321. display: flex;
  322. flex-direction: row;
  323. align-items: center;
  324. justify-content: flex-start;
  325. .title {
  326. font-size: 32rpx;
  327. font-family: PingFang SC;
  328. font-weight: bold;
  329. color: #111111;
  330. }
  331. .line {
  332. margin-right: 15rpx;
  333. height: 30rpx;
  334. width: 6rpx;
  335. background-color: #2BC7B9;
  336. }
  337. }
  338. .desc {
  339. margin-top: 15rpx;
  340. font-size: 28rpx;
  341. font-family: PingFang SC;
  342. color: #9a9a9c;
  343. }
  344. }
  345. }
  346. }
  347. .btn-foot {
  348. box-sizing: border-box;
  349. width: 100%;
  350. height: 121rpx;
  351. background: #FFFFFF;
  352. padding: 0 32rpx 0 28rpx;
  353. display: flex;
  354. align-items: center;
  355. justify-content: space-between;
  356. position: fixed;
  357. left: 0;
  358. bottom: 0;
  359. z-index: 99;
  360. .p-price-box {
  361. .p-name {
  362. font-size: 28rpx;
  363. font-family: PingFang SC;
  364. font-weight: 500;
  365. color: #666666;
  366. }
  367. .p-price {
  368. margin-left: 10rpx;
  369. color: #FF6633;
  370. font-size: 32rpx;
  371. font-family: PingFang SC;
  372. font-weight: bold;
  373. }
  374. }
  375. .btn-box {
  376. display: flex;
  377. align-items: center;
  378. .btn {
  379. width: 200rpx;
  380. height: 88rpx;
  381. line-height: 88rpx;
  382. text-align: center;
  383. border-radius: 44rpx;
  384. margin-left: 20rpx;
  385. font-size: 30rpx;
  386. font-family: PingFang SC;
  387. font-weight: bold;
  388. color: #FFFFFF;
  389. &:first-child {
  390. margin-left: 0;
  391. }
  392. &.buy {
  393. background: #2BC7B9;
  394. }
  395. &.add {
  396. color: #2BC7B9 !important;
  397. border: 1rpx solid #2BC7B9;
  398. }
  399. }
  400. }
  401. }
  402. .goods-banner {
  403. height: 756rpx;
  404. background-color: #FFFFFF;
  405. position: relative;
  406. .swiper-item {
  407. box-sizing: border-box;
  408. }
  409. .swiper,
  410. .swiper-item,
  411. .swiper-item image {
  412. width: 100%;
  413. height: 100%;
  414. }
  415. .num-box {
  416. width: 80rpx;
  417. height: 44rpx;
  418. line-height: 44rpx;
  419. text-align: center;
  420. font-size: 24rpx;
  421. font-family: PingFang SC;
  422. font-weight: 500;
  423. color: #FFFFFF;
  424. background: rgba(0, 0, 0, .3);
  425. border-radius: 22rpx;
  426. position: absolute;
  427. right: 30rpx;
  428. bottom: 30rpx;
  429. z-index: 10;
  430. }
  431. }
  432. .popbox {
  433. padding: 40rpx 32rpx;
  434. &-img {
  435. width: 200rpx;
  436. height: 200rpx;
  437. border-radius: 20rpx;
  438. margin-right: 24rpx;
  439. }
  440. .oldprice {
  441. font-size: 28rpx;
  442. font-family: PingFang SC;
  443. font-weight: 500;
  444. color: #999999;
  445. margin-top: 27rpx;
  446. line-height: 1;
  447. text-decoration: line-through;
  448. margin-left: 24rpx;
  449. }
  450. .info-text {
  451. height: 200rpx;
  452. .price {
  453. display: flex;
  454. align-items: flex-end;
  455. .unit {
  456. font-size: 32rpx;
  457. font-family: PingFang SC;
  458. font-weight: bold;
  459. color: #2BC7B9;
  460. line-height: 1.2;
  461. margin-right: 10rpx;
  462. }
  463. .num {
  464. font-size: 50rpx;
  465. font-family: PingFang SC;
  466. font-weight: bold;
  467. color: #2BC7B9;
  468. line-height: 1;
  469. }
  470. }
  471. .text {
  472. font-size: 28rpx;
  473. font-family: PingFang SC;
  474. font-weight: 400;
  475. color: #2BC7B9;
  476. }
  477. .desc-box {
  478. display: flex;
  479. flex-direction: column;
  480. padding-bottom: 9rpx;
  481. .text {
  482. font-size: 28rpx;
  483. font-family: PingFang SC;
  484. font-weight: 500;
  485. color: #999999;
  486. margin-top: 27rpx;
  487. line-height: 1;
  488. &:first-child {
  489. margin-top: 0;
  490. }
  491. }
  492. }
  493. }
  494. }
  495. .es-max-btn {
  496. width: 100%;
  497. background-color: #2BC7B9;
  498. border-radius: 60rpx;
  499. margin-top: 50rpx;
  500. color: #fff;
  501. padding: 20rpx 0;
  502. box-sizing: border-box;
  503. }
  504. </style>