coupon-share.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. <!-- 弹窗提示 -->
  43. <tui-modal
  44. :show="modal"
  45. @click="handleClick"
  46. @cancel="hideMobel"
  47. :content="contentModalText"
  48. :button="modalButton"
  49. color="#333"
  50. :size="32"
  51. shape="circle"
  52. :maskClosable="false"
  53. >
  54. </tui-modal>
  55. </view>
  56. </template>
  57. <script>
  58. import { mapState, mapMutations } from 'vuex'
  59. import wxLogin from '@/common/config/wxLogin.js'
  60. import authorize from '@/common/config/authorize.js'
  61. export default {
  62. data() {
  63. return {
  64. StaticUrl: this.$Static,
  65. isIphoneX: this.$store.state.isIphoneX,
  66. coupon: {},
  67. coupinList: [],
  68. userId: 0, // 机构Id
  69. couponId: 0, //优惠券Id
  70. payAmount: 100 ,//支付金额
  71. skeletonShow:true,
  72. contentModalText: '', //操作文字提示语句
  73. modal: false,
  74. modalButton: [
  75. {
  76. text: '取消',
  77. type: 'gray',
  78. plain: true //是否空心
  79. },
  80. {
  81. text: '去升级',
  82. customStyle: {
  83. color: '#fff',
  84. bgColor: 'linear-gradient(90deg, #F28F31 0%, #E15616 100%)'
  85. },
  86. plain: false
  87. }
  88. ],
  89. }
  90. },
  91. onLoad(option) {
  92. wxLogin.wxLoginAuthorize()
  93. this.userId = option.userId
  94. this.couponId = option.couponId
  95. console.log('机构userId', this.userId)
  96. console.log('价值优惠券Id', this.couponId)
  97. this.initCouponDetail(this.couponId)
  98. },
  99. filters: {
  100. TypeFormat(value) {
  101. switch (value) {
  102. case 0:
  103. return '活动券'
  104. break
  105. case 1:
  106. return '品类券'
  107. break
  108. case 2:
  109. return '用户专享券'
  110. break
  111. case 3:
  112. return '店铺券'
  113. break
  114. case 4:
  115. return '新用户券'
  116. break
  117. }
  118. }
  119. },
  120. computed: {
  121. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity'])
  122. },
  123. methods: {
  124. initCouponDetail(couponId) {
  125. // 初始化优惠券信息
  126. this.ProductService.QueryCouponDetail({ couponId: couponId })
  127. .then(response => {
  128. this.coupon = response.data
  129. this.skeletonShow = false
  130. })
  131. .catch(error => {
  132. console.log('初始化优惠券信息异常~')
  133. })
  134. },
  135. createCouponRecord(){
  136. // 生成购买优惠券记录Id
  137. this.PayService.WeChatCouponRecord({
  138. userId: this.userId,
  139. couponId: this.couponId
  140. })
  141. .then(response => {
  142. this.MiniWxPayFor(response.data.couponRecordId)
  143. })
  144. .catch(error => {
  145. if(error.code == -1){//个人机构不能购买
  146. this.contentModalText ='该优惠券仅限医美机构购买,请升级为医美机构后再次购买。'
  147. this.modal = true
  148. }else if(error.code == -2){//会员机构不是医美机构不能购买
  149. this.$util.msg('该优惠券仅限医美机构购买', 2000)
  150. }
  151. })
  152. },
  153. async MiniWxPayFor(couponRecordId) {
  154. const wechatcode = await authorize.getCode('weixin')
  155. this.PayService.WeChatCouponMiniWxPay({
  156. userId: this.userId,
  157. couponId: this.couponId,
  158. couponRecordId:couponRecordId,
  159. payWay: 'WEIXIN',
  160. code: wechatcode,
  161. source: 1 //支付来源 1 小程序 2 WWW
  162. })
  163. .then(response => {
  164. // 友盟埋点收集微信支付
  165. if (process.env.NODE_ENV != 'development') {
  166. this.$uma.trackEvent('Um_Event_shareCouponPay', {
  167. Um_Key_PageName: '分享优惠券',
  168. Um_Key_SourcePage: '线上支付优惠券',
  169. Um_Key_CouponId: `${this.couponId}`,
  170. Um_Key_userId: `${this.userId}`
  171. })
  172. }
  173. let PayInfo = JSON.parse(response.data.data.payInfo)
  174. this.WxRequestPayment(PayInfo)
  175. })
  176. .catch(error => {
  177. this.$util.msg(error.msg, 2000)
  178. })
  179. },
  180. WxRequestPayment(data) {
  181. let self = this
  182. wx.requestPayment({
  183. timeStamp: data.timeStamp,
  184. nonceStr: data.nonceStr,
  185. package: data.package,
  186. signType: data.signType,
  187. paySign: data.paySign,
  188. success: function(res) {
  189. wx.reLaunch({ url: '/pages/tabBar/home/index' })
  190. },
  191. fail: function(res) {
  192. self.$util.msg('用户取消支付~')
  193. },
  194. complete: function(res) {}
  195. })
  196. },
  197. hideMobel(){
  198. this.modal = false
  199. },
  200. handleClick(e){
  201. //个人机构跳转升级页面
  202. if (e.index == 1) {
  203. this.$api.navigateTo('/pages/login/apply')
  204. }
  205. this.modal = false
  206. },
  207. navigator(url) {
  208. this.$api.navigateTo(url)
  209. }
  210. },
  211. onShow() {}
  212. }
  213. </script>
  214. <style lang="scss">
  215. page {
  216. background-color: #FFFFFF;
  217. }
  218. .container {
  219. width: 100%;
  220. height: auto;
  221. }
  222. .container-list {
  223. box-sizing: border-box;
  224. padding: 24rpx;
  225. .empty-container-image {
  226. width: 260rpx;
  227. height: 260rpx;
  228. margin-top: -300rpx;
  229. }
  230. .toIndexPage {
  231. bottom: 390rpx;
  232. }
  233. .coupon-list {
  234. width: 702rpx;
  235. height: 200rpx;
  236. box-sizing: border-box;
  237. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-buy@2x.png) no-repeat;
  238. background-position: center;
  239. background-size: auto 200rpx;
  240. position: relative;
  241. .list-cell-le {
  242. width: 502rpx;
  243. height: 100%;
  244. box-sizing: border-box;
  245. padding: 23rpx 32rpx;
  246. float: left;
  247. .list-cell-tags {
  248. width: 100%;
  249. height: 32rpx;
  250. margin-bottom: 7rpx;
  251. .tags {
  252. display: inline-block;
  253. padding: 0 10rpx;
  254. height: 32rpx;
  255. line-height: 32rpx;
  256. background: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  257. color: #ffffff;
  258. font-size: $font-size-22;
  259. border-radius: 8rpx;
  260. text-align: center;
  261. float: left;
  262. }
  263. }
  264. .list-cell-price {
  265. width: 100%;
  266. height: 45rpx;
  267. line-height: 45rpx;
  268. font-size: $font-size-32;
  269. color: #333333;
  270. text-align: left;
  271. margin-top: 10rpx;
  272. font-weight: bold;
  273. }
  274. .list-cell-texts {
  275. width: 100%;
  276. height: auto;
  277. line-height: 40rpx;
  278. text-overflow: ellipsis;
  279. display: -webkit-box;
  280. word-break: break-all;
  281. -webkit-box-orient: vertical;
  282. -webkit-line-clamp: 1;
  283. overflow: hidden;
  284. font-size: 26rpx;
  285. color: #333333;
  286. }
  287. .list-cell-time {
  288. width: 100%;
  289. height: 32rpx;
  290. line-height: 32rpx;
  291. text-align: left;
  292. font-size: $font-size-20;
  293. color: #999999;
  294. }
  295. }
  296. .list-cell-ri {
  297. width: 200rpx;
  298. height: 100%;
  299. box-sizing: border-box;
  300. padding: 58rpx 0 0 0;
  301. float: right;
  302. .coupon-maxMoney {
  303. width: 100%;
  304. height: 78rpx;
  305. line-height: 78rpx;
  306. font-size: 40rpx;
  307. color: #f94b4b;
  308. text-align: center;
  309. .small {
  310. font-size: $font-size-26;
  311. }
  312. }
  313. .coupon-minMoney {
  314. width: 100%;
  315. height: 33rpx;
  316. line-height: 33rpx;
  317. font-size: $font-size-26;
  318. color: #f94b4b;
  319. text-align: center;
  320. }
  321. }
  322. }
  323. }
  324. .container-button {
  325. width: 100%;
  326. height: 90rpx;
  327. margin-top: 190rpx;
  328. .button {
  329. width: 600rpx;
  330. height: 90rpx;
  331. text-align: center;
  332. background: $btn-confirm;
  333. line-height: 90rpx;
  334. font-size: $font-size-30;
  335. color: #ffffff;
  336. margin: 0 auto;
  337. border-radius: 45rpx;
  338. }
  339. }
  340. </style>