paymentPopup.vue 16 KB

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