paymentPopup.vue 10 KB

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