integralGoodsDetails.vue 10 KB

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