cardDetail.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="container">
  3. <view class="top"><image :src="info.details_image" mode=""></image></view>
  4. <view class="main">
  5. <view class="title">
  6. <view class="title-left"></view>
  7. <view class="title-font">卡片详情</view>
  8. <view class="title-right"></view>
  9. </view>
  10. <view class="detail-desc"><rich-text :nodes="info.introduce"></rich-text></view>
  11. <view class="btn" @click="buy()">立即购买(¥{{ info.price }})</view>
  12. <view class="two">
  13. <label @click="checkboxChange">
  14. <radio style="transform:scale(0.7)" color="#5dbc7c" :checked="istype" />
  15. 已阅读并同意
  16. <text>《优惠卡服务协议》</text>
  17. </label>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import { carddetails, wechat, routine } from '@/api/jdr.js';
  24. import { mapState, mapMutations } from 'vuex';
  25. export default {
  26. data() {
  27. return {
  28. id: '',
  29. info: '',
  30. istype: false,
  31. isbuy: false
  32. };
  33. },
  34. computed: {
  35. // #ifdef H5
  36. ...mapState(['weichatObj']),
  37. // #endif
  38. ...mapState('user', ['userInfo'])
  39. },
  40. onLoad(opt) {
  41. this.id = opt.id;
  42. this.loadData();
  43. },
  44. methods: {
  45. loadData() {
  46. carddetails({}, this.id).then(({ data }) => {
  47. this.info = data;
  48. });
  49. },
  50. navTo(opt) {
  51. uni.navigateTo({
  52. url: '/pages/index/cardDetail?id='
  53. });
  54. },
  55. checkboxChange() {
  56. this.istype = !this.istype;
  57. console.log(this.istype);
  58. },
  59. buy() {
  60. const obj = this;
  61. if (!this.istype) {
  62. return this.$api.msg('请阅读并同意优惠卡服务协议');
  63. }
  64. if (this.isbuy) {
  65. return;
  66. }
  67. this.isbuy = true;
  68. // #ifdef H5
  69. wechat({ card_id: this.id }).then(e => {
  70. let da = e.data.data;
  71. obj.weichatObj.chooseWXPay({
  72. timestamp: da.timestamp,
  73. nonceStr: da.nonceStr,
  74. package: da.package,
  75. signType: da.signType,
  76. paySign: da.paySign,
  77. success: function(res) {
  78. obj.isbuy = false;
  79. uni.showModal({
  80. title: '提示',
  81. content: '购买优惠卡成功是否前往卡券中心激活卡',
  82. success: function(res) {
  83. if (res.confirm) {
  84. uni.navigateTo({
  85. url: '/pages/user/coupon'
  86. });
  87. } else if (res.cancel) {
  88. console.log('用户点击取消');
  89. }
  90. }
  91. });
  92. }
  93. });
  94. });
  95. // #endif
  96. // #ifdef MP-WEIXIN
  97. routine({ card_id: this.id }).then(e => {
  98. let da = e.data;
  99. let data = {
  100. // #ifdef H5
  101. timestamp: da.timestamp,
  102. // #endif
  103. // #ifdef MP
  104. timeStamp: da.timestamp,
  105. // #endif
  106. nonceStr: da.nonceStr,
  107. package: da.package,
  108. signType: da.signType,
  109. paySign: da.paySign,
  110. success: function(res) {
  111. obj.isbuy = false;
  112. uni.showModal({
  113. title: '提示',
  114. content: '购买优惠卡成功是否前往卡券中心激活卡',
  115. success: function(res) {
  116. if (res.confirm) {
  117. uni.navigateTo({
  118. url: '/pages/user/coupon'
  119. });
  120. } else if (res.cancel) {
  121. console.log('用户点击取消');
  122. }
  123. }
  124. });
  125. },
  126. fail: () => {
  127. obj.isbuy = false;
  128. }
  129. };
  130. wx.requestPayment(data);
  131. });
  132. // #endif
  133. }
  134. }
  135. };
  136. </script>
  137. <style lang="scss">
  138. page,
  139. .container {
  140. min-height: 100%;
  141. height: auto;
  142. background: #ffffff;
  143. }
  144. .top {
  145. position: relative;
  146. height: 346rpx;
  147. width: 750rpx;
  148. image {
  149. width: 100%;
  150. height: 100%;
  151. }
  152. }
  153. .main {
  154. position: relative;
  155. z-index: 2;
  156. width: 750rpx;
  157. background: #ffffff;
  158. border-radius: 20rpx 20rpx 5rpx 5rpx;
  159. margin-top: -10rpx;
  160. padding: 46rpx 44rpx;
  161. .title {
  162. display: flex;
  163. justify-content: center;
  164. align-items: center;
  165. .title-font {
  166. font-size: 32rpx;
  167. font-family: ZhenyanGB;
  168. font-weight: 400;
  169. color: #bd9360;
  170. }
  171. }
  172. }
  173. .btn {
  174. width: 620rpx;
  175. height: 80rpx;
  176. background: linear-gradient(270deg, #ffe7c4, #ffce8a);
  177. border-radius: 40rpx;
  178. margin: 58rpx auto 0;
  179. font-size: 32rpx;
  180. font-family: PingFang SC;
  181. font-weight: bold;
  182. color: #9f570e;
  183. line-height: 80rpx;
  184. text-align: center;
  185. }
  186. .two {
  187. margin: 26rpx 0 0;
  188. font-size: 28rpx;
  189. text-align: center;
  190. font-family: PingFang SC;
  191. font-weight: 500;
  192. color: #999999;
  193. text {
  194. color: #ff383e;
  195. }
  196. }
  197. </style>