detail.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="giftDetail">
  3. <view class="bannerContainer">
  4. <swiper class="banner">
  5. <swiper-item v-if="item"><view v-if="item.img" class="img" :style="{ backgroundImage: `url(${item.img})` }" /></swiper-item>
  6. </swiper>
  7. <view class="num">
  8. <text class="spec">1</text>
  9. <text>/</text>
  10. <text>1</text>
  11. </view>
  12. </view>
  13. <view class="good">
  14. <view class="top">
  15. <view class="title" v-if="item">{{ item.name }}</view>
  16. <view class="surplus" v-if="item">限量
  17. <text>{{ item.total }}份</text>
  18. </view>
  19. </view>
  20. <view class="bottom">
  21. <view class="num">
  22. <text class="spec">{{ totalPrice }}</text>
  23. </view>
  24. <view class="countNum"><custom-counter :count-num.sync="num"></custom-counter></view>
  25. </view>
  26. </view>
  27. <view class="bottomBtn">
  28. <view class="submitBtn" :class="item.surplus === 0 ? 'disable' : ''" @click="submit">{{ item.surplus ? '立即兑换' : '已兑完' }}</view>
  29. </view>
  30. <toast_confirm :show.sync="toastInfo.show" :title="toastInfo.title" :content="toastInfo.content" @confirm="exchangeConfirm" />
  31. </view>
  32. </template>
  33. <script>
  34. import { api_submitExchange, GetInte } from '../../apis/zbs.js';
  35. import customCounter from './components/count2';
  36. import toast_confirm from '../../components/toast-confirm.vue';
  37. export default {
  38. components: {
  39. customCounter,
  40. toast_confirm
  41. },
  42. data() {
  43. return {
  44. pageTitle: '礼品详情',
  45. item: {},
  46. num: 1,
  47. requesting: false,
  48. integral: '',
  49. toastInfo: {
  50. show: false,
  51. title: '',
  52. content: ''
  53. }
  54. };
  55. },
  56. computed: {
  57. totalPrice() {
  58. if (this.item) {
  59. return this.item.price * this.num;
  60. }
  61. },
  62. userServerInfo() {
  63. //用户服务器信息
  64. return this.$store.state.userinfo;
  65. }
  66. },
  67. onLoad(option) {
  68. this.item = JSON.parse(decodeURIComponent(option.item))
  69. },
  70. onShow() {
  71. this.getBound()
  72. },
  73. methods: {
  74. getBound(){
  75. GetInte({ user_id: this.userServerInfo.id }).then(res => {
  76. //获取兑换礼品列表
  77. this.integral = res.data.integral
  78. })
  79. },
  80. closeToast() {
  81. this.toastInfo.title = '';
  82. this.toastInfo.content = '';
  83. this.toastInfo.show = false;
  84. },
  85. exchangeConfirm(flag) {
  86. const _this = this;
  87. if (flag) {
  88. if (!this.requesting) {
  89. this.requesting = true;
  90. this.closeToast();
  91. uni.showLoading();
  92. api_submitExchange({ gift_id: this.item.id, num: this.num, user_id: this.userServerInfo.id, address_id: 123 }).then(res => {
  93. uni.hideLoading();
  94. this.requesting = false;
  95. if (res.code == 200) {
  96. uni.navigateTo({
  97. url:'./success?totalPrice='+this.totalPrice
  98. })
  99. } else {
  100. uni.hideLoading();
  101. this.requesting = false;
  102. uni.showModal({
  103. content: res.msg || '兑换失败:库存不足',
  104. showCancel: false
  105. });
  106. }
  107. })
  108. }
  109. } else {
  110. this.closeToast();
  111. }
  112. },
  113. submit() {
  114. if (!this.item.surplus) {
  115. uni.showModal({
  116. content: '商品已兑换完',
  117. showCancel: false
  118. });
  119. return false;
  120. }
  121. if (this.num) {
  122. if (this.integral >= this.totalPrice) {
  123. this.toastInfo.title = '温馨提醒';
  124. this.toastInfo.content = `您确定兑换${this.num}件商品吗?`;
  125. this.toastInfo.show = true;
  126. }
  127. else {
  128. uni.showModal({
  129. content: '奖金余额不足',
  130. showCancel: false
  131. });
  132. }
  133. } else {
  134. uni.showModal({
  135. content: '数量不能为空',
  136. showCancel: false
  137. });
  138. }
  139. }
  140. },
  141. // created() {
  142. // //加载完成后开启监听全局 MESSAGE 事件
  143. // this.item = getApp().globalData.detail; //从兑换列表页面进入当前页面后从 getApp().globalData.detail 取值
  144. // }
  145. };
  146. </script>
  147. <style>
  148. page {
  149. background-color: #F9F9FB;
  150. }
  151. </style>
  152. <style lang="scss" scoped>
  153. page {
  154. display: flex;
  155. flex-direction: column;
  156. .giftDetail {
  157. flex: 1;
  158. overflow: hidden;
  159. .bannerContainer {
  160. width: 100%;
  161. height: 628rpx;
  162. position: relative;
  163. .banner {
  164. height: 100%;
  165. width: 100%;
  166. .img {
  167. width: 100%;
  168. height: 100%;
  169. background-position: center;
  170. background-repeat: no-repeat;
  171. background-size: 100%;
  172. }
  173. }
  174. .num {
  175. position: absolute;
  176. width: 112rpx;
  177. height: 48rpx;
  178. border-radius: 48rpx;
  179. line-height: 48rpx;
  180. color: #ffffff;
  181. font-size: 24rpx;
  182. bottom: 54rpx;
  183. right: 44rpx;
  184. background-color: rgba(0, 0, 0, 0.24);
  185. text-align: center;
  186. .spec {
  187. font-size: 28rpx !important;
  188. }
  189. }
  190. }
  191. .good {
  192. width: 100%;
  193. height: 264rpx;
  194. background: linear-gradient(94deg, #f97c55 0%, #f44545 100%);
  195. margin-bottom: 30rpx;
  196. padding: 10rpx;
  197. box-sizing: border-box;
  198. position: relative;
  199. &::after {
  200. content: '';
  201. display: block;
  202. position: absolute;
  203. top: 10rpx;
  204. right: 10rpx;
  205. width: 174rpx;
  206. height: 218rpx;
  207. background-position: top;
  208. background-size: 100%;
  209. background-repeat: no-repeat;
  210. background-image: url(../../static/gift/5.png);
  211. }
  212. .top {
  213. margin-bottom: 20rpx;
  214. width: 100%;
  215. display: flex;
  216. align-items: center;
  217. justify-content: space-between;
  218. height: 72rpx;
  219. padding: 0 20rpx;
  220. .title {
  221. color: #ffffff;
  222. font-size: 40rpx;
  223. line-height: 56rpx;
  224. }
  225. .surplus {
  226. color: #ffffff;
  227. font-size: 28rpx;
  228. align-self: flex-end;
  229. }
  230. }
  231. .bottom {
  232. width: 100%;
  233. height: 120rpx;
  234. border-radius: 8rpx;
  235. background-color: #ffffff;
  236. display: flex;
  237. align-items: center;
  238. justify-content: space-between;
  239. padding: 0 20rpx;
  240. box-sizing: border-box;
  241. position: relative;
  242. z-index: 3;
  243. overflow: hidden;
  244. .num {
  245. color: #ea4a41;
  246. font-size: 24rpx;
  247. .spec {
  248. font-size: 40rpx;
  249. }
  250. }
  251. .countNum {
  252. width: 180rpx;
  253. }
  254. &::before {
  255. content: '';
  256. display: block;
  257. width: 114rpx;
  258. height: 144rpx;
  259. position: absolute;
  260. top: 50%;
  261. left: 16rpx;
  262. transform: translateY(-50%);
  263. background-image: url(../../static/gift/5.png);
  264. background-position: center;
  265. background-size: 100%;
  266. background-repeat: no-repeat;
  267. }
  268. }
  269. }
  270. .desc {
  271. width: 100%;
  272. padding: 30rpx;
  273. box-sizing: border-box;
  274. margin-bottom: 100rpx;
  275. .fixed {
  276. color: #333333;
  277. font-size: 32rpx;
  278. font-weight: bold;
  279. margin-bottom: 20rpx;
  280. }
  281. .content {
  282. color: #333333;
  283. font-size: 28rpx;
  284. line-height: 48rpx;
  285. }
  286. }
  287. .bottomBtn {
  288. @include flex();
  289. left: 0;
  290. right: 0;
  291. bottom: 0;
  292. z-index: 1;
  293. height: 98rpx;
  294. position: fixed;
  295. background: #FFFFFF;
  296. .submitBtn {
  297. width: 690rpx;
  298. height: 88rpx;
  299. line-height: 88rpx;
  300. text-align: center;
  301. background: linear-gradient(93deg, #f97c55 0%, #f44545 100%);
  302. color: #ffffff;
  303. font-size: 32rpx;
  304. border-radius: 88rpx;
  305. &.disable {
  306. background: #999999 !important;
  307. color: #f8f8f8 !important;
  308. }
  309. }
  310. }
  311. }
  312. }
  313. </style>