paymentPopup.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <template>
  2. <view class="content">
  3. <uni-popup class="popup" ref="popup" type="bottom" background-color="#F8F8F8">
  4. <view class="popupContent">
  5. <view class="title">
  6. 购买卡牌
  7. <uni-icons class="close" @click="close()" type="closeempty" size="20"></uni-icons>
  8. </view>
  9. <view class="row">
  10. <view class="label">单价</view>
  11. <view class="value price">¥{{ info.price || 0 }}</view>
  12. </view>
  13. <view class="row" v-if="info.type == 1">
  14. <view class="label">数量</view>
  15. <view class="value number">
  16. <view :class="['item', params.raffleNum == 1 ? 'numBerActive' : '']" @click="numChange(1)">一发</view>
  17. <view :class="['item', params.raffleNum == 3 ? 'numBerActive' : '']" @click="numChange(3)">三发</view>
  18. <view :class="['item', params.raffleNum == 5 ? 'numBerActive' : '']" @click="numChange(5)">五发</view>
  19. <view :class="['item', params.raffleNum == 10 ? 'numBerActive' : '']" @click="numChange(10)">十发</view>
  20. </view>
  21. </view>
  22. <view class="row" v-if="[2, 3, 5].includes(info.type)">
  23. <view class="label">选中卡牌号码</view>
  24. <view class="value number">
  25. <view class="item" v-for="(item, index) in params.raffleNumList">
  26. {{ item }}
  27. </view>
  28. </view>
  29. </view>
  30. <view class="row">
  31. <view class="label">优惠券</view>
  32. <view class="value">
  33. <view v-if="!selestCouponId && couponList.length > 0" class="hasCoupon" @click="showPopup3">
  34. 选择优惠券
  35. <uni-icons type="right" color="#FF2C43" size="20"></uni-icons>
  36. </view>
  37. <view
  38. v-if="!selestCouponId && couponList.length == 0 && unusableList.length > 0"
  39. class="noCoupon"
  40. @click="showPopup3"
  41. >
  42. 暂无可用优惠券
  43. <uni-icons type="right" color="#8c8c8c" size="20"></uni-icons>
  44. </view>
  45. <view v-if="!selestCouponId && couponList.length == 0 && unusableList.length == 0" class="noCoupon">
  46. 没有优惠券
  47. </view>
  48. <view class="coupon price" @click="showPopup3" v-if="selestCouponId">-¥{{ selestCoupon.discount }}</view>
  49. </view>
  50. </view>
  51. <view class="row">
  52. <view class="label">
  53. 抵扣(余额
  54. <span class="price">0</span>
  55. </view>
  56. <view class="value price">¥0</view>
  57. </view>
  58. <view class="row">
  59. <view class="label"></view>
  60. <view class="value">
  61. 小计:
  62. <span class="price">¥{{ priceAll }}</span>
  63. </view>
  64. </view>
  65. <view class="tip">
  66. <radio class="radio" :checked="checkbox1" @click="checkbox1 = !checkbox1" />
  67. <span>
  68. 我已阅读并同意
  69. <span style="color: #ff8e21">《用户协议》</span>
  70. </span>
  71. </view>
  72. <view class="tip">
  73. <radio class="radio" :checked="checkbox2" @click="checkbox2 = !checkbox2" />
  74. <span>本人已满18岁且具备完全行为能力</span>
  75. </view>
  76. <image
  77. @click="submit"
  78. class="button"
  79. :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/first/button5.png'"
  80. mode="widthFix"
  81. ></image>
  82. </view>
  83. </uni-popup>
  84. <!-- 抽赏结果 -->
  85. <uni-popup class="popup2" ref="popup2" type="center">
  86. <image
  87. class="bk"
  88. :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/winningLottery/bk.png'"
  89. mode="widthFix"
  90. ></image>
  91. <view class="lotteryResults">
  92. <view class="title">
  93. 中奖详情
  94. <!-- <uni-icons class="close" @click="close2()" type="closeempty" size="20"></uni-icons> -->
  95. </view>
  96. <view class="prizes">
  97. <view class="item" v-for="(item, index) in prizes">
  98. <image class="img" :src="item.prizeIcon" mode="aspectFill"></image>
  99. <view class="info">
  100. <view class="row name">
  101. <span style="margin-right: 20rpx">{{ item.prizeName }}</span>
  102. <span v-if="item.prizeType == 4">随机</span>
  103. <span>{{ item.prizeNum }}张</span>
  104. </view>
  105. <view class="row type">
  106. {{ $selectDictLabel(rewardType, item.prizeType) }}
  107. </view>
  108. </view>
  109. </view>
  110. <Mloading class="loading" text="抽奖中..." v-if="prizes.length == 0" />
  111. </view>
  112. <image
  113. class="Rectangle"
  114. :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/winningLottery/Rectangle.png'"
  115. mode="widthFix"
  116. ></image>
  117. <view class="text">已放入背包,可前往背包查看~</view>
  118. <image
  119. class="close"
  120. @click="close2"
  121. :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/winningLottery/icon.png'"
  122. mode="widthFix"
  123. ></image>
  124. </view>
  125. </uni-popup>
  126. <!-- 选则优惠券 -->
  127. <uni-popup class="popup" ref="popup3" type="bottom" background-color="#F8F8F8">
  128. <view class="popupContent">
  129. <view class="title">
  130. <!-- 选择优惠券 -->
  131. <uni-icons class="close" @click="close3()" type="closeempty" size="20"></uni-icons>
  132. </view>
  133. </view>
  134. <view class="popupList">
  135. <view class="tip">可用优惠券</view>
  136. <view class="card" v-for="(item, index) in couponList" @click="clickSelestCoupon(item)">
  137. <view class="leftIcon"></view>
  138. <view class="left">
  139. <span style="font-size: 36rpx">{{ item.discount }}</span>
  140. </view>
  141. <view class="right">
  142. <view class="row title">
  143. {{ item.name }}
  144. </view>
  145. <view class="row endTime">{{ item.endTime }}到期</view>
  146. <view class="row desc">
  147. {{ item.desc }}
  148. </view>
  149. </view>
  150. </view>
  151. <view class="tip">以下优惠券本单暂不适用</view>
  152. <view class="card unusable" v-for="(item, index) in unusableList">
  153. <view class="leftIcon"></view>
  154. <view class="left">
  155. <span style="font-size: 36rpx">{{ item.discount }}</span>
  156. </view>
  157. <view class="right">
  158. <view class="row title">
  159. {{ item.name }}
  160. </view>
  161. <view class="row endTime">{{ item.endTime }}到期</view>
  162. <view class="row desc">
  163. {{ item.desc }}
  164. <span class="reason" v-show="item.reason">({{ item.reason }})</span>
  165. </view>
  166. </view>
  167. </view>
  168. </view>
  169. </uni-popup>
  170. </view>
  171. </template>
  172. <script>
  173. import { rewardType } from '@/utils/commonConfig.js'
  174. import { buyCouponListApi } from '@/api/coupon.js'
  175. import { drawCardSubmitApi, submittResultApi, orderPriceApi } from '@/api/drawCard.js'
  176. import Mloading from '@/component/Mloading.vue'
  177. export default {
  178. components: {
  179. Mloading,
  180. },
  181. emits: ['callBack'],
  182. props: {
  183. value: {
  184. type: Object,
  185. default: {},
  186. },
  187. },
  188. computed: {},
  189. data() {
  190. return {
  191. priceAll: 0,
  192. rewardType: rewardType,
  193. checkbox1: false,
  194. checkbox2: false,
  195. params: {
  196. raffleNumList: [],
  197. raffleNum: null,
  198. raffleId: null,
  199. },
  200. orderId: null,
  201. prizes: [],
  202. // prizes: [
  203. // {
  204. // prizeType: 1,
  205. // prizeIcon: 'https://mall.rongtongh.cn/storage/raffle1.jpg',
  206. // prizeName: 'S赏',
  207. // prizeNum: 12
  208. // },
  209. // {
  210. // prizeType: 4,
  211. // prizeIcon: 'https://mall.rongtongh.cn/storage/raffle1.jpg',
  212. // prizeName: 'S赏',
  213. // prizeNum: 12
  214. // },
  215. // {
  216. // prizeType: 1,
  217. // prizeIcon: 'https://mall.rongtongh.cn/storage/raffle1.jpg',
  218. // prizeName: 'S赏',
  219. // prizeNum: 12
  220. // }
  221. // ],
  222. getApiNum: 0,
  223. info: {},
  224. // 优惠券
  225. couponList: [],
  226. // 不可用优惠券
  227. unusableList: [],
  228. // 选中的优惠券
  229. selestCouponId: null,
  230. selestCoupon: {},
  231. }
  232. },
  233. mounted() {
  234. // this.$refs.popup2.open('center')
  235. // this.getLotteryResults()
  236. },
  237. methods: {
  238. getPrice() {
  239. let params = {
  240. orderNum: this.params.raffleNumList.length || this.params.raffleNum,
  241. orderThirdId: this.params.raffleId,
  242. orderType: 1,
  243. userCouponId: this.selestCouponId || '',
  244. }
  245. orderPriceApi(params).then(res => {
  246. console.log(res, '订单价格')
  247. this.priceAll = res.data
  248. })
  249. },
  250. numChange(num) {
  251. this.params.raffleNum = num
  252. //计算订单价格
  253. this.getPrice()
  254. // 获取优惠券
  255. this.getCoupon()
  256. },
  257. show(params, list, info) {
  258. console.log(info, 'info')
  259. this.refresh()
  260. console.log(list, 'list')
  261. this.params = {
  262. ...this.params,
  263. ...params,
  264. }
  265. console.log(toString.call(list), 'toString')
  266. if (toString.call(list) == '[object Array]') {
  267. this.params.raffleNumList = list
  268. } else if (toString.call(list) == '[object Number]') {
  269. this.params.raffleNum = list
  270. }
  271. this.info = info
  272. this.$refs.popup.open('bottom')
  273. //计算订单价格
  274. this.getPrice()
  275. // 获取优惠券列表
  276. this.getCoupon()
  277. },
  278. refresh() {
  279. // 刷新组件状态
  280. this.selestCouponId = null
  281. this.selestCoupon = {}
  282. this.prizes = []
  283. this.checkbox1 = false
  284. this.checkbox2 = false
  285. this.orderId = null
  286. },
  287. close() {
  288. this.$refs.popup.close()
  289. },
  290. close2() {
  291. this.$refs.popup2.close()
  292. },
  293. showPopup3() {
  294. // if (this.couponList.length > 0) {
  295. this.$refs.popup3.open()
  296. // }
  297. },
  298. close3() {
  299. this.$refs.popup3.close()
  300. },
  301. // 获取优惠券
  302. getCoupon() {
  303. let params = {
  304. orderNum: this.params.raffleNumList.length || this.params.raffleNum,
  305. orderThirdId: this.params.raffleId,
  306. orderType: 1,
  307. }
  308. buyCouponListApi(params).then(res => {
  309. console.log(res, 'res')
  310. this.couponList = res.data.usableList
  311. this.unusableList = res.data.unusableList
  312. })
  313. },
  314. // 选择优惠券
  315. clickSelestCoupon(item) {
  316. this.selestCoupon = item
  317. this.selestCouponId = item.id
  318. this.getPrice()
  319. this.close3()
  320. },
  321. submit() {
  322. let _this = this
  323. if (!this.checkbox1) {
  324. wx.showModal({
  325. title: '提示',
  326. content: '请阅完整读用户协议并勾选。',
  327. })
  328. return
  329. }
  330. if (!this.checkbox2) {
  331. wx.showModal({
  332. title: '提示',
  333. content: '请确认本人已满18岁且具备完全行为能力并勾选。',
  334. })
  335. return
  336. }
  337. if (this.selestCouponId) {
  338. this.params.couponId = this.selestCouponId
  339. }
  340. drawCardSubmitApi(this.params).then(res => {
  341. console.log(res, '提交购买卡牌')
  342. this.orderId = res.data.orderId
  343. // 如果不需要付钱,直接进入抽卡结果
  344. if (res.data.orderStatus == 201) {
  345. _this.close()
  346. _this.$refs.popup2.open('center')
  347. _this.getLotteryResults(res)
  348. _this.$emit('callBack')
  349. return
  350. }
  351. // 唤起支付
  352. this.wxPayment(res.data)
  353. })
  354. },
  355. getLotteryResults() {
  356. let params = {
  357. orderId: this.orderId,
  358. raffleId: this.params.raffleId,
  359. }
  360. submittResultApi(params).then(res => {
  361. console.log(res, 'res抽奖结果')
  362. this.prizes = res.data
  363. })
  364. },
  365. wxPayment(data) {
  366. let _this = this
  367. wx.requestPayment({
  368. timeStamp: data.timeStamp,
  369. nonceStr: data.nonceStr,
  370. package: data.packageValue,
  371. signType: data.signType,
  372. paySign: data.paySign,
  373. success: function (res) {
  374. console.log(res, '支付过程成功')
  375. _this.close()
  376. if (_this.info.type == 3) {
  377. wx.showModal({
  378. title: '抽奖成功',
  379. content: '请耐心等待开奖结果。',
  380. })
  381. } else {
  382. _this.$refs.popup2.open('center')
  383. _this.getLotteryResults(res)
  384. }
  385. _this.$emit('callBack')
  386. },
  387. fail: function (res) {
  388. console.log('支付过程失败')
  389. util.showErrorToast('支付失败')
  390. },
  391. complete: function (res) {
  392. console.log('支付过程结束')
  393. },
  394. })
  395. },
  396. },
  397. }
  398. </script>
  399. <style scoped lang="scss">
  400. .popupContent {
  401. background-color: #f8f8f8;
  402. border-radius: 20rpx 20rpx 0 0;
  403. > .row {
  404. margin: 20rpx 40rpx 0 40rpx;
  405. display: flex;
  406. justify-content: space-between;
  407. padding: 24rpx;
  408. background: #fff;
  409. border-radius: 12rpx;
  410. font-size: 28rpx;
  411. color: #666666;
  412. .price {
  413. color: #ff2c43;
  414. font-weight: 600;
  415. }
  416. .label {
  417. margin-right: 20rpx;
  418. }
  419. .number {
  420. display: flex;
  421. flex: 1;
  422. overflow: auto;
  423. max-width: 70%;
  424. // justify-content: flex-end;
  425. .item {
  426. width: 96rpx;
  427. height: 48rpx;
  428. background: #dddddd;
  429. border-radius: 102rpx;
  430. color: #000000;
  431. line-height: 48rpx;
  432. text-align: center;
  433. font-size: 24rpx;
  434. margin-right: 10rpx;
  435. flex-grow: 0;
  436. flex-shrink: 0;
  437. }
  438. .numBerActive {
  439. background: linear-gradient(180deg, #ffad3d 0%, #ff740a 100%);
  440. color: #fff;
  441. }
  442. }
  443. .value {
  444. .hasCoupon {
  445. display: flex;
  446. align-items: center;
  447. color: #ff2c43;
  448. font-size: 24rpx;
  449. }
  450. .noCoupon {
  451. display: flex;
  452. align-items: center;
  453. color: #8c8c8c;
  454. font-size: 24rpx;
  455. }
  456. }
  457. }
  458. > .title {
  459. text-align: center;
  460. padding: 30rpx;
  461. font-weight: 600;
  462. .close {
  463. position: absolute;
  464. right: 30rpx;
  465. top: 30rpx;
  466. }
  467. }
  468. }
  469. .tip {
  470. margin: 20rpx 40rpx 0 40rpx;
  471. color: #000000;
  472. font-size: 24rpx;
  473. display: flex;
  474. align-items: center;
  475. .radio {
  476. transform: scale(0.7);
  477. }
  478. }
  479. .button {
  480. margin: 20rpx auto;
  481. width: 420rpx;
  482. }
  483. .popup2 {
  484. .bk {
  485. position: relative;
  486. top: -10vh;
  487. width: 100vw;
  488. }
  489. }
  490. .lotteryResults {
  491. width: 76vw;
  492. padding-top: 124rpx;
  493. // background: #fff;
  494. border-radius: 20rpx;
  495. position: absolute;
  496. top: -10vh;
  497. left: 50%;
  498. transform: translateX(-50%);
  499. > .title {
  500. text-align: center;
  501. padding: 32rpx;
  502. height: 40rpx;
  503. font-weight: 600;
  504. color: #fff;
  505. .close {
  506. position: absolute;
  507. right: 30rpx;
  508. top: 30rpx;
  509. }
  510. }
  511. .Rectangle {
  512. width: calc(100% - 2rpx);
  513. position: absolute;
  514. bottom: 90rpx;
  515. left: 6rpx;
  516. }
  517. .text {
  518. width: calc(100% - 2rpx);
  519. height: 100rpx;
  520. line-height: 100rpx;
  521. position: absolute;
  522. bottom: 90rpx;
  523. left: 6rpx;
  524. text-align: center;
  525. color: #fff;
  526. text-shadow: 0rpx 2rpx 0rpx rgba(0, 0, 0, 0.5);
  527. font-size: 24rpx;
  528. }
  529. .close {
  530. width: 60rpx;
  531. height: 60rpx;
  532. margin-top: 100rpx;
  533. position: relative;
  534. z-index: 4;
  535. left: 50%;
  536. transform: translateX(-50%);
  537. }
  538. .prizes {
  539. margin: 60rpx 30rpx 20rpx 38rpx;
  540. position: relative;
  541. height: calc(85vw - 60rpx);
  542. background: linear-gradient(180deg, #f77d4d 0%, #feae81 100%);
  543. border-radius: 16rpx;
  544. padding: 20rpx 30rpx;
  545. overflow: auto;
  546. .loading {
  547. position: absolute;
  548. top: 50%;
  549. left: 50%;
  550. transform: translateY(-50%) translateX(-50%);
  551. }
  552. .item {
  553. display: flex;
  554. // flex-direction: column;
  555. align-items: center;
  556. justify-content: center;
  557. text-align: center;
  558. // margin-right: 10rpx;
  559. background: #fff;
  560. padding: 26rpx 30rpx;
  561. margin-bottom: 20rpx;
  562. border-radius: 16rpx;
  563. .img {
  564. width: 15vw;
  565. height: 15vw;
  566. border-radius: 10rpx;
  567. }
  568. .info {
  569. display: flex;
  570. flex-direction: column;
  571. // align-items: center;
  572. justify-content: center;
  573. flex: 1;
  574. .row {
  575. // width: 100%;
  576. }
  577. .name {
  578. font-size: 28rpx;
  579. }
  580. }
  581. }
  582. }
  583. }
  584. .popupList {
  585. max-height: 50vh;
  586. min-height: 30vh;
  587. overflow: auto;
  588. background: #f8f8f8;
  589. padding: 20rpx;
  590. .tip {
  591. color: #8c8c8c;
  592. margin-bottom: 10px;
  593. text-align: center;
  594. }
  595. .card {
  596. background: #fff;
  597. border-radius: 16rpx;
  598. overflow: hidden;
  599. display: flex;
  600. margin-bottom: 20rpx;
  601. .leftIcon {
  602. height: auto;
  603. width: 16rpx;
  604. background: #ff2c43;
  605. }
  606. .left {
  607. width: 160rpx;
  608. display: inline-flex;
  609. justify-content: center;
  610. align-items: center;
  611. color: #ff2c43;
  612. font-weight: 600;
  613. }
  614. .right {
  615. padding: 20rpx;
  616. color: #8e4a21;
  617. .row {
  618. margin-bottom: 8rpx;
  619. font-size: 24rpx;
  620. }
  621. .title {
  622. font-size: 28rpx;
  623. font-weight: 600;
  624. }
  625. .endTime {
  626. color: #ff2c43;
  627. }
  628. .desc {
  629. margin-top: 10rpx;
  630. color: #8c8c8c;
  631. }
  632. }
  633. }
  634. .unusable {
  635. .leftIcon {
  636. background: #ffc1c8;
  637. }
  638. .left {
  639. color: #ffc1c8;
  640. }
  641. .right {
  642. padding: 20rpx;
  643. color: #bf977f;
  644. .endTime {
  645. color: #ffc1c8;
  646. }
  647. .desc {
  648. color: #b7b7b7;
  649. }
  650. }
  651. }
  652. }
  653. </style>
  654. <style scoped>
  655. .popup2 >>> .uni-popup__wrapper {
  656. top: -8vh;
  657. }
  658. </style>