paymentPopup.vue 9.6 KB

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