recharge.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <!--
  2. * @Author: wangwei
  3. * @Date: 2020-12-29 16:05:36
  4. * @LastEditTime: 2021-01-25 14:31:14
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 充值
  7. * @FilePath: /java-pc/src/views/member/money/recharge.vue
  8. -->
  9. <template>
  10. <div class="sld_recharge">
  11. <MemberTitle :memberTitle="L['账户充值']"></MemberTitle>
  12. <div class="sld_recharge_con" v-if="rechargeSetting == 1">
  13. <div class="top_info">
  14. <div class="progress flex_row_center_center">
  15. <div class="step step1 flex_row_start_center">
  16. <span class="line"></span>
  17. <i
  18. class="iconfont icon-querenyuanzhengqueduigoutijiaochenggongwancheng"
  19. ></i>
  20. <span class="step_text">{{ L["1.填写充值金额"] }}</span>
  21. </div>
  22. <div class="step step2 flex_row_start_center">
  23. <span
  24. class="no_line"
  25. :class="{ sel_line: current_step == 2 }"
  26. ></span>
  27. <i
  28. class="iconfont icon-querenyuanzhengqueduigoutijiaochenggongwancheng"
  29. :class="{ no_sel: current_step == 1 }"
  30. ></i>
  31. <span
  32. class="no_step_text"
  33. :class="{ step_text: current_step == 2 }"
  34. >{{ L["2.在线支付"] }}</span
  35. >
  36. </div>
  37. <div class="step step3 flex_row_start_center">
  38. <span class="no_line"></span>
  39. <i
  40. class="iconfont icon-querenyuanzhengqueduigoutijiaochenggongwancheng no_sel"
  41. ></i>
  42. <span class="no_step_text">{{ L["3.充值完成"] }}</span>
  43. </div>
  44. </div>
  45. </div>
  46. <!-- step1 start -->
  47. <div v-if="current_step == 1" class="step_con step1">
  48. <div class="title">{{ L["填写充值金额"] }}</div>
  49. <div class="account">
  50. {{ L["充值账户"] }}:{{ filtersStore.getMemberInfo.memberName }}
  51. </div>
  52. <div class="input_con flex_row_start_center">
  53. <span class="input_span">{{ L["充值金额"] }}:</span>
  54. <div class="input_con_right">
  55. <el-input
  56. class="input"
  57. size="medium"
  58. v-model="money"
  59. placeholder="请输入金额"
  60. @input="moneyInput"
  61. >
  62. </el-input
  63. >元
  64. <div class="info_text">
  65. {{
  66. L[
  67. "请注意:支持支付宝支付、微信支付,在线支付成功后,充值金额会在1到5分钟内到账"
  68. ]
  69. }}
  70. </div>
  71. <div class="next_btn pointer" @click="goStep2">
  72. {{ L["下一步"] }}
  73. </div>
  74. </div>
  75. </div>
  76. <div class="tips">
  77. <p>{{ L["温馨提示"] }}:</p>
  78. <p>
  79. {{
  80. L[
  81. "1.充值成功后,余额可能存在延迟现象,一般1到5分钟内到账,如有问题,请咨询客服;"
  82. ]
  83. }}
  84. </p>
  85. <p>{{ L["2.充值金额输入值必须是不小于1且不大于5000;"] }}</p>
  86. <p>{{ L["3.充值完成后,您可至会员中心查看充值记录。"] }}</p>
  87. </div>
  88. </div>
  89. <!-- step1 end -->
  90. <!-- step2 start -->
  91. <div v-if="current_step == 2" class="reching_tip flex_column_start_start">
  92. <span>{{
  93. show_wx_pay
  94. ? L["请使用手机微信扫描下方二维码进行支付"]
  95. : L["您正在充值余额,请尽快支付"]
  96. }}</span>
  97. <span
  98. >{{ show_wx_pay ? L["应付金额"] : L["充值金额"] }}:<span
  99. >¥{{ money }} 元</span
  100. >
  101. </span>
  102. </div>
  103. <div v-if="current_step == 2" class="step_con step2">
  104. <div v-if="!show_wx_pay" class="select_method flex_row_start_center">
  105. <span class="method">{{ L["选择充值方式"] }}:</span>
  106. <div class="flex_row_start_center">
  107. <div
  108. v-for="(item, index) in method.data"
  109. :key="index"
  110. class="item ali flex_row_around_center pointer"
  111. @click="changePayMethod(item)"
  112. >
  113. <i
  114. :class="{
  115. iconfont: true,
  116. 'icon-yuanquan1': true,
  117. 'icon-duihao1':
  118. currentMethod.data.payMethod == item.payMethod,
  119. }"
  120. ></i>
  121. <img
  122. :src="
  123. item.payMethod == 'wx'
  124. ? wechat
  125. : item.payMethod == 'alipay'
  126. ? ali
  127. : ''
  128. "
  129. alt
  130. />
  131. <span>{{ item.payMethodName }}</span>
  132. </div>
  133. </div>
  134. </div>
  135. <div v-if="!show_wx_pay" class="pay_btn pointer" @click="goPay">
  136. {{ L["立即充值"] }}
  137. </div>
  138. <!-- 微信支付 start-->
  139. <div v-if="show_wx_pay" class="wx_pay_con">
  140. <div class="wx_pay_info">
  141. <span class="pay_type">{{ L["微信支付支付"] }}</span>
  142. <span>
  143. {{ L["如二维码过期,"] }}
  144. <span class="red" @click="wxPayRefresh" style="cursor: pointer">{{
  145. L["刷新"]
  146. }}</span
  147. >{{ L["重新获取二维码。"] }}
  148. </span>
  149. </div>
  150. <div class="qrcode_con flex_row_start_center">
  151. <div class="left flex_column_start_center">
  152. <div class="qrcode_image flex_row_center_center">
  153. <img :src="wxPayQrImg" alt="" />
  154. </div>
  155. <div class="qrcode_image_tips flex_row_center_center">
  156. <i class="iconfont icon-saoma"></i>
  157. <span>{{ L["使用微信扫码支付"] }}</span>
  158. </div>
  159. </div>
  160. <div class="right_tip">
  161. <img src="/member/wx_tips.png" alt />
  162. </div>
  163. </div>
  164. </div>
  165. <!-- 微信支付 end-->
  166. </div>
  167. <!-- step2 end -->
  168. </div>
  169. <div class="sld_recharge_con" v-else>
  170. <SldCommonEmpty
  171. :tip="L['暂未开启充值功能']"
  172. totalWidth="1005"
  173. ></SldCommonEmpty>
  174. </div>
  175. </div>
  176. </template>
  177. <script setup>
  178. import { ElInput, ElMessage } from "element-plus";
  179. import {
  180. getCurrentInstance,
  181. ref,
  182. watch,
  183. reactive,
  184. onMounted,
  185. onUnmounted,
  186. } from "vue";
  187. // import { lang_zn } from "@/assets/language/zh";
  188. import { getCurLanguage } from '@/composables/common.js';
  189. import { useFiltersStore } from "@/store/filter.js";
  190. const router = useRouter()
  191. const filtersStore = useFiltersStore();
  192. // const L = lang_zn;
  193. const L = getCurLanguage();
  194. definePageMeta({
  195. layout: "member",
  196. middleware: ["auth"],
  197. });
  198. const { proxy } = getCurrentInstance();
  199. const saoma = ref("/coupon/saoma.png");
  200. const ali = ref("/buy/ali.png");
  201. const wechat = ref("/buy/wechat.png");
  202. const wx_pay_tip = ref("/coupon/phone-bg.png");
  203. const money = ref("");
  204. const current_step = ref(1);
  205. const method = reactive({ data: [] });
  206. const currentMethod = reactive({
  207. data: {},
  208. });
  209. const rechargeSetting = ref("");
  210. const show_wx_pay = ref(false);
  211. const wxPayQrImg = ref("");
  212. const timer = ref(0); //定时器
  213. const rechargeId = ref("");
  214. const goStep2 = () => {
  215. if (money.value == "") {
  216. ElMessage.warning(L["请输入充值金额"]);
  217. return;
  218. } else if (money.value > 5000) {
  219. ElMessage.warning(L["超过充值金额上限"]);
  220. return;
  221. }
  222. current_step.value = 2;
  223. };
  224. //获取充值方式
  225. const getRechargeMethod = () => {
  226. get("v3/business/front/orderPay/payMethod", {
  227. source: "pc",
  228. type: 2,
  229. })
  230. .then((res) => {
  231. if (res.state == 200) {
  232. method.data = res.data;
  233. if (method.data.length > 0) {
  234. currentMethod.data = method.data[0];
  235. }
  236. } else {
  237. ElMessage(res.msg);
  238. }
  239. })
  240. .catch(() => {
  241. //异常处理
  242. });
  243. };
  244. //切换充值方式
  245. const changePayMethod = (item) => {
  246. currentMethod.data = item;
  247. };
  248. const moneyInput = () => {
  249. if (money.value < 5000) {
  250. money.value =
  251. money.value.toString().indexOf(".") == -1
  252. ? money.value
  253. : money.value
  254. .toString()
  255. .substring(0, money.value.toString().indexOf(".") + 3) > 0
  256. ? money.value
  257. .toString()
  258. .substring(0, money.value.toString().indexOf(".") + 3)
  259. : "";
  260. } else {
  261. money.value =
  262. money.value.slice(0, 4) > 5000 ? 5000 : money.value.slice(0, 4);
  263. }
  264. };
  265. const wxPayRefresh = () => {
  266. goPay();
  267. };
  268. //去支付
  269. const goPay = () => {
  270. if (!currentMethod.data.payMethod) {
  271. ElMessage.warning(L["请选择支付方式"]);
  272. return;
  273. }
  274. let param = {};
  275. param.payType = currentMethod.data.payType;
  276. param.payMethod = currentMethod.data.payMethod;
  277. param.amount = money.value;
  278. //请求支付接口
  279. post("v3/member/front/balanceRecharge/recharge", param)
  280. .then((res) => {
  281. if (res.state == 200) {
  282. if (param.payMethod == "alipay") {
  283. document.write(res.data.payData); //自动提交表单数据
  284. } else if (param.payMethod == "wx") {
  285. rechargeId.value = res.data.rechargeId;
  286. show_wx_pay.value = true;
  287. wxPayQrImg.value = "data:image/png;base64," + res.data.payData; //微信支付二维码
  288. // 定时查询是否支付成功
  289. timer.value = setInterval(() => {
  290. queryPayState();
  291. }, 3000);
  292. //两小时自动跳转充值列表
  293. setTimeout(() => {
  294. router.replace({
  295. path: "/member/balance",
  296. });
  297. }, 432000000);
  298. }
  299. } else {
  300. ElMessage(res.msg);
  301. }
  302. })
  303. .catch(() => {
  304. //异常处理
  305. });
  306. };
  307. // 定时查询是否支付成功
  308. const queryPayState = () => {
  309. getPayInfo();
  310. };
  311. //获取充值明细 --用于判断充值是否成功
  312. const getPayInfo = () => {
  313. get("v3/member/front/balanceRecharge/detail", {
  314. rechargeId: rechargeId.value,
  315. })
  316. .then((res) => {
  317. if (res.state == 200) {
  318. if (res.data.payState == 2) {
  319. //清除定时器
  320. if (timer.value) {
  321. clearInterval(timer.value);
  322. timer.value = 0;
  323. }
  324. if (
  325. window.history.state.back == "/member/balance" ||
  326. !window.history.state.back
  327. ) {
  328. ElMessage.success(L["充值成功,2s后自动跳转充值列表"]);
  329. setTimeout(() => {
  330. router.replace({
  331. path: "/member/balance",
  332. });
  333. }, 2000);
  334. } else {
  335. ElMessage.success(L["充值成功,2s后自动跳转支付页面"]);
  336. setTimeout(() => {
  337. router.go(-1);
  338. }, 2000);
  339. }
  340. }
  341. } else {
  342. ElMessage(res.msg);
  343. }
  344. })
  345. .catch(() => {
  346. //异常处理
  347. });
  348. };
  349. watch(money, (newVal, oldVal) => {
  350. if (newVal == "") {
  351. money.value = "";
  352. return;
  353. }
  354. var reg = /^[1-9]\d*\.?\d*$/;
  355. if (!reg.test(newVal)) {
  356. money.value = oldVal;
  357. }
  358. });
  359. const getReChargeSetting = () => {
  360. get("v3/system/front/setting/getSettings", {
  361. names: "recharge_is_enable",
  362. })
  363. .then((res) => {
  364. if (res.state == 200) {
  365. rechargeSetting.value = res.data[0];
  366. if (rechargeSetting.value == "1") {
  367. getRechargeMethod();
  368. }
  369. }
  370. });
  371. };
  372. onMounted(() => {
  373. nextTick(()=>{
  374. getReChargeSetting();
  375. })
  376. });
  377. onUnmounted(() => {
  378. if (timer.value) {
  379. clearInterval(timer.value);
  380. timer.value = 0;
  381. }
  382. });
  383. </script>
  384. <style lang="scss">
  385. @use "@/assets/style/recharge.scss" as *;
  386. .el-input.is-active .el-input__inner,
  387. .el-input__inner:focus {
  388. border-color: $colorMain;
  389. outline: 0;
  390. }
  391. /**
  392. * 解决el-input设置类型为number时,中文输入法光标上移问题
  393. **/
  394. .el-input__inner {
  395. line-height: 1px !important;
  396. }
  397. </style>