From 118fb63b559095310b0977bef73977c827a040c9 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Mon, 17 Feb 2020 12:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/component/VAS/BuyQuota.js | 328 ++++++++++++++++++---------------- yarn.lock | 12 ++ 3 files changed, 191 insertions(+), 150 deletions(-) diff --git a/package.json b/package.json index 403b83e..1be1693 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "for-editor": "^0.3.5", "http-proxy-middleware": "^0.20.0", "mdi-material-ui": "^6.9.0", + "qrcode-react": "^0.1.16", "react": "^16.12.0", "react-addons-update": "^15.6.2", "react-content-loader": "^4.3.2", diff --git a/src/component/VAS/BuyQuota.js b/src/component/VAS/BuyQuota.js index b84c1e3..a5106b7 100644 --- a/src/component/VAS/BuyQuota.js +++ b/src/component/VAS/BuyQuota.js @@ -9,6 +9,7 @@ import SupervisedUserCircle from "@material-ui/icons/SupervisedUserCircle"; import StarIcon from "@material-ui/icons/StarBorder"; import LocalPlay from "@material-ui/icons/LocalPlay"; import API from "../../middleware/Api"; +import QRCode from "qrcode-react"; import { withStyles, @@ -34,12 +35,8 @@ import RadioGroup from "@material-ui/core/RadioGroup"; import FormLabel from "@material-ui/core/FormLabel"; import FormControlLabel from "@material-ui/core/FormControlLabel"; import Radio from "@material-ui/core/Radio"; -import Divider from "@material-ui/core/Divider"; -import InputLabel from "@material-ui/core/InputLabel"; -import FormControl from "@material-ui/core/FormControl"; -import MenuItem from "@material-ui/core/MenuItem"; -import Select from "@material-ui/core/Select"; -import {AccountBalanceWallet} from "@material-ui/icons"; +import { AccountBalanceWallet } from "@material-ui/icons"; +import pathHelper from "../../untils/page"; const styles = theme => ({ layout: { @@ -141,15 +138,15 @@ class BuyQuotaCompoment extends Component { selectedPack: -1, selectedGroup: -1, times: 1, - scoreNum:1, + scoreNum: 1, loading: false, redeemCode: "", dialog: null, payment: { type: "", - img: "", + img: "" }, - scorePrice:0, + scorePrice: 0, redeemInfo: null, packs: [], groups: [], @@ -167,7 +164,7 @@ class BuyQuotaCompoment extends Component { groups: response.data.groups, alipay: response.data.alipay, payjs: response.data.payjs, - scorePrice:response.data.score_price, + scorePrice: response.data.score_price }); }) .catch(error => { @@ -187,15 +184,12 @@ class BuyQuotaCompoment extends Component { this.setState({ loading: true }); - API - .post("/vas/redeem/" + this.state.redeemCode,) + API.post("/vas/redeem/" + this.state.redeemCode) .then(response => { - - this.setState({ - loading: false, - dialog: "success" - }); - + this.setState({ + loading: false, + dialog: "success" + }); }) .catch(error => { this.setState({ @@ -223,8 +217,7 @@ class BuyQuotaCompoment extends Component { this.setState({ loading: true }); - API - .get("/vas/redeem/" + this.state.redeemCode,) + API.get("/vas/redeem/" + this.state.redeemCode) .then(response => { this.setState({ loading: false, @@ -261,11 +254,16 @@ class BuyQuotaCompoment extends Component { API.post("/vas/order", { action: packType, method: this.state.packPayMethod, - id:packType === "score" ? 1 :(packType === "pack" - ? this.state.packs[this.state.selectedPack].id - : this.state.groups[this.state.selectedGroup].id) - , - num: packType === "score" ?parseInt(this.state.scoreNum) :parseInt(this.state.times) + id: + packType === "score" + ? 1 + : packType === "pack" + ? this.state.packs[this.state.selectedPack].id + : this.state.groups[this.state.selectedGroup].id, + num: + packType === "score" + ? parseInt(this.state.scoreNum) + : parseInt(this.state.times) }) .then(response => { if (!response.data.payment) { @@ -275,6 +273,26 @@ class BuyQuotaCompoment extends Component { }); return; } + if (response.data.qr_code) { + if (pathHelper.isMobile()) { + window.open(response.data.qr_code); + this.setState({ loading: false }); + } else { + this.setState({ + loading: false, + dialog: "qr", + payment: { + type: this.state.packPayMethod, + img: response.data.qr_code + } + }); + } + + this.IntervalId = window.setInterval(() => { + this.querryLoop(response.data.id); + }, 3000); + } + // if (response.data.error === 1) { // this.setState({ // loading: false @@ -325,11 +343,10 @@ class BuyQuotaCompoment extends Component { }; querryLoop = id => { - axios - .get("/Buy/querryStatus?id=" + id) + API + .get("/vas/order/" + id) .then(response => { - var data = eval("(" + response.data + ")"); - if (data.status === 1) { + if (response.data === 1) { this.setState({ dialog: "success" }); @@ -353,7 +370,7 @@ class BuyQuotaCompoment extends Component { this.state.packPayMethod === "score" ? null : this.state.packPayMethod - }); + }); this.setState({ value }); }; @@ -401,101 +418,99 @@ class BuyQuotaCompoment extends Component { render() { const { classes } = this.props; - const methodSelect = (
- 选择支付方式: - - {!this.state.alipay && - !this.state.payjs && - (this.state.value === 0 && (this.state.selectedPack === -1 || - this.state.packs[ - this.state.selectedPack - ].score === 0)) && - (this.state.value === 1 && (this.state.selectedGroup === -1 || - this.state.groups[ - this.state.selectedGroup - ].score === 0)) - && ( - - 无可用支付方式 - - )} - {this.state.alipay && ( - } - label={"支付宝扫码"} - /> - )} - {this.state.payjs && ( - } - label={"微信扫码"} - /> - )} - {this.state.value === 0 && this.state.selectedPack !== -1 && - this.state.packs[ - this.state.selectedPack - ].score !== 0 && ( - } - label={"积分支付"} - /> - )} - {this.state.value === 1 && this.state.selectedGroup !== -1 && - this.state.groups[ - this.state.selectedGroup - ].score !== 0 && ( - } - label={"积分支付"} - /> - )} - + const methodSelect = (
- {this.state.value !== 2 &&购买时长倍数:} - {this.state.value === 2 &&充值积分数量:} -
- {this.state.value !== 2 && - 选择支付方式: + + {!this.state.alipay && + !this.state.payjs && + this.state.value === 0 && + (this.state.selectedPack === -1 || + this.state.packs[this.state.selectedPack].score === + 0) && + this.state.value === 1 && + (this.state.selectedGroup === -1 || + this.state.groups[this.state.selectedGroup] + .score === 0) && ( + 无可用支付方式 + )} + {this.state.alipay && ( + } + label={"支付宝扫码"} + /> )} - /> - } - {this.state.value === 2 && - } + label={"微信扫码"} + /> + )} + {this.state.value === 0 && + this.state.selectedPack !== -1 && + this.state.packs[this.state.selectedPack].score !== + 0 && ( + } + label={"积分支付"} + /> + )} + {this.state.value === 1 && + this.state.selectedGroup !== -1 && + this.state.groups[this.state.selectedGroup].score !== + 0 && ( + } + label={"积分支付"} + /> + )} + +
+ {this.state.value !== 2 && ( + 购买时长倍数: + )} + {this.state.value === 2 && ( + 充值积分数量: + )} +
+ {this.state.value !== 2 && ( + )} - /> - } - -
); + {this.state.value === 2 && ( + + )} + + ); return (
@@ -514,7 +529,12 @@ class BuyQuotaCompoment extends Component { > } /> } /> - {this.state.scorePrice >0 && } />} + {this.state.scorePrice > 0 && ( + } + /> + )} } /> @@ -707,17 +727,16 @@ class BuyQuotaCompoment extends Component {
当前费用: {this.state.packPayMethod !== - "score" && ( + "score" && ( ¥ - - - {( - this.state.scorePrice / 100 * - this.state.scoreNum - ).toFixed(2)} - - + + {( + (this.state.scorePrice / + 100) * + this.state.scoreNum + ).toFixed(2)} + )}
@@ -730,9 +749,11 @@ class BuyQuotaCompoment extends Component { disabled={ this.state.loading || this.state.packPayMethod === - null + null + } + onClick={() => + this.buyPack("score") } - onClick={() => this.buyPack("score")} > 立即购买 @@ -785,16 +806,13 @@ class BuyQuotaCompoment extends Component { {this.state.payment.type === "alipay" && ( 支付宝 )} - {this.state.payment.type === "youzan" && ( - 支付宝或微信 + {this.state.payment.type === "payjs" && ( + 微信 )} 扫描下方二维码完成付款,付款完成后本页面会自动刷新。
- + ,
@@ -840,15 +858,23 @@ class BuyQuotaCompoment extends Component { {this.state.redeemInfo.name} - {this.state.redeemInfo.type === 2?"数量:":"时长:"} + {this.state.redeemInfo.type === 2 + ? "数量:" + : "时长:"} - {this.state.redeemInfo.type === 2 && <>{this.state.redeemInfo.num}} - {this.state.redeemInfo.type !== 2 && <>{Math.ceil( - this.state.redeemInfo.time / 86400 - ) * this.state.redeemInfo.num} - 天} - + {this.state.redeemInfo.type === 2 && ( + <>{this.state.redeemInfo.num} + )} + {this.state.redeemInfo.type !== 2 && ( + <> + {Math.ceil( + this.state.redeemInfo.time / + 86400 + ) * this.state.redeemInfo.num} + 天 + + )} )} @@ -881,7 +907,7 @@ class BuyQuotaCompoment extends Component { this.state.groups[this.state.selectedGroup] .name} - {methodSelect} + {methodSelect}
当前费用: {this.state.packPayMethod !== "score" && ( @@ -932,8 +958,10 @@ class BuyQuotaCompoment extends Component { 取消