/** * 确认订单并支付 */ import React, { Component } from "react"; import { Form, Tooltip, Button, Modal, message, Checkbox, Alert, Table, Input, } from "antd"; import { withRouter } from "dva/router"; import "../../meeting.less"; import { checkProductCoupon, saveOrder, getPayPhone, sendPayVerifycode, checkOrder, } from "../../../../services/api"; import { formatCurrency } from "../../../../utils/utils"; import { toUpper } from "lodash"; const formItemLayout = { labelCol: { xs: { span: 12 }, sm: { span: 5 }, }, wrapperCol: { xs: { span: 12 }, sm: { span: 13 }, }, }; @Form.create() @withRouter export default class ConfirmOrder extends Component { constructor(props, context) { super(props, context); this.state = { mobilePhone: null, //企业钱包的手机号码 mergeList: props.mergeList, //合并所有信息 totalAmount: props.totalAmount, //总价 actualTotalAmount: props.totalAmount, //应付 discountWay: "", //优惠类型 discountValue: "", //优惠金额 couponsChecked: false, //是否选择了优惠卷 couponsUsered: false, //勾选了优惠卷是否确认使用 coupons: "", //输入的优惠卷码 sureCoupons: "", //最终确认使用的优惠卷码 canPay: true, //应付金额是否大于总金额 checkbox: false, //是否点击了同意按钮 paymentStatus: false, //支付模态框状态 verificationName: "获取验证码", //验证码按钮名称 timer: null, // 验证码定时器 time: 0, // 可发送验证码剩余时间 // activeCode: null //输入的验证码值 showReceivingAddress: false, //是否显示收货地址输入框(只有有硬件数据的时候,需要这个字段,osp需要存) deliveryAddress: null, //地址 }; } componentDidMount() { // this._getPayPhone(); this.changeReceivingAddress(this.props.mergeList); } componentWillReceiveProps(nextProps) { //每次修改列表把所有和优惠卷相关的都重置 this.setState({ mergeList: nextProps.mergeList, totalAmount: nextProps.totalAmount, actualTotalAmount: nextProps.totalAmount, }); if (this.state.couponsChecked) { if (this.state.discountWay && this.state.discountValue) { let actualTotalAmount = nextProps.totalAmount switch (this.state.discountWay) { case "1": actualTotalAmount = actualTotalAmount - this.state.discountValue; if (actualTotalAmount <= 0) { console.log(actualTotalAmount) actualTotalAmount = 0 } break; case "2": actualTotalAmount = this.state.discountValue; break; case "3": actualTotalAmount = actualTotalAmount * this.state.discountValue; break; } this.setState({ actualTotalAmount }) if (actualTotalAmount > nextProps.totalAmount) { message.error("当前应付金额大于总金额,请更换优惠卷") this.setState({ canPay: false }) } } } //每次修改列表如果有硬件订单把所有和优惠卷相关的都重置 let hasHardware = nextProps.mergeList.some(item=>item.productServiceType==="2" || item.productServiceType==="3") if(hasHardware){ this.setState({ actualTotalAmount: nextProps.totalAmount, discountWay: "", discountValue: "", couponsChecked: false, couponsUsered: "", coupons: "", sureCoupons: "" }); } this.changeReceivingAddress(nextProps.mergeList); } //改变是否显示收货地址字段 changeReceivingAddress(mergeList) { const showReceivingAddress = JSON.stringify(mergeList).indexOf('"productServiceType":"2"') > -1; this.setState({ showReceivingAddress, }); } //根据优惠卷获取应付金额 setActualTotalAmount = () => { let { coupons, actualTotalAmount, totalAmount } = this.state; checkProductCoupon({ productCouponId: coupons, productCategoryType: 11 }) .then(res => { switch (res.data.discountWay) { case "1": actualTotalAmount = totalAmount - res.data.discountValue; if (actualTotalAmount <= 0) { actualTotalAmount = 0 } break; case "2": actualTotalAmount = res.data.discountValue; break; case "3": actualTotalAmount = totalAmount * res.data.discountValue; break; } this.setState({ actualTotalAmount, canPay: true, discountWay: res.data.discountWay, discountValue: res.data.discountValue, couponsUsered: false, sureCoupons: coupons, }) if (actualTotalAmount > totalAmount) { message.error("当前应付金额大于总金额,请更换优惠卷") this.setState({ canPay: false }) } }) .catch(err => { this.setState({ actualTotalAmount: this.state.totalAmount, //应付 discountWay: "", //优惠类型 discountValue: "", }) }) } /** * 先支付校验 * 再获取支付手机号码 * 再获取验证码 * 再提交订单 */ //支付校验 _checkOrder() { // this.props.form.validateFields((err, values) => { // if (!err) { checkOrder({ actualPayAmount: this.state.actualTotalAmount, }).then((res) => { if (res.retType === "0") { // this._saveOrder(); this._getPayPhone(); } }); // } // }); } //获取企业钱包账户资料 _getPayPhone() { getPayPhone({}).then((res) => { if (res.retType === "0") { this.setState({ mobilePhone: res.data, paymentStatus: !this.state.paymentStatus, }); } }); // .catch(err => { // if (err.retType === "-1") { // message.warning( // "您的企业尚未开通企业钱包,请访问【金融保险】-【金融钱包】-【企业钱包】免费在线开通。" // ); // } // }); } //确认提交订单 _saveOrder() { this.props.form.validateFields((err, values) => { console.log(this.state.actualTotalAmount) if (!err) { const data = { activeCode: values.activeCode, orderDetailListStr: JSON.stringify(this.state.mergeList), amount: this.state.totalAmount, actualPayAmount: this.state.actualTotalAmount, productCouponId: this.state.discountWay?this.state.sureCoupons:"", productCategoryType: 11, }; console.log(this.state.deliveryAddress) if (this.state.showReceivingAddress) { data.deliveryAddress = this.state.deliveryAddress } console.log(data) saveOrder({ ...data, }).then((res) => { // console.log(res); if (res.retType === "0") { this.setState({ paymentStatus: !this.state.paymentStatus, }); const _this = this; Modal.success({ title: "支付成功!", content: (
云会议资源购买订单支付后,系统将进行资源分配,预计1~2个工作日完成。
), okText: "查看订单", onOk() { // _this.props.history.push("/meeting/resource"); // _this.props.history.push({ pathname: "/meeting/buy-setMeal", state: '3' }); _this.props.changeKeyTab("3"); }, }); } }); } }); } render() { const { getFieldDecorator } = this.props.form; const { mergeList, totalAmount, mobilePhone, actualTotalAmount, coupons, couponsChecked } = this.state; const columns = [ { title: "分类", dataIndex: "name", key: "name", }, { title: "产品", dataIndex: "productName", key: "productName", }, { title: "单价", dataIndex: "eachAmount", key: "eachAmount", render: (text, record) => { return ( {formatCurrency(text)} {record.unit} ); }, }, { title: "时长", dataIndex: "duration", key: "duration", render: (text, record) => { return ( {record.productBuyMode === "1" ? text + "月" : record.productBuyMode === "2" ? text + "年" : "---"} ); }, }, { title: "数量", dataIndex: "num", key: "num", }, { title: "小计(元)", dataIndex: "amount", key: "amount", render: (text, recoed) => { return {formatCurrency(text)}; }, }, ]; //如果订单包含productServiceType为2或3则不能使用优惠卷 let hasHardware = mergeList.some(item=>item.productServiceType==="2" || item.productServiceType==="3") return ( //