coupon.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <app-layout>
  3. <view class='nav main-center cross-center'>
  4. <template v-if="coupon.coupon.type == 2">
  5. <view class='price'>¥
  6. <text v-if="coupon.coupon.sub_price > 99999" style="font-size:22px">{{coupon.coupon.sub_price}}</text>
  7. <text v-else-if="coupon.coupon.sub_price > 9999" style="font-size:26px">{{coupon.coupon.sub_price}}</text>
  8. <text v-else-if="coupon.coupon.sub_price > 999" style="font-size:32px">{{coupon.coupon.sub_price}}</text>
  9. <text v-else-if="coupon.coupon.sub_price > 99" style="font-size:36px">{{coupon.coupon.sub_price}}</text>
  10. <text v-else>{{coupon.coupon.sub_price}}</text>
  11. </view>
  12. </template>
  13. <template v-if="coupon.coupon.type == 1">
  14. <view class='price'>
  15. <text>{{coupon.coupon.discount}}</text>折
  16. </view>
  17. </template>
  18. <view class="right dir-top-nowrap main-center">
  19. <text class='name'>{{coupon.coupon.name}}</text>
  20. <text>满{{coupon.coupon.min_price}}元可用</text>
  21. <text v-if="coupon.coupon.discount_limit">优惠上限:¥{{coupon.coupon.discount_limit}}</text>
  22. </view>
  23. </view>
  24. <view class='need-price'>
  25. <text>{{coupon.integral_num}}</text>积分
  26. <text v-if="coupon.price > 0" style="font-size:16px">+¥</text>
  27. <text v-if="coupon.price > 0">{{coupon.price}}</text>
  28. </view>
  29. <view class='about'>
  30. <view class='title'>
  31. <view></view>
  32. <text>优惠券说明</text>
  33. </view>
  34. <view v-if="coupon.coupon.expire_type == 1">优惠券有效期:兑换后{{coupon.coupon.expire_day}}天</view>
  35. <view v-if="coupon.coupon.expire_type == 2">优惠券有效期:{{coupon.coupon.begin_time}}-{{coupon.coupon.end_time}}</view>
  36. <view>适用范围:
  37. <text v-if="coupon.coupon.appoint_type == 1">以下指定分类商品适用:
  38. <text v-for="(item,index) in coupon.coupon.cat" :key="item.name">
  39. <text v-if="index != 0">、</text>
  40. <text>{{item.name}}</text>
  41. </text>
  42. </text>
  43. <text v-if="coupon.coupon.appoint_type == 2">
  44. <text v-for="(item,index) in coupon.coupon.goods" :key="item.name">
  45. <text v-if="index != 0">、</text>
  46. <text>{{item.name}}</text>
  47. </text>
  48. </text>
  49. <text v-if="coupon.coupon.appoint_type == 3">全场通用</text>
  50. <text v-if="coupon.coupon.appoint_type == 4">仅限当面付活动使用</text>
  51. </view>
  52. <view class='content'>使用说明:{{coupon.coupon.rule}}</view>
  53. </view>
  54. <view @click="exchangeCoupon=true" :class="[`exchange`,iphone_x? `iphone_x`:``]">
  55. <view class='coupon-exchange'>立即兑换</view>
  56. </view>
  57. <view class="dialog-bg" v-if="exchangeCoupon">
  58. <view class="dialog-tip">
  59. <view class="dialog-title">提示</view>
  60. <view class="dialog-msg">
  61. 确定使用
  62. <text v-if="coupon.integral_num > 0"><text style="color: #ff4544">{{coupon.integral_num}}</text>积分</text>
  63. <text v-if="coupon.price > 0"><text v-if="coupon.integral_num > 0">与</text>
  64. <text style="color: #ff4544">{{coupon.price}}</text>元</text>
  65. 兑换此优惠券?
  66. </view>
  67. <view class="dialog-btn main-center">
  68. <view @click="exchangeCoupon=false" class="dialog-close">取消</view>
  69. <view class="line"></view>
  70. <view class="dialog-submit" @click="submit">确认</view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class='dialog-bg' v-if="lose || success">
  75. <view class='dialog'>
  76. <view @click="close">
  77. <image class='close' src='/static/image/icon/icon-close.png'></image>
  78. </view>
  79. <view class='lose' v-if="lose">
  80. <image class='lose-img' src='/static/image/lose.png'></image>
  81. <view class='lose-title'>兑换失败!</view>
  82. <view>当前积分不足</view>
  83. </view>
  84. <view class='success' v-if="success">
  85. <image class='success-head' :src="integralImg.app_image.success"></image>
  86. <view>恭喜您,兑换成功!</view>
  87. <view class='main-between success-btn'>
  88. <view @click="toList">
  89. <button class='to-card'>去卡券包</button>
  90. </view>
  91. <view @click="toList">
  92. <button class='to-use'>立即使用</button>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </app-layout>
  99. </template>
  100. <script>
  101. import { mapState } from "vuex";
  102. export default {
  103. name: "about",
  104. data() {
  105. return {
  106. coupon: {
  107. coupon: {
  108. min_price: '',
  109. rule: ''
  110. }
  111. },
  112. success: false,
  113. lose: false,
  114. iphone_x: false,
  115. exchangeCoupon: false,
  116. current: 'wechat',
  117. };
  118. },
  119. computed: {
  120. ...mapState({
  121. integralImg: state => state.mallConfig.plugin.integral_mall,
  122. mall: state => state.mallConfig.mall
  123. }),
  124. },
  125. onLoad(options) { this.$commonLoad.onload(options);
  126. let that = this;
  127. let id = options.id;
  128. that.$showLoading({
  129. type: 'global',
  130. text: '加载中...'
  131. });
  132. that.getList(id);
  133. uni.getSystemInfo({
  134. success: function (res) {
  135. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  136. that.iphone_x = true;
  137. }
  138. }
  139. })
  140. },
  141. methods: {
  142. close() {
  143. this.success = false;
  144. this.lose = false;
  145. },
  146. toList() {
  147. this.success = false;
  148. uni.navigateTo({
  149. url: '/pages/coupon/index/index'
  150. });
  151. },
  152. getList(id) {
  153. let that = this;
  154. that.$request({
  155. url: that.$api.integral_mall.detail,
  156. data: {
  157. id: id
  158. }
  159. }).then(response=>{
  160. that.$hideLoading();
  161. if(response.code == 0) {
  162. that.coupon = response.data.detail;
  163. }else {
  164. uni.showToast({
  165. title: response.msg,
  166. icon: 'none',
  167. duration: 1000
  168. });
  169. }
  170. }).catch(response => {
  171. that.$hideLoading();
  172. });
  173. },
  174. submit() {
  175. let that = this;
  176. let id = that.coupon.id;
  177. that.exchangeCoupon = false;
  178. if (that.userInfo != null && that.userInfo.integral < that.choose.integral_num) {
  179. uni.showToast({
  180. title: '积分不足',
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. }else {
  185. uni.showLoading({
  186. mask: true,
  187. title: '领取中...'
  188. });
  189. that.$request({
  190. url: that.$api.integral_mall.coupon_submit,
  191. data: {
  192. id: id
  193. },
  194. method: 'post'
  195. }).then(response=>{
  196. if(response.code == 0) {
  197. let queue_id = response.data.queue_id;
  198. let token = response.data.token;
  199. that.getPayOrderId(queue_id, token)
  200. }else {
  201. uni.hideLoading();
  202. uni.showToast({
  203. title: response.msg,
  204. icon: 'none',
  205. duration: 1000
  206. });
  207. }
  208. }).catch(response => {
  209. uni.hideLoading();
  210. });
  211. }
  212. },
  213. getPayOrderId(queue_id, token) {
  214. this.$request({
  215. url: this.$api.integral_mall.coupon_pay,
  216. data: {
  217. queue_id: queue_id,
  218. token: token,
  219. },
  220. }).then(response => {
  221. if (response.code === 0) {
  222. if (response.data.retry && response.data.retry === 1) {
  223. this.getPayDataTimer = setTimeout(() => {
  224. this.getPayOrderId(queue_id, token);
  225. }, 1000);
  226. } else {
  227. uni.hideLoading();
  228. this.pay(response.data.id);
  229. }
  230. } else {
  231. this.exchangeCoupon = false;
  232. uni.hideLoading();
  233. uni.showModal({
  234. title: '提示',
  235. content: response.msg,
  236. showCancel: false,
  237. });
  238. }
  239. }).catch(e => {
  240. this.exchangeCoupon = false;
  241. uni.hideLoading();
  242. uni.showModal({
  243. title: '提示',
  244. content: e.errMsg,
  245. showCancel: false,
  246. });
  247. });
  248. },
  249. pay(id) {
  250. this.$payment.pay(id).then(res => {
  251. this.success = true;
  252. }).catch(e => {
  253. uni.showToast({
  254. title: '支付失败',
  255. icon: 'none',
  256. duration: 1000
  257. });
  258. });
  259. },
  260. }
  261. }
  262. </script>
  263. <style scoped lang="scss">
  264. .nav {
  265. height: #{270rpx};
  266. width: 100%;
  267. color: #353535;
  268. font-size: 15px;
  269. background-image: url('/static/image/BG.png');
  270. background-size: 100% 100%;
  271. padding: 0 #{90rpx};
  272. >view {
  273. width: 50%;
  274. }
  275. }
  276. .price {
  277. height: #{270rpx};
  278. line-height: #{270rpx};
  279. font-size: 22px;
  280. text-align: center;
  281. text {
  282. font-size: 40px;
  283. }
  284. }
  285. .name {
  286. font-size: $uni-line-height-import-two;
  287. width: 100%;
  288. overflow: hidden;
  289. text-overflow: ellipsis;
  290. white-space: nowrap;
  291. }
  292. .need-price {
  293. height: #{140rpx};
  294. line-height: #{140rpx};
  295. padding-left: #{24rpx};
  296. font-size: 16px;
  297. color: #353535;
  298. border-bottom: #{1rpx} solid #ededed;
  299. }
  300. .need-price text {
  301. font-size: 24px;
  302. }
  303. .about {
  304. padding: #{40rpx} #{24rpx};
  305. color: #666;
  306. font-size: 15px;
  307. }
  308. .title {
  309. font-size: 15px;
  310. margin-bottom: #{30rpx};
  311. color: #353535;
  312. }
  313. .title view {
  314. display: inline-block;
  315. height: #{20rpx};
  316. width: #{6rpx};
  317. margin-right: #{8rpx};
  318. background-color: #ff4544;
  319. }
  320. .content {
  321. padding-bottom: #{130rpx};
  322. }
  323. .exchange {
  324. z-index: 10;
  325. border-top: #{1rpx} solid #e2e2e2;
  326. position: fixed;
  327. bottom: 0;
  328. left: 0;
  329. right: 0;
  330. background-color: #fff;
  331. height: #{120rpx};
  332. }
  333. .exchange.iphone_x {
  334. padding-bottom: #{50rpx};
  335. height: #{170rpx};
  336. }
  337. .coupon-exchange {
  338. margin-top: #{20rpx};
  339. margin-left: 5%;
  340. height: #{80rpx};
  341. line-height: #{80rpx};
  342. width: 90%;
  343. border-radius: #{40rpx};
  344. background-color: #ff4544;
  345. text-align: center;
  346. font-size: 16px;
  347. color: #fff;
  348. padding: 0;
  349. }
  350. .coupon-exchange::after {
  351. border: 0;
  352. }
  353. .dialog-bg {
  354. position: fixed;
  355. left: 0;
  356. top: 0;
  357. height: 100%;
  358. width: 100%;
  359. background-color: rgba(0, 0, 0, 0.3);
  360. }
  361. .dialog {
  362. width: #{574rpx};
  363. margin: 0 auto;
  364. background-color: #fff;
  365. position: fixed;
  366. top: 25%;
  367. left: 0;
  368. right: 0;
  369. border-radius: #{16rpx};
  370. }
  371. .close {
  372. height: #{30rpx};
  373. width: #{30rpx};
  374. position: absolute;
  375. right: #{22rpx};
  376. top: #{22rpx};
  377. z-index: 10;
  378. }
  379. .lose {
  380. padding: #{88rpx} 0 #{88rpx} #{90rpx};
  381. height: #{310rpx};
  382. font-size: 15px;
  383. color: #353535;
  384. }
  385. .lose-img {
  386. height: #{134rpx};
  387. width: #{124rpx};
  388. margin-right: #{48rpx};
  389. display: block;
  390. float: left;
  391. }
  392. .lose-title {
  393. font-size: 23px;
  394. font-weight: 500;
  395. margin: #{15rpx} 0;
  396. }
  397. .success {
  398. height: #{350rpx};
  399. background-color: #fff;
  400. text-align: center;
  401. padding-top: #{150rpx};
  402. font-size: 18px;
  403. color: #353535;
  404. border-radius: #{16rpx};
  405. }
  406. .success-head {
  407. height: #{332rpx};
  408. width: #{574rpx};
  409. position: absolute;
  410. top: #{-215rpx};
  411. left: 0;
  412. }
  413. .to-card, .to-use {
  414. margin-top: #{44rpx};
  415. height: #{64rpx};
  416. border-radius: #{32rpx};
  417. line-height: #{64rpx};
  418. width: #{228rpx};
  419. font-size: 16px;
  420. }
  421. .to-card::after, .to-use::after {
  422. border: 0;
  423. }
  424. .to-card {
  425. background-color: #fff;
  426. color: #353535;
  427. border: #{1rpx} solid #999;
  428. }
  429. .to-use {
  430. background-color: #ff4544;
  431. color: #fff;
  432. }
  433. .success-btn {
  434. padding:0 #{39rpx};
  435. }
  436. .dialog-tip {
  437. position: fixed;
  438. top: #{400rpx};
  439. left: 0;
  440. right: 0;
  441. padding-bottom: #{88rpx};
  442. width: #{640rpx};
  443. margin: 0 auto;
  444. z-index: 221;
  445. background-color: #fff;
  446. border-radius: 10px;
  447. text-align: center;
  448. font-size: #{30rpx};
  449. }
  450. .dialog-msg {
  451. margin: 0 #{50rpx} #{50rpx};
  452. }
  453. .dialog-title {
  454. margin: #{40rpx} auto #{35rpx};
  455. }
  456. .dialog-btn {
  457. height: #{88rpx};
  458. width: #{640rpx};
  459. border-top: #{1rpx} solid #e2e2e2;
  460. line-height: #{88rpx};
  461. position: absolute;
  462. bottom: 0;
  463. left: 0;
  464. }
  465. .dialog-close,.dialog-submit {
  466. width: 50%;
  467. }
  468. .line {
  469. height: #{44rpx};
  470. margin-top: #{22rpx};
  471. width: #{1rpx};
  472. background-color: #e2e2e2;
  473. }
  474. .dialog-submit {
  475. color: #ff4544;
  476. }
  477. .nav .right {
  478. height: #{270rpx};
  479. width: #{320rpx};
  480. padding-left: #{10rpx};
  481. font-size: $uni-font-size-general-two;
  482. }
  483. </style>