Ipay.vue 11 KB

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