paymentPopup.vue 15 KB

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