paymentPopup.vue 14 KB

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