pay-popup.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <u-popup :show="payShow" mode="bottom" @close="close" :closeable="true">
  4. <view class="choiceShow-wrap">
  5. <view class="flex goods">
  6. <view class="flex image-wrap">
  7. <image :src="payInfo.picUrl" mode="aspectFit"></image>
  8. </view>
  9. <view class="info">
  10. <view class="info-title">{{ payInfo.title }}</view>
  11. <view class="info-stock">¥{{ $numberFormat( payInfo.salePrice ) }}</view>
  12. </view>
  13. </view>
  14. <view class="flex coupon" @click="toCoupon">
  15. <view class="flex coupon-left">
  16. <u-icon name="coupon" size="26" color="#333"></u-icon>
  17. <view class="txt">优惠券</view>
  18. </view>
  19. <view class="flex coupon-right">
  20. <view class="txt" v-if="payInfo.couponTitle">{{ payInfo.couponTitle }}</view>
  21. <view class="txt" v-else>暂无可用优惠券</view>
  22. <u-icon name="arrow-right" size="16" color="#333"></u-icon>
  23. </view>
  24. </view>
  25. <view class="flex agreement">
  26. <view class="txt" @click="toRule">同意<text>《盲票购买协议》</text></view>
  27. <view class="checked">
  28. <u-checkbox-group>
  29. <u-checkbox :value="checked" :checked="checked" size="24" shape="circle"
  30. activeColor="#E96737" @change="changeChecked"></u-checkbox>
  31. </u-checkbox-group>
  32. </view>
  33. </view>
  34. <view class="flex btn">
  35. <view class="flex btn-left">
  36. <view class="title">应付:</view>
  37. <view class="flex coin">¥{{ $numberFormat(payInfo.payAmt) }}</view>
  38. </view>
  39. <view class="btn-right">
  40. <view class="confirm" @click="pay">立即支付</view>
  41. </view>
  42. </view>
  43. </view>
  44. </u-popup>
  45. </view>
  46. </template>
  47. <script>
  48. import $http from '@/utils/request.js'
  49. export default {
  50. name: "pay-popup",
  51. props: {
  52. payShow: {
  53. type: [Boolean],
  54. default: false
  55. },
  56. payInfo: {
  57. type: [Object],
  58. default: {}
  59. }
  60. },
  61. data() {
  62. return {
  63. checked: false,
  64. };
  65. },
  66. methods: {
  67. changeChecked(e) {
  68. this.checked = e
  69. },
  70. toCoupon() {
  71. uni.navigateTo({
  72. url: `/pages/coupon/index?couponId=${ this.payInfo.couponId }&boxId=${ this.payInfo.boxId }`
  73. })
  74. },
  75. toNotice() {
  76. uni.navigateTo({
  77. url: '/pages/about/notice'
  78. })
  79. },
  80. toRule() {
  81. uni.navigateTo({
  82. url: '/pages/about/rule'
  83. })
  84. },
  85. close() {
  86. this.checked = false
  87. this.$emit('close')
  88. },
  89. success(id) {
  90. this.checked = false
  91. this.$emit('success', id)
  92. },
  93. pay() {
  94. let _this = this
  95. let payIng = false
  96. if (!this.checked) {
  97. uni.$u.toast('请同意《盲票产品规则》');
  98. return
  99. }
  100. uni.showLoading({
  101. title: '支付中'
  102. });
  103. if (payIng) return
  104. $http.post('/api/v1/mp/user/ticket/order/submit', {
  105. suid: uni.getStorageSync('shareUid'),
  106. type: uni.getStorageSync('shareType')
  107. }).then(res => {
  108. uni.hideLoading();
  109. payIng = true
  110. if (res.code == 0) {
  111. if (res.data.needPay == 1) {
  112. $http.post('/api/v1/mp/user/ticket/order/pay', {
  113. orderId: res.data.orderId,
  114. payType: 2
  115. }).then(ele => {
  116. if (ele.code == 0) {
  117. uni.requestPayment({
  118. timeStamp: ele.data.timeStamp,
  119. nonceStr: ele.data.nonceStr,
  120. package: ele.data.package,
  121. signType: ele.data.signType,
  122. paySign: ele.data.paySign,
  123. success() {
  124. uni.showToast({
  125. title: '支付成功',
  126. icon: 'success',
  127. duration: 2000
  128. })
  129. _this.success(res.data.orderId)
  130. },
  131. fail() {
  132. payIng = false
  133. _this.close()
  134. }
  135. })
  136. } else {
  137. payIng = false
  138. _this.close()
  139. uni.$u.toast('支付失败!');
  140. }
  141. }).catch(() => {
  142. payIng = false
  143. _this.close()
  144. uni.$u.toast('支付失败!');
  145. })
  146. } else {
  147. uni.showToast({
  148. title: '支付成功',
  149. icon: 'success',
  150. duration: 2000
  151. })
  152. _this.success(res.data.orderId)
  153. }
  154. } else if (res.code == 1020) {
  155. payIng = false
  156. _this.close()
  157. uni.$u.toast(res.msg);
  158. } else {
  159. payIng = false
  160. _this.close()
  161. uni.$u.toast('支付失败!');
  162. }
  163. }).catch(() => {
  164. uni.hideLoading();
  165. payIng = false
  166. uni.$u.toast('支付失败!');
  167. })
  168. },
  169. },
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .choiceShow-wrap {
  174. min-height: 400rpx;
  175. padding: 80rpx 0 60rpx;
  176. .goods {
  177. padding: 0 20rpx;
  178. justify-content: space-between;
  179. margin-bottom: 20rpx;
  180. .image-wrap {
  181. width: 220rpx;
  182. height: 220rpx;
  183. border: 1px solid #F8F8F8;
  184. border-radius: 10rpx;
  185. image {
  186. width: 174rpx;
  187. height: 174rpx;
  188. }
  189. }
  190. .info {
  191. flex: 1;
  192. display: flex;
  193. height: 220rpx;
  194. flex-direction: column;
  195. justify-content: space-between;
  196. padding-left: 26rpx;
  197. &-title {
  198. font-size: 32rpx;
  199. line-height: 44rpx;
  200. font-weight: bold;
  201. }
  202. &-coin {
  203. display: flex;
  204. align-items: center;
  205. font-size: 32rpx;
  206. line-height: 44rpx;
  207. color: rgba(235, 112, 9, 100);
  208. font-weight: bold;
  209. image {
  210. width: 42rpx;
  211. height: 42rpx;
  212. margin-right: 20rpx;
  213. }
  214. }
  215. &-stock {
  216. line-height: 44rpx;
  217. }
  218. }
  219. }
  220. .coupon {
  221. box-sizing: border-box;
  222. height: 110rpx;
  223. line-height: 110rpx;
  224. justify-content: space-between;
  225. padding: 0 40rpx;
  226. border-top: 1px solid #F8F8F8;
  227. border-bottom: 1px solid #F8F8F8;
  228. .txt {
  229. margin: 0 24rpx;
  230. }
  231. }
  232. .agreement {
  233. box-sizing: border-box;
  234. height: 110rpx;
  235. line-height: 110rpx;
  236. justify-content: space-between;
  237. padding: 0 40rpx;
  238. border-bottom: 1px solid #F8F8F8;
  239. .txt text {
  240. color: #007aff;
  241. }
  242. }
  243. .btn {
  244. justify-content: space-between;
  245. padding: 20rpx 40rpx;
  246. &-left {
  247. .coin {
  248. display: flex;
  249. align-items: center;
  250. font-size: 32rpx;
  251. line-height: 44rpx;
  252. color: rgba(235, 112, 9, 100);
  253. margin-left: 20rpx;
  254. }
  255. }
  256. &-right {
  257. .confirm {
  258. width: 280rpx;
  259. height: 90rpx;
  260. font-size: 36rpx;
  261. line-height: 90rpx;
  262. border-radius: 10rpx;
  263. background-color: rgba(235, 112, 9, 100);
  264. color: rgba(255, 255, 255, 100);
  265. text-align: center;
  266. }
  267. }
  268. }
  269. }
  270. </style>