index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <view class="grade-popup popup" catchtouchmove="true" :class="(value && complete) ? 'show' : 'none'"
  3. @touchmove.stop.prevent="moveHandle">
  4. <view class="mask" @click="close('mask')"></view>
  5. <!-- 要购买的等级信息确认 start -->
  6. <view v-if="!isShowPay" class="layer attr-content" :style="'border-radius: 10rpx 10rpx 0 0;'">
  7. <view class="specification-wrapper">
  8. <scroll-view class="specification-wrapper-content" scroll-y="true">
  9. <view class="specification-header">
  10. <view class="specification-name"><text class="price" v-if="memberGrade.catchValue > 0">¥{{ memberGrade.catchValue }}</text>购买{{ memberGrade.name }}</view>
  11. </view>
  12. <view class="specification-content">
  13. <view class="grade-item" v-if="memberGrade.discount > 0">
  14. <view class="item-rule"><view class="title">买单折扣:</view>{{ memberGrade.discount }}折</view>
  15. </view>
  16. <view class="grade-item" v-if="memberGrade.speedPoint > 0">
  17. <view class="item-rule"><view class="title">积分加速:</view>{{ memberGrade.speedPoint }}倍</view>
  18. </view>
  19. <view class="grade-item">
  20. <view class="item-rule">
  21. <view class="title">有效期限:</view>
  22. <text v-if="memberGrade.validDay > 0">{{ memberGrade.validDay }}天</text>
  23. <text v-else>永久</text>
  24. </view>
  25. </view>
  26. <view class="grade-description">
  27. <view class="item-rule">
  28. <view class="title">权益说明:</view>
  29. <view>{{ memberGrade.userPrivilege ? memberGrade.userPrivilege : '暂无'}}</view>
  30. </view>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. <view class="close" @click="close('close')" v-if="showClose">
  35. <image class="close-item" :src="closeImage"></image>
  36. </view>
  37. </view>
  38. <view class="btn-wrapper">
  39. <view class="sure" @click="buyNow">立即购买</view>
  40. </view>
  41. <!-- 页面结束 -->
  42. </view>
  43. <!-- 要购买的等级信息确认 end -->
  44. <!-- 支付信息确认 start -->
  45. <view class="confirm" v-if="isShowPay">
  46. <view class="layer attr-content" :style="'border-radius: 10rpx 10rpx 0 0;'">
  47. <view class="specification-wrapper">
  48. <scroll-view class="specification-wrapper-content" scroll-y="true">
  49. <view class="specification-header">
  50. <view class="specification-name">支付确认</view>
  51. </view>
  52. <view class="specification-content">
  53. <view v-if="couponInfo && couponInfo.amount" class="pay-item">
  54. <view class="item-point">
  55. <view class="title" @click="doUseCoupon">
  56. <text v-if="useCoupon" class="iconfont is-use icon-success"></text>
  57. <text v-if="!useCoupon" class="iconfont icon-success"></text>
  58. <text class="point-amount">使用卡券抵扣</text>
  59. <text class="amount">¥{{ couponInfo.amount }}</text>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="pay-item">
  64. <view class="item-amount">
  65. <view class="title">
  66. 实付金额:<text class="amount">¥{{ ((parseFloat(memberGrade.catchValue) - parseFloat(useCouponInfo.amount)) >= 0 ? (parseFloat(memberGrade.catchValue) - parseFloat(useCouponInfo.amount)) : 0.0.toFixed(2)) }}</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </scroll-view>
  72. <view class="close" @click="close('close')" v-if="showClose">
  73. <image class="close-item" :src="closeImage"></image>
  74. </view>
  75. </view>
  76. <view class="btn-wrapper">
  77. <view class="sure" @click="doBuy">确认支付</view>
  78. </view>
  79. <!-- 页面结束 -->
  80. </view>
  81. </view>
  82. <!-- 支付信息确认 end -->
  83. </view>
  84. </template>
  85. <script>
  86. import * as SettlementApi from '@/api/settlement'
  87. import PayTypeEnum from '@/common/enum/order/PayType'
  88. import { wxPayment } from '@/utils/app'
  89. var that; // 当前页面对象
  90. var vk; // 自定义函数集
  91. export default {
  92. name: 'GradePopup',
  93. props: {
  94. // true 组件显示 false 组件隐藏
  95. value: {
  96. Type: Boolean,
  97. default: false
  98. },
  99. // vk云函数路由模式参数开始-----------------------------------------------------------
  100. // 等级信息
  101. memberGrade: {
  102. Type: Object,
  103. default: {}
  104. },
  105. // vk云函数路由模式参数结束-----------------------------------------------------------
  106. // 点击遮罩是否关闭组件 true 关闭 false 不关闭 默认true
  107. maskCloseAble: {
  108. Type: Boolean,
  109. default: true
  110. },
  111. // 是否显示右上角关闭按钮
  112. showClose: {
  113. Type: Boolean,
  114. default: true
  115. },
  116. // 关闭按钮的图片地址
  117. closeImage: {
  118. Type: String,
  119. default: "https://img.alicdn.com/imgextra/i1/121022687/O1CN01ImN0O11VigqwzpLiK_!!121022687.png"
  120. }
  121. },
  122. data() {
  123. return {
  124. complete: false, // 组件是否加载完成
  125. isShowPay: false, // true 显示 false 隐藏
  126. useCoupon: true, // 是否使用卡券
  127. useCouponInfo: { amount: 0, id: '' }, // 使用的卡券
  128. couponInfo: null // 可用卡券
  129. };
  130. },
  131. mounted() {
  132. that = this;
  133. },
  134. methods: {
  135. async open() {
  136. that.complete = true;
  137. that.$emit("open", true);
  138. that.$emit("input", true);
  139. },
  140. // 监听 - 弹出层收起
  141. close(s) {
  142. if (s == "close") {
  143. that.$emit("input", false);
  144. that.$emit("close", "close");
  145. that.isShowPay = false;
  146. that.useCoupon = true;
  147. } else if (s == "mask") {
  148. if (that.maskCloseAble) {
  149. that.$emit("input", false);
  150. that.$emit("close", "mask");
  151. }
  152. }
  153. },
  154. moveHandle() {
  155. //禁止父元素滑动
  156. },
  157. // 立即购买
  158. buyNow() {
  159. this.prePay();
  160. },
  161. // 是否使用卡券
  162. doUseCoupon() {
  163. if (this.useCoupon) {
  164. this.useCoupon = false;
  165. this.useCouponInfo = { amount: 0, id: '' };
  166. } else {
  167. this.useCoupon = true;
  168. this.useCouponInfo = this.couponInfo;
  169. }
  170. },
  171. // 确认购买
  172. doBuy() {
  173. const app = this
  174. let couponId = "";
  175. if (app.useCoupon) {
  176. couponId = app.couponInfo ? app.couponInfo.userCouponId : 0;
  177. }
  178. // 请求api
  179. SettlementApi.submit(app.memberGrade.id, "", "member", "", "", 0, couponId, "", 0, 0, 0, "", "JSAPI")
  180. .then(result => app.onSubmitCallback(result))
  181. .catch(err => {
  182. if (err.result) {
  183. const errData = err.result.data
  184. if (errData) {
  185. return false
  186. }
  187. }
  188. })
  189. },
  190. // 支付前查询
  191. prePay() {
  192. const app = this
  193. // 请求api
  194. SettlementApi.prePay({ type: 'memberGrade' })
  195. .then(result => {
  196. if (result.data) {
  197. if (result.data.canUseCouponInfo) {
  198. app.couponInfo = result.data.canUseCouponInfo;
  199. if (app.useCoupon) {
  200. app.useCouponInfo = app.couponInfo;
  201. }
  202. }
  203. app.isShowPay = true;
  204. }
  205. })
  206. .catch(err => {
  207. if (err.result) {
  208. const errData = err.result.data;
  209. if (errData) {
  210. return false;
  211. }
  212. }
  213. })
  214. },
  215. // 订单提交成功后回调
  216. onSubmitCallback(result) {
  217. const app = this
  218. // 微信支付
  219. if (result.data.payType == PayTypeEnum.WECHAT.value) {
  220. wxPayment(result.data.payment)
  221. .then(() => {
  222. uni.showModal({
  223. title: '支付结果',
  224. content: '支付成功',
  225. showCancel: false,
  226. success(o) {
  227. if (o.confirm) {
  228. app.$router.go(0);
  229. app.$emit('onPaySuccess');
  230. }
  231. }
  232. })
  233. })
  234. .catch(err => app.$error('支付失败'))
  235. .finally(() => {
  236. //empty
  237. })
  238. }
  239. // 余额支付
  240. if (result.data.payType == PayTypeEnum.BALANCE.value) {
  241. app.$error('支付成功');
  242. app.$emit('onPaySuccess');
  243. }
  244. },
  245. // 弹窗
  246. toast(title, icon) {
  247. uni.showToast({
  248. title: title,
  249. icon: icon
  250. });
  251. }
  252. },
  253. watch: {
  254. value: function(val) {
  255. if (val) {
  256. that.open();
  257. }
  258. },
  259. }
  260. };
  261. </script>
  262. <style lang="scss" scoped>
  263. .grade-popup {
  264. position: fixed;
  265. left: 0;
  266. top: 0;
  267. right: 0;
  268. bottom: 0;
  269. z-index: 9999999999;
  270. overflow: hidden;
  271. &.show {
  272. display: block;
  273. .mask {
  274. animation: showPopup 0.2s linear both;
  275. }
  276. .layer {
  277. animation: showLayer 0.2s linear both;
  278. }
  279. }
  280. &.hide {
  281. .mask {
  282. animation: hidePopup 0.2s linear both;
  283. }
  284. .layer {
  285. animation: hideLayer 0.2s linear both;
  286. }
  287. }
  288. &.none {
  289. display: none;
  290. }
  291. .mask {
  292. position: fixed;
  293. top: 0;
  294. width: 100%;
  295. height: 100%;
  296. z-index: 1;
  297. background-color: rgba(0, 0, 0, 0.65);
  298. }
  299. .layer {
  300. display: flex;
  301. width: 100%;
  302. flex-direction: column;
  303. position: fixed;
  304. z-index: 99;
  305. bottom: 0;
  306. border-radius: 10rpx 10rpx 0 0;
  307. background-color: #fff;
  308. .specification-wrapper {
  309. width: 100%;
  310. padding: 30rpx 25rpx 10rpx 25rpx;
  311. box-sizing: border-box;
  312. background: #ffffff;
  313. .specification-wrapper-content {
  314. width: 100%;
  315. max-height: 1200rpx;
  316. min-height: 300rpx;
  317. &::-webkit-scrollbar {
  318. /*隐藏滚轮*/
  319. display: none;
  320. }
  321. .specification-header {
  322. width: 100%;
  323. display: flex;
  324. flex-direction: row;
  325. position: relative;
  326. margin-bottom: 40rpx;
  327. text-align: center;
  328. .specification-name {
  329. .price {
  330. color: #f03c3c;
  331. }
  332. font-weight: bold;
  333. width: 100%;
  334. font-size: 30rpx;
  335. padding: 10rpx;
  336. }
  337. }
  338. .specification-content {
  339. font-weight: 500;
  340. font-size: 26rpx;
  341. .grade-item {
  342. .title {
  343. font-weight: bold;
  344. display: flex;
  345. float: left;
  346. }
  347. display: flex;
  348. height: 100rpx;
  349. padding-top:30rpx;
  350. cursor:pointer;
  351. .item-rule {
  352. padding: 20rpx;
  353. border-bottom: solid 1px #cccccc;
  354. width: 100%;
  355. text-align: left;
  356. }
  357. }
  358. .grade-description {
  359. margin-top: 20rpx;
  360. padding: 20rpx;
  361. min-height: 100rpx;
  362. .title {
  363. font-weight: bold;
  364. }
  365. }
  366. .pay-item {
  367. padding: 30rpx;
  368. font-size: 30rpx;
  369. background: #fff;
  370. border: 1rpx solid $fuint-theme;
  371. border-radius: 8rpx;
  372. color: #888;
  373. margin-bottom: 12rpx;
  374. text-align: center;
  375. .amount {
  376. color: #f03c3c;
  377. font-weight: bold;
  378. }
  379. .iconfont {
  380. margin-right: 10rpx;
  381. }
  382. .is-use {
  383. color: $fuint-theme
  384. }
  385. .item-left_icon {
  386. margin-right: 20rpx;
  387. font-size: 48rpx;
  388. &.wechat {
  389. color: #00c800;
  390. }
  391. &.balance {
  392. color: $fuint-theme;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. .close {
  399. position: absolute;
  400. top: 30rpx;
  401. right: 25rpx;
  402. width: 50rpx;
  403. height: 50rpx;
  404. text-align: center;
  405. line-height: 50rpx;
  406. .close-item {
  407. width: 40rpx;
  408. height: 40rpx;
  409. }
  410. }
  411. }
  412. .btn-wrapper {
  413. display: flex;
  414. width: 100%;
  415. height: 120rpx;
  416. flex: 0 0 120rpx;
  417. align-items: center;
  418. justify-content: space-between;
  419. padding: 0 26rpx;
  420. box-sizing: border-box;
  421. margin-bottom: 120rpx;
  422. .layer-btn {
  423. width: 335rpx;
  424. height: 76rpx;
  425. border-radius: 38rpx;
  426. color: #fff;
  427. line-height: 76rpx;
  428. text-align: center;
  429. font-weight: 500;
  430. font-size: 28rpx;
  431. &.add-cart {
  432. background: #ffbe46;
  433. }
  434. &.buy {
  435. background: #fe560a;
  436. }
  437. }
  438. .sure {
  439. width: 698rpx;
  440. height: 80rpx;
  441. border-radius: 40rpx;
  442. color: #fff;
  443. line-height: 80rpx;
  444. text-align: center;
  445. font-weight: 500;
  446. font-size: 28rpx;
  447. background:linear-gradient(to right, #f9211c, #ff6335)
  448. }
  449. .sure.add-cart {
  450. background: #ff9402;
  451. }
  452. }
  453. }
  454. @keyframes showPopup {
  455. 0% {
  456. opacity: 0;
  457. }
  458. 100% {
  459. opacity: 1;
  460. }
  461. }
  462. @keyframes hidePopup {
  463. 0% {
  464. opacity: 1;
  465. }
  466. 100% {
  467. opacity: 0;
  468. }
  469. }
  470. @keyframes showLayer {
  471. 0% {
  472. transform: translateY(120%);
  473. }
  474. 100% {
  475. transform: translateY(0%);
  476. }
  477. }
  478. @keyframes hideLayer {
  479. 0% {
  480. transform: translateY(0);
  481. }
  482. 100% {
  483. transform: translateY(120%);
  484. }
  485. }
  486. }
  487. </style>