paymentPopup.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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: 10px">{{ 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: 18px">{{ 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), (this.selestCoupon = {})
  249. this.prizes = []
  250. this.checkbox1 = false
  251. this.checkbox2 = false
  252. this.orderId = null
  253. },
  254. close() {
  255. this.$refs.popup.close()
  256. },
  257. close2() {
  258. this.$refs.popup2.close()
  259. },
  260. showPopup3() {
  261. // if (this.couponList.length > 0) {
  262. this.$refs.popup3.open()
  263. // }
  264. },
  265. close3() {
  266. this.$refs.popup3.close()
  267. },
  268. // 获取优惠券
  269. getCoupon() {
  270. let params = {
  271. limit: 999,
  272. page: 1,
  273. status: 0,
  274. raffleId: this.params.raffleId,
  275. }
  276. couponListApi(params).then(res => {
  277. this.couponList = res.data.list
  278. })
  279. },
  280. // 选择优惠券
  281. clickSelestCoupon(item) {
  282. this.selestCoupon = item
  283. this.selestCouponId = item.id
  284. this.getPrice()
  285. this.close3()
  286. },
  287. submit() {
  288. let _this = this
  289. if (!this.checkbox1) {
  290. wx.showModal({
  291. title: '提示',
  292. content: '请阅完整读用户协议并勾选。',
  293. })
  294. return
  295. }
  296. if (!this.checkbox2) {
  297. wx.showModal({
  298. title: '提示',
  299. content: '请确认本人已满18岁且具备完全行为能力并勾选。',
  300. })
  301. return
  302. }
  303. if (this.selestCouponId) {
  304. this.params.couponId = this.selestCouponId
  305. }
  306. drawCardSubmitApi(this.params).then(res => {
  307. console.log(res, '提交购买卡牌')
  308. this.orderId = res.data.orderId
  309. // 如果不需要付钱,直接进入抽卡结果
  310. if (res.data.orderStatus == 201) {
  311. _this.close()
  312. _this.$refs.popup2.open('center')
  313. _this.getLotteryResults(res)
  314. _this.$emit('callBack')
  315. return
  316. }
  317. // 唤起支付
  318. this.wxPayment(res.data)
  319. })
  320. },
  321. getLotteryResults() {
  322. let params = {
  323. orderId: this.orderId,
  324. raffleId: this.params.raffleId,
  325. }
  326. submittResultApi(params).then(res => {
  327. console.log(res, 'res抽奖结果')
  328. this.prizes = res.data
  329. })
  330. },
  331. wxPayment(data) {
  332. let _this = this
  333. wx.requestPayment({
  334. timeStamp: data.timeStamp,
  335. nonceStr: data.nonceStr,
  336. package: data.packageValue,
  337. signType: data.signType,
  338. paySign: data.paySign,
  339. success: function (res) {
  340. console.log(res, '支付过程成功')
  341. _this.close()
  342. if (_this.info.type == 3) {
  343. wx.showModal({
  344. title: '抽奖成功',
  345. content: '请耐心等待开奖结果。',
  346. })
  347. } else {
  348. _this.$refs.popup2.open('center')
  349. _this.getLotteryResults(res)
  350. }
  351. _this.$emit('callBack')
  352. },
  353. fail: function (res) {
  354. console.log('支付过程失败')
  355. util.showErrorToast('支付失败')
  356. },
  357. complete: function (res) {
  358. console.log('支付过程结束')
  359. },
  360. })
  361. },
  362. },
  363. }
  364. </script>
  365. <style scoped lang="scss">
  366. .popupContent {
  367. background-color: #f8f8f8;
  368. border-radius: 10px 10px 0 0;
  369. > .row {
  370. margin: 10px 20px 0 20px;
  371. display: flex;
  372. justify-content: space-between;
  373. padding: 12px;
  374. background: #fff;
  375. border-radius: 6px;
  376. font-size: 14px;
  377. color: #666666;
  378. .price {
  379. color: #ff2c43;
  380. font-weight: 600;
  381. }
  382. .label {
  383. margin-right: 10px;
  384. }
  385. .number {
  386. display: flex;
  387. flex: 1;
  388. overflow: auto;
  389. max-width: 70%;
  390. // justify-content: flex-end;
  391. .item {
  392. width: 48px;
  393. height: 24px;
  394. background: #dddddd;
  395. border-radius: 51px;
  396. color: #000000;
  397. line-height: 24px;
  398. text-align: center;
  399. font-size: 12px;
  400. margin-right: 5px;
  401. flex-grow: 0;
  402. flex-shrink: 0;
  403. }
  404. .numBerActive {
  405. background: linear-gradient(180deg, #ffad3d 0%, #ff740a 100%);
  406. color: #fff;
  407. }
  408. }
  409. .value {
  410. .hasCoupon {
  411. display: flex;
  412. align-items: center;
  413. color: #ff2c43;
  414. font-size: 12px;
  415. }
  416. .noCoupon {
  417. display: flex;
  418. align-items: center;
  419. color: #8c8c8c;
  420. font-size: 12px;
  421. }
  422. }
  423. }
  424. > .title {
  425. text-align: center;
  426. padding: 15px;
  427. font-weight: 600;
  428. .close {
  429. position: absolute;
  430. right: 15px;
  431. top: 15px;
  432. }
  433. }
  434. }
  435. .tip {
  436. margin: 10px 20px 0 20px;
  437. color: #000000;
  438. font-size: 12px;
  439. display: flex;
  440. align-items: center;
  441. .radio {
  442. transform: scale(0.7);
  443. }
  444. }
  445. .button {
  446. margin: 10px auto;
  447. width: 210px;
  448. }
  449. .popup2 {
  450. .bk {
  451. position: relative;
  452. top: -10vh;
  453. width: 100vw;
  454. }
  455. }
  456. .lotteryResults {
  457. width: 76vw;
  458. padding-top: 62px;
  459. // background: #fff;
  460. border-radius: 10px;
  461. position: absolute;
  462. top: -10vh;
  463. left: 50%;
  464. transform: translateX(-50%);
  465. > .title {
  466. text-align: center;
  467. padding: 16px;
  468. height: 20px;
  469. font-weight: 600;
  470. color: #fff;
  471. .close {
  472. position: absolute;
  473. right: 15px;
  474. top: 15px;
  475. }
  476. }
  477. .Rectangle {
  478. width: calc(100% - 1px);
  479. position: absolute;
  480. bottom: 45px;
  481. left: 3px;
  482. }
  483. .text {
  484. width: calc(100% - 1px);
  485. height: 50px;
  486. line-height: 50px;
  487. position: absolute;
  488. bottom: 45px;
  489. left: 3px;
  490. text-align: center;
  491. color: #fff;
  492. text-shadow: 0px 1px 0px rgba(0, 0, 0, 0.5);
  493. font-size: 12px;
  494. }
  495. .close {
  496. width: 30px;
  497. height: 30px;
  498. margin-top: 50px;
  499. position: relative;
  500. z-index: 4;
  501. left: 50%;
  502. transform: translateX(-50%);
  503. }
  504. .prizes {
  505. margin: 30px 15px 10px 19px;
  506. position: relative;
  507. height: calc(85vw - 30px);
  508. background: linear-gradient(180deg, #f77d4d 0%, #feae81 100%);
  509. border-radius: 8px;
  510. padding: 10px 15px;
  511. overflow: auto;
  512. .loading {
  513. position: absolute;
  514. top: 50%;
  515. left: 50%;
  516. transform: translateY(-50%) translateX(-50%);
  517. }
  518. .item {
  519. display: flex;
  520. // flex-direction: column;
  521. align-items: center;
  522. justify-content: center;
  523. text-align: center;
  524. // margin-right: 5px;
  525. background: #fff;
  526. padding: 13px 15px;
  527. margin-bottom: 10px;
  528. border-radius: 8px;
  529. .img {
  530. width: 15vw;
  531. height: 15vw;
  532. border-radius: 5px;
  533. }
  534. .info {
  535. display: flex;
  536. flex-direction: column;
  537. // align-items: center;
  538. justify-content: center;
  539. flex: 1;
  540. .row {
  541. // width: 100%;
  542. }
  543. .name {
  544. font-size: 14px;
  545. }
  546. }
  547. }
  548. }
  549. }
  550. .popupList {
  551. max-height: 50vh;
  552. min-height: 30vh;
  553. overflow: auto;
  554. background: #f8f8f8;
  555. padding: 10px;
  556. .card {
  557. background: #fff;
  558. border-radius: 8px;
  559. overflow: hidden;
  560. display: flex;
  561. .leftIcon {
  562. height: auto;
  563. width: 8px;
  564. background: #ff2c43;
  565. }
  566. .left {
  567. width: 80px;
  568. display: inline-flex;
  569. justify-content: center;
  570. align-items: center;
  571. color: #ff2c43;
  572. font-weight: 600;
  573. }
  574. .right {
  575. padding: 10px;
  576. color: #8e4a21;
  577. .row {
  578. margin-bottom: 4px;
  579. font-size: 12px;
  580. }
  581. .title {
  582. font-size: 14px;
  583. font-weight: 600;
  584. }
  585. .endTime {
  586. color: #ff2c43;
  587. }
  588. .desc {
  589. margin-top: 5px;
  590. color: #8c8c8c;
  591. }
  592. }
  593. }
  594. }
  595. </style>
  596. <style scoped>
  597. .popup2 >>> .uni-popup__wrapper {
  598. top: -8vh;
  599. }
  600. </style>