paymentPopup.vue 9.8 KB

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