paymentPopup.vue 15 KB

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