coupon-share.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view class="container clearfix" >
  3. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5" />
  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 ? '全商城商品通用' : coupon.couponName }}
  23. </text>
  24. <text v-if="coupon.couponType == 1">
  25. {{ coupon.categoryType == 1 ? coupon.couponName : coupon.couponName }}
  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. if (!this.hasLogin) {
  164. const pages = getCurrentPages()
  165. const page = pages[pages.length - 1]
  166. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  167. this.$api.redirectTo('/pages/login/login')
  168. } else {
  169. this.PayService.WeChatCouponRecord({
  170. userId: this.userId,
  171. couponId: this.couponId
  172. })
  173. .then(response => {
  174. this.MiniWxPayFor(response.data.couponRecordId)
  175. })
  176. .catch(error => {
  177. if(error.code == -1){//个人机构不能购买
  178. this.contentModalText ='该优惠券仅限医美机构购买,请升级为医美机构后再次购买。'
  179. this.modal = true
  180. }else if(error.code == -2){//会员机构不是医美机构不能购买
  181. this.$util.msg('该优惠券仅限医美机构购买', 2000)
  182. }
  183. })
  184. }
  185. },
  186. async MiniWxPayFor(couponRecordId) {
  187. const wechatcode = await authorize.getCode('weixin')
  188. const params = {
  189. userId: this.userId,
  190. couponId: this.couponId,
  191. couponRecordId:couponRecordId,
  192. payType:'XCX',
  193. code: wechatcode,
  194. source: 1 //支付来源 1 小程序 2 WWW
  195. }
  196. this.weChatMiniCouponWxPay(params,'Um_Event_shareCouponPay','分享优惠券','线上支付优惠券',this.couponId,this.userId)
  197. },
  198. hideMobel(){
  199. this.modal = false
  200. },
  201. handleClick(e){
  202. //个人机构跳转升级页面
  203. if (e.index == 1) {
  204. this.$api.navigateTo('/pages/login/apply')
  205. }
  206. this.modal = false
  207. },
  208. navigator(url) {
  209. this.$api.navigateTo(url)
  210. }
  211. },
  212. onShow() {}
  213. }
  214. </script>
  215. <style lang="scss">
  216. page {
  217. background-color: #FFFFFF;
  218. }
  219. .container {
  220. width: 100%;
  221. height: auto;
  222. }
  223. .container-list {
  224. box-sizing: border-box;
  225. padding: 24rpx;
  226. .empty-container-image {
  227. width: 260rpx;
  228. height: 260rpx;
  229. margin-top: -300rpx;
  230. }
  231. .toIndexPage {
  232. bottom: 390rpx;
  233. }
  234. .coupon-list {
  235. width: 702rpx;
  236. height: 200rpx;
  237. box-sizing: border-box;
  238. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-buy@2x.png) no-repeat;
  239. background-position: center;
  240. background-size: auto 200rpx;
  241. position: relative;
  242. .list-cell-le {
  243. width: 502rpx;
  244. height: 100%;
  245. box-sizing: border-box;
  246. padding: 23rpx 32rpx;
  247. float: left;
  248. .list-cell-tags {
  249. width: 100%;
  250. height: 32rpx;
  251. margin-bottom: 7rpx;
  252. .tags {
  253. display: inline-block;
  254. padding: 0 10rpx;
  255. height: 32rpx;
  256. line-height: 32rpx;
  257. background: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  258. color: #ffffff;
  259. font-size: $font-size-22;
  260. border-radius: 8rpx;
  261. text-align: center;
  262. float: left;
  263. }
  264. }
  265. .list-cell-price {
  266. width: 100%;
  267. height: 45rpx;
  268. line-height: 45rpx;
  269. font-size: $font-size-32;
  270. color: #333333;
  271. text-align: left;
  272. margin-top: 10rpx;
  273. font-weight: bold;
  274. }
  275. .list-cell-texts {
  276. width: 100%;
  277. height: auto;
  278. line-height: 40rpx;
  279. text-overflow: ellipsis;
  280. display: -webkit-box;
  281. word-break: break-all;
  282. -webkit-box-orient: vertical;
  283. -webkit-line-clamp: 1;
  284. overflow: hidden;
  285. font-size: 26rpx;
  286. color: #333333;
  287. }
  288. .list-cell-time {
  289. width: 100%;
  290. height: 32rpx;
  291. line-height: 32rpx;
  292. text-align: left;
  293. font-size: $font-size-20;
  294. color: #999999;
  295. }
  296. }
  297. .list-cell-ri {
  298. width: 200rpx;
  299. height: 100%;
  300. box-sizing: border-box;
  301. padding: 58rpx 0 0 0;
  302. float: right;
  303. .coupon-maxMoney {
  304. width: 100%;
  305. height: 78rpx;
  306. line-height: 78rpx;
  307. font-size: 28rpx;
  308. color: #f94b4b;
  309. text-align: center;
  310. .small {
  311. font-size: $font-size-26;
  312. }
  313. }
  314. .coupon-minMoney {
  315. width: 100%;
  316. height: 33rpx;
  317. line-height: 33rpx;
  318. font-size: $font-size-26;
  319. color: #f94b4b;
  320. text-align: center;
  321. }
  322. }
  323. }
  324. }
  325. .container-button {
  326. width: 100%;
  327. height: 90rpx;
  328. margin-top: 190rpx;
  329. .button {
  330. width: 600rpx;
  331. height: 90rpx;
  332. text-align: center;
  333. background: $btn-confirm;
  334. line-height: 90rpx;
  335. font-size: $font-size-30;
  336. color: #ffffff;
  337. margin: 0 auto;
  338. border-radius: 45rpx;
  339. }
  340. }
  341. </style>