paymentPopup.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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="https://mall.rongtongh.cn/storage/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. this.refresh()
  174. console.log(list, 'list')
  175. this.params.raffleId = id
  176. this.params.raffleNumList = list
  177. this.info = info
  178. this.$refs.popup.open('bottom')
  179. // 获取优惠券列表
  180. this.getCoupon()
  181. },
  182. refresh() {
  183. // 刷新组件状态
  184. this.selestCouponId = null,
  185. this.selestCoupon = {}
  186. this.prizes = []
  187. this.checkbox1 = false
  188. this.checkbox2 = false
  189. this.orderId = null
  190. },
  191. close() {
  192. this.$refs.popup.close()
  193. },
  194. close2() {
  195. this.$refs.popup2.close()
  196. },
  197. showPopup3() {
  198. // if (this.couponList.length > 0) {
  199. this.$refs.popup3.open()
  200. // }
  201. },
  202. close3() {
  203. this.$refs.popup3.close()
  204. },
  205. // 获取优惠券
  206. getCoupon() {
  207. let params = {
  208. limit: 999,
  209. page: 1,
  210. status: 0,
  211. raffleId: this.params.raffleId
  212. }
  213. couponListApi(params).then(res => {
  214. this.couponList = res.data.list
  215. })
  216. },
  217. // 选择优惠券
  218. clickSelestCoupon(item) {
  219. this.selestCoupon = item
  220. this.selestCouponId = item.id
  221. this.close3()
  222. },
  223. submit() {
  224. let _this = this
  225. if (this.selestCouponId) {
  226. this.params.couponId = this.selestCouponId
  227. }
  228. drawCardSubmitApi(this.params).then(res => {
  229. console.log(res, '提交购买卡牌')
  230. this.orderId = res.data.orderId
  231. // 如果不需要付钱,直接进入抽卡结果
  232. if (res.data.orderStatus == 201) {
  233. _this.close()
  234. _this.$refs.popup2.open('center')
  235. _this.getLotteryResults(res)
  236. _this.$emit('callBack')
  237. return
  238. }
  239. // 唤起支付
  240. this.wxPayment(res.data)
  241. })
  242. },
  243. getLotteryResults() {
  244. let params = {
  245. orderId: this.orderId,
  246. raffleId: this.params.raffleId,
  247. }
  248. submittResultApi(params).then(res => {
  249. console.log(res, 'res抽奖结果')
  250. this.prizes = res.data
  251. })
  252. },
  253. wxPayment(data) {
  254. let _this = this
  255. wx.requestPayment({
  256. 'timeStamp': data.timeStamp,
  257. 'nonceStr': data.nonceStr,
  258. 'package': data.packageValue,
  259. 'signType': data.signType,
  260. 'paySign': data.paySign,
  261. 'success': function(res) {
  262. console.log(res, "支付过程成功");
  263. _this.close()
  264. _this.$refs.popup2.open('center')
  265. _this.getLotteryResults(res)
  266. _this.$emit('callBack')
  267. },
  268. 'fail': function(res) {
  269. console.log("支付过程失败");
  270. util.showErrorToast('支付失败');
  271. },
  272. 'complete': function(res) {
  273. console.log("支付过程结束")
  274. }
  275. });
  276. },
  277. }
  278. }
  279. </script>
  280. <style scoped lang="scss">
  281. .popupContent {
  282. background-color: #F8F8F8;
  283. border-radius: 10px 10px 0 0;
  284. >.row {
  285. margin: 10px 20px 0 20px;
  286. display: flex;
  287. justify-content: space-between;
  288. padding: 12px;
  289. background: #fff;
  290. border-radius: 6px;
  291. font-size: 14px;
  292. color: #666666;
  293. .price {
  294. color: #FF2C43;
  295. font-weight: 600;
  296. }
  297. .label {
  298. margin-right: 10px;
  299. }
  300. .number {
  301. display: flex;
  302. flex: 1;
  303. overflow: auto;
  304. max-width: 60%;
  305. // justify-content: flex-end;
  306. .item {
  307. width: 48px;
  308. height: 24px;
  309. background: #DDDDDD;
  310. border-radius: 51px;
  311. color: #000000;
  312. line-height: 24px;
  313. text-align: center;
  314. font-size: 12px;
  315. margin-right: 5px;
  316. flex-grow: 0;
  317. flex-shrink: 0;
  318. }
  319. }
  320. .value {
  321. .hasCoupon {
  322. display: flex;
  323. align-items: center;
  324. color: #FF2C43;
  325. font-size: 12px;
  326. }
  327. .noCoupon {
  328. display: flex;
  329. align-items: center;
  330. color: #8c8c8c;
  331. font-size: 12px;
  332. }
  333. }
  334. }
  335. > .title {
  336. text-align: center;
  337. padding: 15px;
  338. font-weight: 600;
  339. .close {
  340. position: absolute;
  341. right: 15px;
  342. top: 15px;
  343. }
  344. }
  345. }
  346. .tip {
  347. margin: 10px 20px 0 20px;
  348. color: #000000;
  349. font-size: 12px;
  350. display: flex;
  351. align-items: center;
  352. .radio {
  353. transform: scale(0.7);
  354. }
  355. }
  356. .button {
  357. margin: 10px auto;
  358. width: 210px;
  359. }
  360. .lotteryResults {
  361. width: 90vw;
  362. background: #fff;
  363. border-radius: 10px;
  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. .prizes {
  375. padding: 10px;
  376. .item {
  377. display: inline-flex;
  378. flex-direction: column;
  379. align-items: center;
  380. justify-content: center;
  381. text-align: center;
  382. margin-right: 5px;
  383. .img {
  384. width: 70px;
  385. border-radius: 5px;
  386. }
  387. }
  388. }
  389. }
  390. .popupList {
  391. max-height: 50vh;
  392. min-height: 30vh;
  393. overflow: auto;
  394. background: #F8F8F8;
  395. padding: 10px;
  396. .card {
  397. background: #fff;
  398. border-radius: 8px;
  399. overflow: hidden;
  400. display: flex;
  401. .leftIcon {
  402. height: auto;
  403. width: 8px;
  404. background: #FF2C43;
  405. }
  406. .left {
  407. width: 80px;
  408. display: inline-flex;
  409. justify-content: center;
  410. align-items: center;
  411. color: #FF2C43;
  412. font-weight: 600;
  413. }
  414. .right {
  415. padding: 10px;
  416. .row {
  417. margin-bottom: 4px;
  418. font-size: 12px;
  419. }
  420. .title {
  421. font-size: 14px;
  422. font-weight: 600;
  423. }
  424. .endTime {
  425. color: #FF2C43;
  426. }
  427. .desc {
  428. margin-top: 5px;
  429. color: #8c8c8c;
  430. }
  431. }
  432. }
  433. }
  434. </style>
  435. <style scoped>
  436. </style>