Ipay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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': checked ? false : true }" id="expCode" ref="expCodeRef"></div>
  56. <div v-if="!checked" class="grayText">请先阅读并同意相关协议再扫码支付</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. <el-checkbox v-model="checked" style="margin-right: 5px;font-size: 16px;"></el-checkbox>
  69. <div>
  70. 请阅读并同意
  71. </div>
  72. <span style="color: #04498d;cursor: pointer;" @click="getHtmldata()">《充值协议》</span>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <el-dialog
  82. title="用户充值协议"
  83. :visible.sync="dialogVisible"
  84. width="50%">
  85. <div v-html="htmlData"></div>
  86. <span slot="footer" class="dialog-footer" style="display: flex;justify-content: center">
  87. <el-button style="width:50%;font-size: 24px;" type="danger" @click="dialogVisible = false">我已知晓</el-button>
  88. </span>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script>
  93. import QRCode from 'qrcodejs2';
  94. import { dictList } from "@/api/allApi";
  95. import { payList, getWxPayCode,queryWxPayStatus } from "@/api/pay";
  96. export default {
  97. data() {
  98. return {
  99. checked:false,
  100. htmlData:'',
  101. dialogVisible: false,
  102. timerPayWxQRcode: null,
  103. timer: null,
  104. fullscreenLoading: false,
  105. money: undefined,
  106. integralMoney: undefined,
  107. visible: false,
  108. selected: 0,
  109. orderNo: undefined,
  110. rate:undefined,
  111. payList: [],
  112. payUrl:'https://dgtmall.dgtis.com/mall'
  113. };
  114. },
  115. created() {
  116. this.getPayList();
  117. // this.$nextTick (function () {
  118. // this.handlePayWxQRcode()
  119. // this.qrcode(this.payUrl);
  120. // })
  121. },
  122. methods: {
  123. getHtmldata(){
  124. dictList({dictType:'recharge_agreement'}).then(response => {
  125. this.htmlData = response.data.data[0].remark;
  126. this.dialogVisible = true;
  127. })
  128. },
  129. // 清空二维码,避免生成多个二维码
  130. delQrcode() {
  131. this.$refs.expCodeRef.innerHTML = ""
  132. },
  133. qrcode(payUrl) { // 前端根据 payUrl 生成微信支付二维码
  134. this.delQrcode();
  135. return new QRCode('expCode', {
  136. width: 150,
  137. height: 150,
  138. text: payUrl,
  139. colorDark: '#000',
  140. colorLight: '#fff'
  141. });
  142. },
  143. handlePayWxQRcode() { // 获取微信支付二维码
  144. getWxPayCode({ // 这里根据不同的后端接口去修改
  145. integral: this.integralMoney*this.rate,
  146. totalFee: this.integralMoney*1,
  147. }).then(res => {
  148. let data = res.data.data;
  149. this.fullscreenLoading = false;
  150. this.qrcode(data.payUrl); // 例如:data.payUrl 的值为 "weixin://wxpay/bizpayurl?pr=......",根据这个值生成相对应的微信支付二维码
  151. this.timer = setInterval(() => { // 通过定时器每间隔一会去请求查询微信支付状态(具体参数根据项目需要而定)
  152. this.handleQueryWxPayStatus(data.orderNo);
  153. }, 1000);
  154. this.timerPayWxQRcode = setInterval(() => { // 刷新微信支付二维码
  155. console.log('刷新微信支付二维码');
  156. clearInterval(this.timer); // 清除定时器;
  157. clearInterval(this.timerPayWxQRcode);
  158. this.handlePayWxQRcode();
  159. }, 60000);
  160. }).catch(err => {
  161. this.fullscreenLoading = false;
  162. console.log(err)
  163. })
  164. },
  165. handleQueryWxPayStatus(orderNo) { // 查询微信支付状态
  166. queryWxPayStatus({ // 这里根据不同的后端接口去修改
  167. orderNo: orderNo,
  168. }).then(res => {
  169. let data = res.data.data;
  170. if (data == '支付成功') { // 当查询到支付成功时
  171. this.$store.dispatch('GetUserInfo');
  172. this.$message({
  173. type: 'success',
  174. message: '支付成功!'
  175. });
  176. clearInterval(this.timer); // 清除定时器;
  177. clearInterval(this.timerPayWxQRcode);
  178. }
  179. }).catch(err => {
  180. console.log(err)
  181. })
  182. },
  183. cancel() {
  184. this.visible = false;
  185. this.money = '';
  186. },
  187. confirm() {
  188. clearInterval(this.timer);
  189. clearInterval(this.timerPayWxQRcode);
  190. this.visible = false;
  191. this.integralMoney = this.money;
  192. this.fullscreenLoading = true;
  193. this.handlePayWxQRcode()
  194. },
  195. changePay(integralMoney, index) {
  196. clearInterval(this.timer);
  197. clearInterval(this.timerPayWxQRcode);
  198. this.money = '';
  199. this.selected = index;
  200. this.integralMoney = integralMoney;
  201. this.fullscreenLoading = true;
  202. this.handlePayWxQRcode()
  203. },
  204. getPayList() {
  205. payList().then(response => {
  206. this.rate = response.data.data.rate;
  207. this.payList = response.data.data.items;
  208. this.integralMoney = response.data.data.items[0].integralMoney;
  209. this.handlePayWxQRcode();
  210. })
  211. },
  212. },
  213. beforeDestroy() {
  214. clearInterval(this.timer);
  215. clearInterval(this.timerPayWxQRcode);
  216. }
  217. }
  218. </script>
  219. <style scoped>
  220. ::v-deep .el-dialog {
  221. left: 50%;
  222. top: 5%;
  223. transform: translate(-50%, -5%);
  224. margin: 0px !important;
  225. border-radius: 8px;
  226. }
  227. ::v-deep .el-dialog__title,::v-deep .el-dialog__headerbtn{
  228. font-size: 24px;
  229. }
  230. ::v-deep .el-dialog__header {
  231. -webkit-box-shadow: 0 1px 4px 0 rgba(31, 45, 61, .12);
  232. box-shadow: 0 1px 4px 0 rgba(31, 45, 61, .12);
  233. }
  234. ::v-deep .el-dialog__body{
  235. overflow: auto;
  236. overflow-x: hidden;
  237. max-height: 70vh!important;
  238. }
  239. ::v-deep .el-dialog__footer {
  240. border-top: 1px solid #d7d9dc;
  241. }
  242. .gray {
  243. filter: blur(4px);
  244. }
  245. .container {
  246. position: relative;
  247. margin: 0 auto;
  248. width: 100%;
  249. max-width: 960px;
  250. }
  251. .notification-view {
  252. margin-top: 1.767rem;
  253. }
  254. .chat-view {
  255. position: relative;
  256. width: 960px;
  257. }
  258. .chat-view .notification {
  259. width: 100%;
  260. margin-bottom: 1rem;
  261. /* height: 800px; */
  262. background-color: #fff;
  263. border-radius: 16px;
  264. }
  265. .payBox {
  266. padding: 20px 48px 40px;
  267. }
  268. .payBox-title {
  269. display: flex;
  270. align-items: center;
  271. margin-top: 20px;
  272. }
  273. .title {
  274. font-weight: 500;
  275. font-size: 24px;
  276. }
  277. .payBox-content {
  278. margin-top: 15px;
  279. margin-bottom: 26px;
  280. }
  281. .payBox-content-list {
  282. display: flex;
  283. flex-wrap: wrap;
  284. }
  285. /* .payBox-content-list .item:nth-child(4n+1) {
  286. margin-left: 0;
  287. } */
  288. .payBox-content-list .item {
  289. cursor: pointer;
  290. width: 200px;
  291. height: 120px;
  292. margin: 6px;
  293. border-radius: 6px;
  294. border: .5px solid #e7e7ec;
  295. position: relative;
  296. flex-direction: column;
  297. align-items: center;
  298. justify-content: center;
  299. background-color: #f7f7f9;
  300. display: flex;
  301. }
  302. .actived {
  303. color: #fe2c55;
  304. border: .5px solid rgba(254, 44, 85, .5) !important;
  305. background: linear-gradient(0deg, rgba(254, 44, 85, .06), rgba(254, 44, 85, .06)), #fff;
  306. }
  307. .itemUp {
  308. display: flex;
  309. font-size: 16px;
  310. align-items: baseline;
  311. font-weight: 500;
  312. }
  313. .itemDown {
  314. font-size: 12px;
  315. /* color: rgba(22, 24, 35, .75); */
  316. }
  317. .payBox-way {
  318. margin-top: 16px;
  319. }
  320. .way-item {
  321. display: flex;
  322. background-color: #f7f7f9;
  323. border-radius: 6px;
  324. padding: 12px;
  325. }
  326. .item-left {
  327. position: relative;
  328. width: 150px;
  329. height: 150px;
  330. background-color: #fff;
  331. border-radius: 6px;
  332. padding: 7px;
  333. }
  334. .item-left .grayText{
  335. width: 100px;
  336. position: absolute;
  337. left: 50%;
  338. top:50%;
  339. transform:translate(-50%,-50%);
  340. color: #fff;
  341. text-align: center;
  342. }
  343. .item-right {
  344. margin-left: 12px;
  345. }
  346. .up {
  347. display: flex;
  348. align-items: flex-end;
  349. font-size: 18px;
  350. font-weight: 600;
  351. height: 60px;
  352. }
  353. .center {
  354. display: flex;
  355. align-items: center;
  356. margin-top: 6px;
  357. }
  358. .textStyle {
  359. font-size: 16px;
  360. font-weight: 400;
  361. margin-left: 4px;
  362. color: rgba(22, 24, 35, .34);
  363. }
  364. .down {
  365. font-size: 16px;
  366. color: rgba(22, 24, 35, .34);
  367. margin-top: 16px;
  368. display: flex;
  369. -moz-box-align: center;
  370. -ms-flex-align: center;
  371. align-items: center;
  372. }
  373. </style>