index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar title="兑换码" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0" />
  5. <!-- #endif -->
  6. <!-- #ifndef MP-ALIPAY -->
  7. <u-navbar title="兑换码" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  8. <!-- #endif -->
  9. <view class="wrap">
  10. <view class="wrap-code">
  11. <view class="wrap-code-input">
  12. <u-input :placeholder="placeholder" v-model="code" border="none" maxlength="16" placeholderStyle="color:#333" inputAlign="center" @focus="setPlaceholder" @blur = "setPlaceholder2"/>
  13. </view>
  14. <view class="wrap-code-text">
  15. 兑换规则说明:<br>
  16. 1、输入兑换码即可兑换相应奖品。<br>
  17. 2、兑换码有效期有限制,超期失效。<br>
  18. 3、兑换码不找零、不兑现,使用支配权归用户所有,可自用也可转赠他人
  19. </view>
  20. </view>
  21. <button @click="submit" type="button">提交兑换</button>
  22. </view>
  23. <u-overlay :show="exchangeShow" mask-click-able="false" >
  24. <view class="rect">
  25. <view class="rect-popup">
  26. <view class="rect-popup-top">
  27. <view class="image1">
  28. <image src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/static/activityPrizeBackGround.png" mode="aspectFit"></image>
  29. </view>
  30. <view class="text">~恭喜您得到奖品~</view>
  31. <view class="title">{{ info.type == 'coin' ? (info.goodsName + ' x' + info.value): info.goodsName }}</view>
  32. <view class="image2">
  33. <image :src="info.picUrl" mode="aspectFit"></image>
  34. </view>
  35. <view class="btn" v-if="info.type != 'coin'">
  36. <button @click="toPrize(info.type)">去查看我的奖品</button>
  37. </view>
  38. <view class="btn" v-if="info.type == 'coin'">
  39. <button @click="toPrize(info.type)">去商城兑换商品</button>
  40. </view>
  41. <view class="tip">温馨提示:实物商品需前往提货才可提交订单</view>
  42. </view>
  43. <view class="rect-popup-bottom" @click="close">
  44. <u-icon name="close" size="24"></u-icon>
  45. </view>
  46. </view>
  47. </view>
  48. </u-overlay>
  49. </view>
  50. </template>
  51. <script>
  52. import env from '../../config/env.js'
  53. import $http from '@/utils/request.js'
  54. export default {
  55. data() {
  56. return {
  57. code: '',
  58. info: {},
  59. placeholder: '请输入兑换码',
  60. loading: false,
  61. exchangeShow: false,
  62. }
  63. },
  64. methods: {
  65. setPlaceholder() {
  66. if(this.code == '' && this.placeholder == '请输入兑换码'){
  67. this.placeholder = ''
  68. }
  69. },
  70. setPlaceholder2() {
  71. if(this.code == '' && this.placeholder == ''){
  72. this.placeholder = '请输入兑换码'
  73. }
  74. },
  75. submit() {
  76. if(this.loading) return
  77. this.loading = true
  78. let _this = this
  79. if(_this.code == '') {
  80. _this.loading = false
  81. uni.$u.toast('请输入兑换码');
  82. return
  83. }
  84. if(_this.code.length != 16) {
  85. _this.loading = false
  86. uni.$u.toast('兑换码错误');
  87. return
  88. }
  89. const rule = /^[a-zA-Z0-9]+$/
  90. if (!rule.test(_this.code)) {
  91. _this.loading = false
  92. uni.$u.toast('兑换码错误');
  93. return
  94. }
  95. let data = {
  96. cdKey: _this.code
  97. }
  98. $http.post('/api/v1/mp/user/mine/cdKey/exchange', data).then(res => {
  99. if (res.code == 0) {
  100. res.data.picUrl = env.filePublic + res.data.picUrl.split(',')[0] + '?imageView2/2/w/170'
  101. _this.info = res.data
  102. _this.exchangeShow = true
  103. _this.loading = false
  104. }else {
  105. _this.loading = false
  106. }
  107. })
  108. },
  109. toPrize(data) {
  110. if (data == 'goods') {
  111. uni.redirectTo({
  112. url: '/packagePrize/prize/index'
  113. })
  114. }
  115. if (data == 'coupon') {
  116. uni.redirectTo({
  117. url: '/packagePrize/prize/index?coupon=1'
  118. })
  119. }
  120. if (data == 'coupon_pkg') {
  121. uni.redirectTo({
  122. url: '/packagePrize/prize/index?coupon=1'
  123. })
  124. }
  125. if (data == 'coin') {
  126. uni.switchTab({
  127. url: '/pages/core/index'
  128. })
  129. }
  130. },
  131. close() {
  132. this.exchangeShow = false
  133. }
  134. },
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .wrap {
  139. padding: 30rpx;
  140. &-code {
  141. background-color: #fff;
  142. padding: 40rpx;
  143. margin-bottom: 80rpx;
  144. &-input {
  145. margin-top: 28rpx;
  146. margin-bottom: 50rpx;
  147. height: 88rpx;
  148. border: 1px solid $uni-bg-color;
  149. background-color: rgba(142,81,247,0.12);
  150. display: flex;
  151. flex-direction: row;
  152. align-items: center;
  153. justify-content: space-between;
  154. flex: 1;
  155. }
  156. &-text {
  157. font-size: 24rpx;
  158. color: #666666;
  159. line-height: 56rpx;
  160. font-family: PingFang SC-Regular, PingFang SC;
  161. font-weight: 400;
  162. }
  163. }
  164. button {
  165. margin: 0 auto;
  166. width: 666rpx;
  167. height: 98rpx;
  168. line-height: 98rpx;
  169. background: $uni-bg-color;
  170. border-radius: 6rpx;
  171. color: #fff;
  172. }
  173. }
  174. .rect {
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. height: 100%;
  179. &-popup {
  180. width: 85vw;
  181. text-align: center;
  182. &-top {
  183. background: linear-gradient(125deg, #FFF9F5 0%, #F8DFEF 44%, #C1BDFF 100%);
  184. margin-bottom: 80rpx;
  185. padding: 0 80rpx 40rpx;
  186. .image1 {
  187. display: inline-block;
  188. width: 374rpx;
  189. height: 148rpx;
  190. margin-top: -74rpx;
  191. image {
  192. width: 374rpx;
  193. height: 148rpx;
  194. }
  195. }
  196. .text {
  197. margin-top: 20rpx;
  198. font-size: 30rpx;
  199. font-family: PingFang SC-Medium, PingFang SC;
  200. font-weight: 500;
  201. color: $uni-text-color;
  202. line-height: 36rpx;
  203. }
  204. .title {
  205. margin: 8rpx 0 15rpx;
  206. font-size: 26rpx;
  207. font-family: PingFang SC-Regular, PingFang SC;
  208. font-weight: 400;
  209. color: #666666;
  210. line-height: 50rpx;
  211. }
  212. .image2 {
  213. margin: 0 auto;
  214. width: 218rpx;
  215. height: 218rpx;
  216. image {
  217. width: 218rpx;
  218. height: 218rpx;
  219. }
  220. }
  221. .btn {
  222. margin: 40rpx 0 12rpx;
  223. button {
  224. height: 68rpx;
  225. line-height: 68rpx;
  226. background: $uni-bg-color;
  227. border-radius: 50rpx;
  228. color: #fff;
  229. font-size: 26rpx;
  230. font-family: PingFang SC-Medium, PingFang SC;
  231. font-weight: 500;
  232. }
  233. }
  234. .tip {
  235. font-size: 24rpx;
  236. font-family: PingFang SC-Regular, PingFang SC;
  237. font-weight: 400;
  238. color: #999999;
  239. line-height: 50rpx;
  240. }
  241. }
  242. &-bottom {
  243. width: 80rpx;
  244. height: 80rpx;
  245. background: rgba(255,255,255,0.5);
  246. margin: 0 auto;
  247. border-radius: 50%;
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. }
  252. }
  253. }
  254. </style>