index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <script setup lang="ts">
  2. import { mapState } from 'pinia'
  3. import { useI18n } from 'vue-i18n'
  4. import { ref, watch, onMounted, nextTick } from 'vue'
  5. import logoCn from '@/assets/images/logoCn.png'
  6. import logoEn from '@/assets/images/logoEn.png'
  7. import { useUserStore } from '@/stores/user'
  8. import QrcodeVue from 'qrcode.vue'
  9. import { show, showConfirm } from '@/components/Toast'
  10. import { openPay, queryOrderStatus, getOrderInfo } from '@/api/api'
  11. import { useRouter, useRoute } from 'vue-router'
  12. import { GetRequest } from '@/utils/index'
  13. import { getCurrentInstance } from 'vue'
  14. //得到i18n的locale token, info,
  15. const { locale: language, t } = useI18n()
  16. let t1 = null
  17. const route = useRoute()
  18. const { isEur, info } = useUserStore()
  19. console.log('route', route)
  20. const orderSn = ref(route.query.id || GetRequest('orderSn'))
  21. let { $cdn } = getCurrentInstance()?.proxy
  22. let PAYSID = {
  23. wechatPay: 0,
  24. alipay: 1,
  25. paypal: 2
  26. }
  27. const selectedPayType = ref('alipay')
  28. watch(selectedPayType, () => {
  29. getCode()
  30. })
  31. const qrCodeUrl = ref('')
  32. const orderDetal = ref({})
  33. const response = ref({
  34. price: 0.01,
  35. src: ''
  36. })
  37. console.log('orderSn', orderSn, route)
  38. onMounted(() => {
  39. getDetial()
  40. getCode()
  41. })
  42. function inverRequest() {
  43. clearInterval(t1)
  44. t1 = null
  45. t1 = setInterval(() => {
  46. handleQueryOrderStatus()
  47. }, 5000)
  48. }
  49. async function handleQueryOrderStatus() {
  50. if (t1) {
  51. let response = await getOrderInfo(orderSn.value)
  52. console.log('response', response)
  53. orderDetal.value = response
  54. if (response.payStatus === 0) {
  55. //未支付
  56. console.log('未支付')
  57. } else {
  58. //支付失败
  59. t1 = null
  60. t1 && clearInterval(t1)
  61. showConfirm({
  62. text: response.payStatus === 2 ? t('payInfo.payfail') : t('mall.paySuccessTip'),
  63. type: response.payStatus === 2 ? 'err' : 'success',
  64. callback: () => {
  65. if (response.payStatus === 2) {
  66. getCode()
  67. } else {
  68. window.close()
  69. }
  70. }
  71. })
  72. }
  73. }
  74. }
  75. function getDetial() {
  76. getOrderInfo(orderSn.value).then((res) => {
  77. orderDetal.value = res
  78. })
  79. }
  80. async function getCode() {
  81. qrCodeUrl.value = ''
  82. let paysidtype = {
  83. wechatPay: 2,
  84. alipay: 3,
  85. paypal: 0
  86. }
  87. openPay({
  88. orderSn: orderSn.value,
  89. payType: paysidtype[selectedPayType.value],
  90. openId: ''
  91. }).then((res) => {
  92. qrCodeUrl.value = res.qrCodeUrl
  93. inverRequest()
  94. })
  95. }
  96. </script>
  97. <template>
  98. <div class="pcPage">
  99. <div class="mall-pay">
  100. <div class="container">
  101. <div class="pay-header">
  102. <div class="logo">
  103. <img :src="language === 'zh' ? logoCn : logoEn" alt="" />
  104. </div>
  105. <p>{{ $t('mall.payCenter') }}</p>
  106. </div>
  107. <div class="pay-content">
  108. <div class="account">
  109. <span class="label">{{ $t('mall.nowAccount') }}:</span
  110. ><span>{{ orderDetal.userName }}</span>
  111. </div>
  112. <div class="account">
  113. <span class="label"
  114. >{{ $t(`mall.${orderDetal.orderType == 'incrementOrder'?'vip':orderDetal.orderType == 'downOrder'?'downdesc':'goqy'}`) }}:
  115. <span>
  116. <span v-if="orderDetal.goodsInfo && orderDetal.goodsInfo[0]">{{orderDetal.goodsInfo[0].name}}{{
  117. orderDetal.goodsInfo[0].count
  118. }}</span>
  119. <span v-else>1</span>
  120. <span v-if="orderDetal.orderType == 'incrementOrder'">,{{ $t(`payInfo.expiration`,{num:1}) }}</span>
  121. </span
  122. ></span
  123. >
  124. </div>
  125. <div class="pay-types">
  126. <p class="label">{{ $t('mall.payType') }}:</p>
  127. <div
  128. class="pay-type ali-pay"
  129. @click="selectedPayType = 'alipay'"
  130. :class="{ 'is-active': selectedPayType === 'alipay' }"
  131. >
  132. <img :src="`${$cdn}images/ali-pay.png`" class="t-icon" alt />
  133. <h-icon type="vip_true" class="select-icon"></h-icon>
  134. <img :src="`${$cdn}images/tag-icon.png`" class="t-click" alt />
  135. {{ $t('mall.aliPay') }}
  136. </div>
  137. <div
  138. class="pay-type wechat-pay"
  139. @click="selectedPayType = 'wechatPay'"
  140. :class="{ 'is-active': selectedPayType === 'wechatPay' }"
  141. >
  142. <img :src="`${$cdn}images/wechat-pay.png`" class="t-icon" alt />
  143. <h-icon type="vip_true" class="select-icon"></h-icon>
  144. <img :src="`${$cdn}images/tag-icon.png`" class="t-click" alt />
  145. {{ $t('mall.wechatPay') }}
  146. </div>
  147. <div
  148. v-if="isEur"
  149. class="pay-type paypal-pay"
  150. @click="selectedPayType = 'paypal'"
  151. :class="{ 'is-active': selectedPayType === 'paypal' }"
  152. >
  153. <img :src="`${$cdn}images/paypal.png`" class="t-icon" alt />
  154. <h-icon type="vip_true" class="select-icon"></h-icon>
  155. <img :src="`${$cdn}images/tag-icon.png`" class="t-click" alt />
  156. paypal
  157. </div>
  158. </div>
  159. <div class="pay-info">
  160. <p class="label">{{ $t('mall.payNum') }}:</p>
  161. <p class="price">¥{{ response.price }}</p>
  162. <div class="pay-qrcode" style="min-height: 220px">
  163. <QrcodeVue
  164. v-if="qrCodeUrl"
  165. :value="qrCodeUrl"
  166. class="enter-x flex justify-center xl:justify-start"
  167. :size="190"
  168. />
  169. <p>
  170. {{
  171. $t('mall.payTip', {
  172. type: selectedPayType === 'alipay' ? $t('mall.aliPay') : $t('mall.wechat')
  173. })
  174. }}
  175. </p>
  176. </div>
  177. <div :class="`pay-scan-tip ${language === 'zh' ? '' : 'isEn'}`"></div>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. </template>
  184. <style lang="less" scoped>
  185. .mall-pay {
  186. padding: 61px 0 61px;
  187. background: #f7f7f7;
  188. .container {
  189. background: #fff;
  190. }
  191. .pay-header {
  192. border-bottom: 1px solid #e4e4e4;
  193. padding: 26px 0 21px 92px;
  194. font-size: 24px;
  195. line-height: 32px;
  196. .logo,
  197. p {
  198. display: inline-block;
  199. vertical-align: middle;
  200. }
  201. .logo {
  202. margin-right: 52px;
  203. position: relative;
  204. &::after {
  205. content: '';
  206. display: block;
  207. width: 1px;
  208. height: 34px;
  209. background: #c8c8c8;
  210. position: absolute;
  211. right: -30px;
  212. top: 11px;
  213. }
  214. }
  215. }
  216. .pay-content {
  217. padding: 0 92px 80px;
  218. }
  219. .account {
  220. height: 56px;
  221. line-height: 56px;
  222. font-weight: bold;
  223. border-bottom: 1px solid #e4e4e4;
  224. }
  225. .label {
  226. font-weight: bold;
  227. margin-right: 13px;
  228. }
  229. .pay-types {
  230. padding: 50px 0;
  231. border-bottom: 1px solid #e4e4e4;
  232. & > p,
  233. & > div {
  234. display: inline-block;
  235. }
  236. .pay-type {
  237. width: 190px;
  238. height: 40px;
  239. line-height: 40px;
  240. margin-right: 30px;
  241. border: 1px solid #909090;
  242. border-radius: 2px;
  243. padding-left: 60px;
  244. cursor: pointer;
  245. position: relative;
  246. &.is-active {
  247. border-color: @primary-color;
  248. &::after {
  249. content: '';
  250. display: block;
  251. position: absolute;
  252. right: 0;
  253. bottom: 0;
  254. border-bottom: 20px solid @primary-color;
  255. border-left: 22px solid transparent;
  256. }
  257. .t-click {
  258. display: block;
  259. }
  260. }
  261. .select-icon {
  262. color: #fff;
  263. position: absolute;
  264. bottom: 0;
  265. right: 0;
  266. z-index: 1;
  267. line-height: 1;
  268. font-size: 12px;
  269. }
  270. .t-icon {
  271. width: 30px;
  272. height: 30px;
  273. padding: 6px;
  274. left: 0;
  275. position: absolute;
  276. }
  277. .t-click {
  278. position: absolute;
  279. right: 0;
  280. bottom: 0;
  281. display: none;
  282. display: none;
  283. }
  284. }
  285. .pay-icon {
  286. position: absolute;
  287. left: 4px;
  288. top: 0;
  289. height: 40px;
  290. width: 34px;
  291. display: inline-block;
  292. background: url(~@/assets/images/refactor/mall/ali-icon.png) no-repeat center center;
  293. background-size: 34px 34px;
  294. &.wechat-icon {
  295. background: url(~@/assets/images/refactor/mall/wechat-icon.png) no-repeat center center;
  296. background-size: 28px 25px;
  297. }
  298. }
  299. }
  300. .pay-info {
  301. padding-top: 24px;
  302. position: relative;
  303. & > p {
  304. display: inline-block;
  305. vertical-align: middle;
  306. }
  307. .price {
  308. color: @primary-color;
  309. font-size: 40px;
  310. line-height: 50px;
  311. }
  312. }
  313. .pay-qrcode {
  314. padding: 60px 0 0 337px;
  315. img {
  316. width: 190px;
  317. height: 190px;
  318. margin-bottom: 7px;
  319. display: block;
  320. }
  321. }
  322. .pay-scan-tip {
  323. width: 186px;
  324. height: 165.5px;
  325. background: url(@/assets/images/scan-tip.png) no-repeat center center;
  326. background-size: contain;
  327. position: absolute;
  328. top: 113px;
  329. left: 562px;
  330. &.isEn {
  331. background-image: url(@/assets/images/scan-tip-en.png);
  332. }
  333. }
  334. }
  335. </style>