coupon-share.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="container clearfix" >
  3. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  4. <view class="container-content tui-skeleton" v-else>
  5. <view class="container-list">
  6. <view class="coupon-list">
  7. <view class="list-cell-le">
  8. <view class="list-cell-tags">
  9. <template v-if="coupon.moneyCouponFlag == 1">
  10. <text class="tags" v-if="coupon.moneyCouponType == 1"
  11. >意向{{ coupon.couponType | TypeFormat }}</text
  12. >
  13. <text class="tags" v-else>定向{{ coupon.couponType | TypeFormat }}</text>
  14. </template>
  15. <template v-else>
  16. <text class="tags">{{ coupon.couponType | TypeFormat }}</text>
  17. </template>
  18. </view>
  19. <view class="list-cell-price"> {{ coupon.couponAmount }}元满{{ coupon.touchPrice }}可用 </view>
  20. <view class="list-cell-texts">
  21. <text v-if="coupon.couponType == 0">
  22. {{ coupon.productType && coupon.productType == 1 ? '全商城商品通用' : '仅可购买指定商品' }}
  23. </text>
  24. <text v-if="coupon.couponType == 1">
  25. {{ coupon.categoryType == 1 ? '仅限购买产品类商品' : '仅限购买仪器类商品' }}
  26. </text>
  27. <text v-if="coupon.couponType == 3">仅限购买店铺【{{ coupon.shopName }}】的商品</text>
  28. <text v-if="coupon.couponType == 4 || coupon.couponType == 2">全商城商品通用</text>
  29. </view>
  30. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  31. </view>
  32. <view class="list-cell-ri">
  33. <view class="coupon-minMoney">售价</view>
  34. <view class="coupon-maxMoney"> <text class="small">¥</text> {{ coupon.moneyCouponPrice }} </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="container-button">
  39. <view class="button" @click="createCouponRecord">¥{{ coupon.moneyCouponPrice }}购买</view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { mapState, mapMutations } from 'vuex'
  46. import authorize from '@/common/config/authorize.js'
  47. export default {
  48. data() {
  49. return {
  50. StaticUrl: this.$Static,
  51. isIphoneX: this.$store.state.isIphoneX,
  52. coupon: {},
  53. coupinList: [],
  54. userId: 0, // 机构Id
  55. couponId: 0, //优惠券Id
  56. payAmount: 100 ,//支付金额
  57. skeletonShow:true
  58. }
  59. },
  60. onLoad(option) {
  61. this.userId = option.userId
  62. this.couponId = option.couponId
  63. console.log('机构userId', this.userId)
  64. console.log('价值优惠券Id', this.couponId)
  65. this.initCouponDetail(this.couponId)
  66. },
  67. filters: {
  68. TypeFormat(value) {
  69. switch (value) {
  70. case 0:
  71. return '活动券'
  72. break
  73. case 1:
  74. return '品类券'
  75. break
  76. case 2:
  77. return '用户专享券'
  78. break
  79. case 3:
  80. return '店铺券'
  81. break
  82. case 4:
  83. return '新用户券'
  84. break
  85. }
  86. }
  87. },
  88. computed: {
  89. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity'])
  90. },
  91. methods: {
  92. initCouponDetail(couponId) {
  93. // 初始化优惠券信息
  94. this.ProductService.QueryCouponDetail({ couponId: couponId })
  95. .then(response => {
  96. this.coupon = response.data
  97. this.skeletonShow = false
  98. })
  99. .catch(error => {
  100. console.log('初始化优惠券信息异常~')
  101. })
  102. },
  103. createCouponRecord(){
  104. // 生成购买优惠券记录Id
  105. this.PayService.WeChatCouponRecord({
  106. userId: this.userId,
  107. couponId: this.couponId
  108. })
  109. .then(response => {
  110. this.MiniWxPayFor(response.data.couponRecordId)
  111. })
  112. .catch(error => {
  113. console.log(error)
  114. })
  115. },
  116. async MiniWxPayFor(couponRecordId) {
  117. const wechatcode = await authorize.getCode('weixin')
  118. this.PayService.WeChatCouponMiniWxPay({
  119. userId: this.userId,
  120. couponId: this.couponId,
  121. couponRecordId:couponRecordId,
  122. payWay: 'WEIXIN',
  123. code: wechatcode,
  124. source: 1 //支付来源 1 小程序 2 WWW
  125. })
  126. .then(response => {
  127. // 友盟埋点收集微信支付
  128. if (process.env.NODE_ENV != 'development') {
  129. this.$uma.trackEvent('Um_Event_shareCouponPay', {
  130. Um_Key_PageName: '分享优惠券',
  131. Um_Key_SourcePage: '线上支付优惠券',
  132. Um_Key_CouponId: `${this.couponId}`,
  133. Um_Key_userId: `${this.userId}`
  134. })
  135. }
  136. let PayInfo = JSON.parse(response.data.data.payInfo)
  137. this.WxRequestPayment(PayInfo)
  138. })
  139. .catch(error => {
  140. this.$util.msg(error.msg, 2000)
  141. })
  142. },
  143. WxRequestPayment(data) {
  144. let self = this
  145. wx.requestPayment({
  146. timeStamp: data.timeStamp,
  147. nonceStr: data.nonceStr,
  148. package: data.package,
  149. signType: data.signType,
  150. paySign: data.paySign,
  151. success: function(res) {
  152. wx.reLaunch({ url: '/pages/tabBar/home/index' })
  153. },
  154. fail: function(res) {
  155. self.$util.msg('用户取消支付~')
  156. },
  157. complete: function(res) {}
  158. })
  159. },
  160. navigator(url) {
  161. this.$api.navigateTo(url)
  162. }
  163. },
  164. onShow() {}
  165. }
  166. </script>
  167. <style lang="scss">
  168. page {
  169. background-color: #FFFFFF;
  170. }
  171. .container {
  172. width: 100%;
  173. height: auto;
  174. }
  175. .container-list {
  176. box-sizing: border-box;
  177. padding: 24rpx;
  178. .empty-container-image {
  179. width: 260rpx;
  180. height: 260rpx;
  181. margin-top: -300rpx;
  182. }
  183. .toIndexPage {
  184. bottom: 390rpx;
  185. }
  186. .coupon-list {
  187. width: 702rpx;
  188. height: 200rpx;
  189. box-sizing: border-box;
  190. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-buy@2x.png) no-repeat;
  191. background-position: center;
  192. background-size: auto 200rpx;
  193. position: relative;
  194. .list-cell-le {
  195. width: 502rpx;
  196. height: 100%;
  197. box-sizing: border-box;
  198. padding: 23rpx 32rpx;
  199. float: left;
  200. .list-cell-tags {
  201. width: 100%;
  202. height: 32rpx;
  203. margin-bottom: 7rpx;
  204. .tags {
  205. display: inline-block;
  206. padding: 0 10rpx;
  207. height: 32rpx;
  208. line-height: 32rpx;
  209. background: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  210. color: #ffffff;
  211. font-size: $font-size-22;
  212. border-radius: 8rpx;
  213. text-align: center;
  214. float: left;
  215. }
  216. }
  217. .list-cell-price {
  218. width: 100%;
  219. height: 45rpx;
  220. line-height: 45rpx;
  221. font-size: $font-size-32;
  222. color: #333333;
  223. text-align: left;
  224. margin-top: 10rpx;
  225. font-weight: bold;
  226. }
  227. .list-cell-texts {
  228. width: 100%;
  229. height: auto;
  230. line-height: 40rpx;
  231. text-overflow: ellipsis;
  232. display: -webkit-box;
  233. word-break: break-all;
  234. -webkit-box-orient: vertical;
  235. -webkit-line-clamp: 1;
  236. overflow: hidden;
  237. font-size: 26rpx;
  238. color: #333333;
  239. }
  240. .list-cell-time {
  241. width: 100%;
  242. height: 32rpx;
  243. line-height: 32rpx;
  244. text-align: left;
  245. font-size: $font-size-20;
  246. color: #999999;
  247. }
  248. }
  249. .list-cell-ri {
  250. width: 200rpx;
  251. height: 100%;
  252. box-sizing: border-box;
  253. padding: 58rpx 0 0 0;
  254. float: right;
  255. .coupon-maxMoney {
  256. width: 100%;
  257. height: 78rpx;
  258. line-height: 78rpx;
  259. font-size: 40rpx;
  260. color: #f94b4b;
  261. text-align: center;
  262. .small {
  263. font-size: $font-size-26;
  264. }
  265. }
  266. .coupon-minMoney {
  267. width: 100%;
  268. height: 33rpx;
  269. line-height: 33rpx;
  270. font-size: $font-size-26;
  271. color: #f94b4b;
  272. text-align: center;
  273. }
  274. }
  275. }
  276. }
  277. .container-button {
  278. width: 100%;
  279. height: 90rpx;
  280. margin-top: 190rpx;
  281. .button {
  282. width: 600rpx;
  283. height: 90rpx;
  284. text-align: center;
  285. background: $btn-confirm;
  286. line-height: 90rpx;
  287. font-size: $font-size-30;
  288. color: #ffffff;
  289. margin: 0 auto;
  290. border-radius: 45rpx;
  291. }
  292. }
  293. </style>