paymentPopup.vue 15 KB

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