payment.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <div class="payment">
  3. <div class="content">
  4. <div class="step-box">
  5. <div class="left">
  6. <span class="img"></span>
  7. <span class="text">{{$t('payment.orderPayment')}}</span>
  8. </div>
  9. <div class="steps">
  10. <div class="item">
  11. <div class="number">step 01.</div>
  12. <div class="text">{{$t('payment.selectProductToBuy')}}</div>
  13. </div>
  14. <div class="item">
  15. <div class="number">step 02.</div>
  16. <div class="text">{{$t('payment.confirmOrderInformation')}}</div>
  17. </div>
  18. <div class="item active">
  19. <div class="number">step 03.</div>
  20. <div class="text">{{$t('payment.payToCompleteTheOrder')}}</div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="payment-con">
  25. <div class="pay-box">
  26. <div class="pay-info">
  27. <div class="tag success"></div>
  28. <div class="item">
  29. <div class="tit">{{$t('payment.orderSubmittedSuccessfully')}}!</div>
  30. <div class="total-pay">
  31. {{$t('payment.totalPayable')}}:
  32. <span class="price">
  33. <span v-if="payOrderInfo.totalFee">¥{{payOrderInfo.totalFee}}</span>
  34. <span v-if="payOrderInfo.totalFee &&payOrderInfo.totalScore">+</span>
  35. <span v-if="payOrderInfo.totalScore">{{payOrderInfo.totalScore}}{{$t('payment.points')}}</span>
  36. </span>
  37. </div>
  38. </div>
  39. <div class="item">
  40. <div class="time" v-if="isOverTime && $t('language') == 'zh' ">
  41. 请在
  42. <span class="warning">{{min}} : {{sec}}</span>内付款,否则交易会被取消。
  43. </div>
  44. <div class="time" v-if="isOverTime && $t('language') == 'en'">
  45. please pay within
  46. <span class="warning">{{min}} : {{sec}}</span>,otherwise the transaction will be cancelled。
  47. </div>
  48. <div class="rest-time" v-if="!isOverTime">{{$t('payment.orderHasExpired')}}</div>
  49. <div class="order-det" @click="showOrderInfo = !showOrderInfo">{{$t('payment.orderDetails')}}</div>
  50. </div>
  51. </div>
  52. <div class="order-info" v-if="showOrderInfo">
  53. <div v-if="mold !=1 " class="text">
  54. <div v-if="payOrderInfo.receiver||payOrderInfo.mobile||payOrderInfo.userAddr">
  55. <div class="label" :style="this.$store.state.locale =='en'?'width: 140px':'width: 70px'">{{$t('payment.receiptInformation')}}:</div>
  56. <div class="con">{{payOrderInfo.receiver}} {{payOrderInfo.mobile}}</div>
  57. <div class="con">{{payOrderInfo.userAddr}}</div>
  58. </div>
  59. </div>
  60. <div class="text">
  61. <div class="label" :style="this.$store.state.locale =='en'?'width: 140px':'width: 70px'">{{$t('payment.productName')}}:</div>
  62. <div class="con con-items">
  63. <div class="item" v-for="item in payOrderInfo.prodNameList" :key="item">{{item}}</div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <div class="section-payment">
  69. <div class="tit" v-if="payOrderInfo.totalFee>0">{{$t('payment.selectPaymentMethod')}}</div>
  70. <div class="con" v-if="payOrderInfo.totalFee>0">
  71. <div
  72. v-if="paySwitchInfo.aliPaySwitch"
  73. class="item"
  74. :class="{active: payType === PayTypeConstant.ALIPAY}"
  75. @click="payType = PayTypeConstant.ALIPAY"
  76. >
  77. <img src="~/assets/images/payment-aliPay.png" alt />
  78. <span class="payment-text">{{$t('payment.aliPay')}}</span>
  79. <div v-html="payHtml"></div>
  80. </div>
  81. <div
  82. v-if="paySwitchInfo.wxPaySwitch"
  83. class="item"
  84. :class="{active: payType === PayTypeConstant.WECHATPAY_SWEEP_CODE}"
  85. @click="payType = PayTypeConstant.WECHATPAY_SWEEP_CODE"
  86. >
  87. <img src="~/assets/images/payment-wechatPay.png" alt />
  88. <span class="payment-text">{{$t('payment.wechatPay')}}</span>
  89. </div>
  90. <div
  91. v-if="paySwitchInfo.payPalSwitch"
  92. class="item paypal"
  93. :class="{active: payType === PayTypeConstant.PAYPAL}"
  94. @click="payType = PayTypeConstant.PAYPAL"
  95. >
  96. <img class="paypal-logo" src="~/assets/images/paypal.png" alt />
  97. <img class="paypal-text" src="~/assets/images/paypal-text.png" alt />
  98. </div>
  99. <div
  100. class="item paypal item-balance"
  101. :class="{active: payType === PayTypeConstant.BALANCEPAY}"
  102. @click="payType = PayTypeConstant.BALANCEPAY"
  103. >
  104. <img class="paypal-logo item-balance-img" src="~/assets/images/balancePay.png" alt />
  105. <div class="payment-text item-balance-div">{{$t('payment.balancePay')}}<span class="item-balance-span">({{$t('payment.availableBalance')}}:{{currentBalance}})</span></div>
  106. </div>
  107. <!-- <div class="item"><img src="~/assets/images/unionpay.png"
  108. alt=""></div>-->
  109. </div>
  110. <a
  111. href="javascript:void(0)"
  112. :class="[isCanPay ? '' : 'no-pay', 'btn']"
  113. @click="toPay"
  114. >{{$t('payment.payNow')}}</a>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import { PayType } from '~/plugins/constant'
  122. import util from '../plugins/util'
  123. export default {
  124. data () {
  125. return {
  126. orderNumber: '', //订单号
  127. total: 0, //订单价
  128. payHtml: '', //支付宝页面
  129. min: '00', //分
  130. sec: '00', //秒
  131. timer: null, //倒计时变量
  132. payOrderInfo: {}, //支付订单详情
  133. showOrderInfo: false, //是否显示订单详情
  134. payType: PayType.ALIPAY, //支付类型,默认支付宝
  135. PayTypeConstant: PayType, //支付类型常量
  136. isCanPay: true, //是否能支付
  137. isOverTime: true, //能否支付的文字提示
  138. loading: false, //PayPal支付的加载缓冲弹窗
  139. mold: null,
  140. currentBalance: 0 //余额
  141. }
  142. },
  143. computed: {
  144. // 从缓存获取系统支付开关
  145. paySwitchInfo() {
  146. return JSON.parse(localStorage.getItem('paySwitchInfo')).switchInfo
  147. }
  148. },
  149. mounted () {
  150. this.orderNumber = sessionStorage.getItem("pay_orderNumber")
  151. this.total = sessionStorage.getItem("pay_total")
  152. this.mold = Number(sessionStorage.getItem("pay_mold"))
  153. this.getOrderDetail()
  154. this.setDefaultPayType()
  155. this.getBalanceInfo()
  156. },
  157. methods: {
  158. /**
  159. * 设置默认支付类型
  160. */
  161. setDefaultPayType() {
  162. if (this.paySwitchInfo.aliPaySwitch) {
  163. return
  164. }
  165. if (this.paySwitchInfo.wxPaySwitch) {
  166. this.payType = PayType.WECHATPAY_SWEEP_CODE
  167. return
  168. }
  169. if (this.paySwitchInfo.balancePaySwitch) {
  170. this.payType = PayType.WECHATPAY_SWEEP_CODE
  171. return
  172. }
  173. if (this.paySwitchInfo.payPalSwitch) {
  174. this.payType = PayType.PAYPAL
  175. }
  176. },
  177. // 请求支付订单详情
  178. getOrderDetail () {
  179. this.$axios.get('/p/order/getOrderPayInfoByOrderNumber', {
  180. params: {
  181. orderNumbers: this.orderNumber
  182. }
  183. }).then(({ data }) => {
  184. this.payOrderInfo = data
  185. this.countTime()
  186. })
  187. },
  188. //获取余额信息
  189. getBalanceInfo () {
  190. this.$axios.get('/p/userBalance/getBalanceInfo').then(({ data }) => {
  191. this.currentBalance = data
  192. })
  193. },
  194. // 倒计时
  195. countTime (hu) {
  196. // 获取当前时间
  197. let date = new Date()
  198. let now = date.getTime()
  199. // // 设置截止时间()
  200. let end = new Date(this.payOrderInfo.endTime).getTime()
  201. // 时间差
  202. let leftTime = end - now
  203. // 定义变量 d,h,m,s保存倒计时的时间
  204. if (leftTime >= 0) {
  205. // 分
  206. let m = Math.floor(leftTime / 1000 / 60 % 60)
  207. this.min = m < 10 ? '0' + m : m
  208. // 秒
  209. let s = Math.floor(leftTime / 1000 % 60)
  210. this.sec = s < 10 ? '0' + s : s
  211. } else {
  212. this.min = '00'
  213. this.sec = '00'
  214. this.isOverTime = false
  215. this.isCanPay = false
  216. }
  217. // 等于0的时候不调用
  218. if (Number(this.min) === 0 && Number(this.sec) === 0) {
  219. return
  220. } else {
  221. // 递归每秒调用countTime方法,显示动态时间效果,
  222. this.timer = setTimeout(this.countTime, 1000)
  223. }
  224. },
  225. //去支付
  226. toPay () {
  227. if (this.isCanPay && this.payOrderInfo.totalFee == 0 && this.payOrderInfo.totalScore) {
  228. // 纯积分
  229. this.$axios.post('/p/order/pay', {
  230. payType: PayType.SCOREPAY,
  231. orderNumbers: this.orderNumber,
  232. }).then(({ data }) => {
  233. this.$router.push({ path: '/user-center/uc-order' })
  234. })
  235. return
  236. }
  237. if (this.isCanPay) {
  238. var type = this.payType
  239. if (type == PayType.ALIPAY) {
  240. this.$axios.post('/p/order/pay', {
  241. payType: type,
  242. orderNumbers: this.orderNumber,
  243. returnUrl: window.location.origin + '/user-center/uc-order'
  244. }).then(({ data }) => {
  245. // 支付宝部分
  246. this.payHtml = data
  247. this.$nextTick(() => {
  248. document.forms[0].submit()
  249. })
  250. }).catch((err) => {
  251. util.getSysPaySwitch(true)
  252. })
  253. } else if (type == PayType.WECHATPAY_SWEEP_CODE) {
  254. // 微信部分
  255. this.$router.push({
  256. path: '/weixin-pay'
  257. })
  258. } else if (type == PayType.PAYPAL) {
  259. // PayPal部分
  260. const loading = this.$loading({
  261. lock: true,
  262. text: this.$i18n.t('loading'),
  263. background: 'rgba(255, 255, 255, 0.8)'
  264. });
  265. this.$axios.post('/p/order/pay', {
  266. payType: type,
  267. orderNumbers: this.orderNumber,
  268. returnUrl: window.location.origin + '/user-center/uc-order'
  269. }).then(({ data }) => {
  270. window.location.href = data
  271. // setTimeout(() => {
  272. // loading.close();
  273. // },1000)
  274. })
  275. } else if (type == PayType.BALANCEPAY) {
  276. // 余额部分
  277. if (parseFloat(this.payOrderInfo.totalFee) > parseFloat(this.currentBalance)) {
  278. this.$message({
  279. message: this.$t('payment.balanceTip') + this.currentBalance,
  280. type: 'none',
  281. duration: 3000
  282. })
  283. return
  284. }
  285. var that = this
  286. this.$confirm(this.$t("myBalance.payTips"), this.$t("tips"), {
  287. distinguishCancelAndClose: true,
  288. confirmButtonText: this.$t("determine"),
  289. cancelButtonText: this.$t("cancel")
  290. }).then(() => {
  291. this.$axios.post('/p/order/pay', {
  292. payType: type,
  293. orderNumbers: this.orderNumber,
  294. returnUrl: window.location.origin + '/user-center/uc-order'
  295. }).then(({ data }) => {
  296. this.$message({
  297. message: this.$t('payment.paymentSuccessful'),
  298. type: 'success',
  299. duration: 1000,
  300. onClose() {
  301. that.$router.push({ path: '/user-center/uc-order' })
  302. }
  303. })
  304. })
  305. }).catch((action) => {})
  306. }
  307. } else {
  308. return false
  309. }
  310. }
  311. },
  312. destroyed () {
  313. if (this.timer) { //如果定时器在运行则关闭
  314. clearInterval(this.timer);
  315. }
  316. }
  317. }
  318. </script>
  319. <style scoped src='~/assets/css/payment.css'></style>