cardDetail.vue 4.4 KB

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