coupon-share.vue 8.5 KB

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