pay-popup.vue 6.6 KB

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