paymentPopup.vue 14 KB

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