AddFunds.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <div class="container">
  3. <div class="notification-view">
  4. <div class="chat-view">
  5. <div class="notification">
  6. <div class="payBox" v-loading="fullscreenLoading">
  7. <div class="payBox-title">
  8. <div class="title">充值选择</div>
  9. </div>
  10. <div class="payBox-content">
  11. <div class="payBox-content-list">
  12. <div class="item" :class="{ 'actived': selected == index ? true : false }"
  13. v-for="(item, index) in payList" :key="index" @click="changePay(item.integralMoney, index)">
  14. <div class="itemUp">
  15. <div style="font-size: 24px;">{{ item.integral }}</div>
  16. <div style="font-size: 12px;font-weight: 400;margin-left: 2px;">积分</div>
  17. </div>
  18. <div class="itemDown">
  19. 需支付 {{ item.integralMoney }}元
  20. </div>
  21. </div>
  22. <el-popover placement="top" width="300" v-model="visible">
  23. <el-input size="small" placeholder="输入充值金额" v-model="money" oninput="value=value.match(/\d+\.?\d{0,1}/,'')" style="margin: 10px 0;"></el-input>
  24. <div style="float: left;" v-if="money">充值{{ money * 10 }}积分</div>
  25. <div style="text-align: right; margin: 0">
  26. <el-button size="small" @click="cancel()">取消</el-button>
  27. <el-button type="primary" size="small" @click="confirm()">确定</el-button>
  28. </div>
  29. <div class="item" :class="{ 'actived': selected == -1 ? true : false }" slot="reference"
  30. @click="selected = -1">
  31. <div class="itemUp" v-if="money">
  32. <div style="font-size: 24px; color: rgba(22, 24, 35, .75);">{{ money * 10 }}</div>
  33. <div style="font-size: 12px;font-weight: 400;margin-left: 2px; color: rgba(22, 24, 35, .75);">积分
  34. </div>
  35. </div>
  36. <div class="itemUp" v-else>
  37. <div style=" color: rgba(22, 24, 35, .75);">自定义金额</div>
  38. </div>
  39. <div class="itemDown">
  40. <div v-if="money">
  41. <span style="color: rgba(22, 24, 35, .75);">需支付 {{ money }}元</span> 修改
  42. </div>
  43. <div v-else style="color: rgba(22, 24, 35, .75);">最高100万元</div>
  44. </div>
  45. </div>
  46. </el-popover>
  47. </div>
  48. </div>
  49. <div class="payBox-title">
  50. <div class="title">扫码支付</div>
  51. </div>
  52. <div class="payBox-way">
  53. <div class="way-item">
  54. <div class="item-left">
  55. <div :class="{ 'gray': integralMoney ? false : true }" id="expCode" ref="expCodeRef"></div>
  56. <div v-if="!integralMoney" style="position: absolute;top: 70px;left: 30px;color: #fff;">请先选择套餐</div>
  57. </div>
  58. <div class="item-right">
  59. <div class="up">
  60. <div>应付金额</div>
  61. <div style="color: #fe2c55;margin-left: 8px;">¥ {{ integralMoney ? integralMoney : '--' }}</div>
  62. </div>
  63. <div class="center">
  64. <img style="height: 18px;" src="../assets/icon/weixinPay.png" alt="weixinpay">
  65. <div class="textStyle">微信扫码支付</div>
  66. </div>
  67. <div class="down">
  68. <div>扫码支付代表已阅读并同意</div>
  69. <a href="/RechargeAgreement" target="_blank" style="color: #04498d;">《充值协议》</a>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import QRCode from 'qrcodejs2';
  82. import { payList, getWxPayCode,queryWxPayStatus } from "@/api/pay";
  83. export default {
  84. data() {
  85. return {
  86. timerPayWxQRcode: null,
  87. timer: null,
  88. fullscreenLoading: false,
  89. money: undefined,
  90. integralMoney: undefined,
  91. visible: false,
  92. selected: -2,
  93. orderNo: undefined,
  94. rate:undefined,
  95. payList: [],
  96. payUrl:'https://dgtmall.dgtis.com/mall'
  97. };
  98. },
  99. created() {
  100. this.getPayList();
  101. this.$nextTick (function () {
  102. this.qrcode(this.payUrl);
  103. })
  104. },
  105. methods: {
  106. // 清空二维码,避免生成多个二维码
  107. delQrcode() {
  108. this.$refs.expCodeRef.innerHTML = ""
  109. },
  110. qrcode(payUrl) { // 前端根据 payUrl 生成微信支付二维码
  111. this.delQrcode();
  112. return new QRCode('expCode', {
  113. width: 150,
  114. height: 150,
  115. text: payUrl,
  116. colorDark: '#000',
  117. colorLight: '#fff'
  118. });
  119. },
  120. handlePayWxQRcode() { // 获取微信支付二维码
  121. getWxPayCode({ // 这里根据不同的后端接口去修改
  122. integral: this.integralMoney*this.rate,
  123. totalFee: this.integralMoney*1,
  124. }).then(res => {
  125. let data = res.data.data;
  126. this.fullscreenLoading = false;
  127. this.qrcode(data.payUrl); // 例如:data.payUrl 的值为 "weixin://wxpay/bizpayurl?pr=......",根据这个值生成相对应的微信支付二维码
  128. this.timer = setInterval(() => { // 通过定时器每间隔一会去请求查询微信支付状态(具体参数根据项目需要而定)
  129. this.handleQueryWxPayStatus(data.orderNo);
  130. }, 1000);
  131. this.timerPayWxQRcode = setInterval(() => { // 刷新微信支付二维码
  132. this.handlePayWxQRcode();
  133. }, 180000);
  134. }).catch(err => {
  135. this.fullscreenLoading = false;
  136. console.log(err)
  137. })
  138. },
  139. handleQueryWxPayStatus(orderNo) { // 查询微信支付状态
  140. queryWxPayStatus({ // 这里根据不同的后端接口去修改
  141. orderNo: orderNo,
  142. }).then(res => {
  143. let data = res.data.data;
  144. if (data != "订单未支付") { // 当查询到支付成功时
  145. this.$store.dispatch('GetUserInfo');
  146. this.$message({
  147. type: 'success',
  148. message: '支付成功!'
  149. });
  150. clearInterval(this.timer); // 清除定时器;
  151. clearInterval(this.timerPayWxQRcode);
  152. }
  153. }).catch(err => {
  154. console.log(err)
  155. })
  156. },
  157. cancel() {
  158. this.visible = false;
  159. this.money = '';
  160. },
  161. confirm() {
  162. clearInterval(this.timer);
  163. clearInterval(this.timerPayWxQRcode);
  164. this.visible = false;
  165. this.integralMoney = this.money;
  166. this.fullscreenLoading = true;
  167. this.handlePayWxQRcode()
  168. },
  169. changePay(integralMoney, index) {
  170. clearInterval(this.timer);
  171. clearInterval(this.timerPayWxQRcode);
  172. this.money = '';
  173. this.selected = index;
  174. this.integralMoney = integralMoney;
  175. this.fullscreenLoading = true;
  176. this.handlePayWxQRcode()
  177. },
  178. getPayList() {
  179. payList().then(response => {
  180. this.rate = response.data.data.rate;
  181. this.payList = response.data.data.items;
  182. })
  183. },
  184. },
  185. beforeDestroy() {
  186. clearInterval(this.timer);
  187. clearInterval(this.timerPayWxQRcode);
  188. }
  189. }
  190. </script>
  191. <style scoped>
  192. .gray {
  193. filter: blur(4px);
  194. }
  195. .container {
  196. position: relative;
  197. margin: 0 auto;
  198. width: 100%;
  199. max-width: 960px;
  200. }
  201. .notification-view {
  202. /* margin-top: 1.767rem; */
  203. }
  204. .chat-view {
  205. position: relative;
  206. width: 960px;
  207. }
  208. .chat-view .notification {
  209. width: 100%;
  210. margin-bottom: 1rem;
  211. /* height: 800px; */
  212. background-color: #fff;
  213. border-radius: 16px;
  214. }
  215. .payBox {
  216. /* padding: 20px 48px 40px; */
  217. }
  218. .payBox-title {
  219. display: flex;
  220. align-items: center;
  221. /* margin-top: 20px; */
  222. }
  223. .title {
  224. font-weight: 500;
  225. font-size: 24px;
  226. }
  227. .payBox-content {
  228. margin-top: 15px;
  229. margin-bottom: 26px;
  230. }
  231. .payBox-content-list {
  232. display: flex;
  233. flex-wrap: wrap;
  234. }
  235. /* .payBox-content-list .item:nth-child(4n+1) {
  236. margin-left: 0;
  237. } */
  238. .payBox-content-list .item {
  239. cursor: pointer;
  240. width: 200px;
  241. height: 120px;
  242. margin: 6px;
  243. border-radius: 6px;
  244. border: .5px solid #e7e7ec;
  245. position: relative;
  246. flex-direction: column;
  247. align-items: center;
  248. justify-content: center;
  249. background-color: #f7f7f9;
  250. display: flex;
  251. }
  252. .actived {
  253. color: #fe2c55;
  254. border: .5px solid rgba(254, 44, 85, .5) !important;
  255. background: linear-gradient(0deg, rgba(254, 44, 85, .06), rgba(254, 44, 85, .06)), #fff;
  256. }
  257. .itemUp {
  258. display: flex;
  259. font-size: 16px;
  260. align-items: baseline;
  261. font-weight: 500;
  262. }
  263. .itemDown {
  264. font-size: 12px;
  265. /* color: rgba(22, 24, 35, .75); */
  266. }
  267. .payBox-way {
  268. margin-top: 16px;
  269. }
  270. .way-item {
  271. display: flex;
  272. background-color: #f7f7f9;
  273. border-radius: 6px;
  274. padding: 12px;
  275. }
  276. .item-left {
  277. position: relative;
  278. width: 150px;
  279. height: 150px;
  280. background-color: #fff;
  281. border-radius: 6px;
  282. padding: 7px;
  283. }
  284. .item-right {
  285. margin-left: 12px;
  286. }
  287. .up {
  288. display: flex;
  289. align-items: flex-end;
  290. font-size: 18px;
  291. font-weight: 600;
  292. height: 60px;
  293. }
  294. .center {
  295. display: flex;
  296. align-items: center;
  297. margin-top: 6px;
  298. }
  299. .textStyle {
  300. font-size: 16px;
  301. font-weight: 400;
  302. margin-left: 4px;
  303. color: rgba(22, 24, 35, .34);
  304. }
  305. .down {
  306. font-size: 16px;
  307. color: rgba(22, 24, 35, .34);
  308. margin-top: 16px;
  309. display: flex;
  310. -moz-box-align: center;
  311. -ms-flex-align: center;
  312. align-items: center;
  313. }
  314. </style>