Commit 39a7c8fa by wangshuo

跨域

parent d493c440
import React, {Component} from 'react' import React, { Component } from 'react'
import './index.scss' import './index.scss'
import {getParam} from "@/utils" import { getParam } from "@/utils"
import {connect} from "react-redux" import { connect } from "react-redux"
import {Link} from "react-router-dom" import { Link } from "react-router-dom"
import {Flex} from 'antd-mobile' import { Flex } from 'antd-mobile'
class Group extends Component { class Group extends Component {
...@@ -36,9 +36,9 @@ class Group extends Component { ...@@ -36,9 +36,9 @@ class Group extends Component {
toPay = (pdd_order_id) => { toPay = (pdd_order_id) => {
const courseInfo = this.props.courseInfo.courseInfo.course_info; const courseInfo = this.props.courseInfo.courseInfo.course_info;
if(courseInfo.group_status === 3) { if (courseInfo.group_status === 3) {
this.props.history.push(`/order?id=${getParam('id')}&&groupon_code=${pdd_order_id}`); this.props.history.push(`/order?id=${getParam('id')}&&groupon_code=${pdd_order_id}`);
}else{ } else {
this.setState({ this.setState({
isShowMore: false, isShowMore: false,
alreadyIn: true alreadyIn: true
...@@ -51,8 +51,8 @@ class Group extends Component { ...@@ -51,8 +51,8 @@ class Group extends Component {
isShowMore: false, isShowMore: false,
alreadyIn: false, alreadyIn: false,
}); });
const {pdd_price, number, data} = this.state; const { pdd_price, number, data } = this.state;
if(browser.isWeixin) { if (browser.isWeixin) {
let share = this.state.share; let share = this.state.share;
this.setState({ this.setState({
share: !share, share: !share,
...@@ -64,7 +64,7 @@ class Group extends Component { ...@@ -64,7 +64,7 @@ class Group extends Component {
imgUrl: data.image_name, // 分享图标 imgUrl: data.image_name, // 分享图标
}; };
http.post(`${api['pay-api']}/m/sale/signature`).then(res => { http.post(`${api['pay-api']}/m/sale/signature`).then(res => {
const {nonce_str, signature, timestamp} = res.data; const { nonce_str, signature, timestamp } = res.data;
wx.config({ wx.config({
"debug": false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 "debug": false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
"appId": 'wx23dac6775ac82877', // 必填,公众号的唯一标识 "appId": 'wx23dac6775ac82877', // 必填,公众号的唯一标识
...@@ -84,7 +84,7 @@ class Group extends Component { ...@@ -84,7 +84,7 @@ class Group extends Component {
wx.ready(function () { //需在用户可能点击分享按钮前就先调用 wx.ready(function () { //需在用户可能点击分享按钮前就先调用
wx.hideAllNonBaseMenuItem(); wx.hideAllNonBaseMenuItem();
wx.showMenuItems({ wx.showMenuItems({
menuList: ['menuItem:share:appMessage' , 'menuItem:share:timeline'] // 要显示的菜单项,所有menu项见附录3 menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline'] // 要显示的菜单项,所有menu项见附录3
}); });
wx.updateAppMessageShareData({ wx.updateAppMessageShareData({
...shareData, ...shareData,
...@@ -99,7 +99,7 @@ class Group extends Component { ...@@ -99,7 +99,7 @@ class Group extends Component {
} }
}) })
}); });
}else{ } else {
Toast.info('请在微信中使用分享功能!', 2); Toast.info('请在微信中使用分享功能!', 2);
} }
} }
...@@ -113,9 +113,9 @@ class Group extends Component { ...@@ -113,9 +113,9 @@ class Group extends Component {
componentDidMount() { componentDidMount() {
if (this.props.courseInfo && this.props.courseInfo.courseInfo && this.props.courseInfo.courseInfo.course_info && this.props.courseInfo.courseInfo.course_info.pdd_group_info) { if (this.props.courseInfo && this.props.courseInfo.courseInfo && this.props.courseInfo.courseInfo.course_info && this.props.courseInfo.courseInfo.course_info.pdd_group_info) {
let now_groupon_list = this.props.courseInfo.courseInfo.course_info.pdd_group_info.now_groupon_list; let now_groupon_list = this.props.courseInfo.courseInfo.course_info.pdd_group_info.now_groupon_list;
if(now_groupon_list && now_groupon_list.length > 0) { if (now_groupon_list && now_groupon_list.length > 0) {
setInterval(() => { setInterval(() => {
now_groupon_list.map(item=>{ now_groupon_list.map(item => {
item.end_time -= 1; item.end_time -= 1;
return item; return item;
}); });
...@@ -138,26 +138,26 @@ class Group extends Component { ...@@ -138,26 +138,26 @@ class Group extends Component {
hours = 0, hours = 0,
minutes = 0, minutes = 0,
seconds = 0; seconds = 0;
date -= 1000 date -= 1000;
hours = `${parseInt(date / (60 * 60 * 1000))}`.padStart(2, 0); hours = `${parseInt(date / (60 * 60 * 1000))}`.padStart(2, 0);
minutes = `${parseInt((date - hours * 3600000) / 60000)}`.padStart(2, 0); minutes = `${parseInt((date - hours * 3600000) / 60000)}`.padStart(2, 0);
seconds = `${parseInt((date - hours * 3600000 - minutes * 60000 ) / 1000)}`.padStart(2, 0); seconds = `${parseInt((date - hours * 3600000 - minutes * 60000) / 1000)}`.padStart(2, 0);
return `${hours}:${minutes}:${seconds}`; return `${hours}:${minutes}:${seconds}`;
} }
render() { render() {
const {alreadyIn, countdown, now_groupon_list} = this.state; const { alreadyIn, countdown, now_groupon_list } = this.state;
let groupInfo = '',groupon_member = '', group_status = -1, groupSuccessMbc = null; let groupInfo = '', groupon_member = '', group_status = -1, groupSuccessMbc = null;
if (this.props.courseInfo && this.props.courseInfo.courseInfo && this.props.courseInfo.courseInfo.course_info) { if (this.props.courseInfo && this.props.courseInfo.courseInfo && this.props.courseInfo.courseInfo.course_info) {
groupInfo = this.props.courseInfo.courseInfo.course_info.pdd_group_info; groupInfo = this.props.courseInfo.courseInfo.course_info.pdd_group_info;
groupon_member = groupInfo.groupon_member; groupon_member = groupInfo.groupon_member;
group_status = this.props.courseInfo.courseInfo.course_info.group_status; group_status = this.props.courseInfo.courseInfo.course_info.group_status;
} }
if(group_status === 4) { if (group_status === 4) {
if(groupon_member.member) { if (groupon_member.member) {
const {number} = groupon_member; const { number } = groupon_member;
let ary=[],num = number; let ary = [], num = number;
while(num != 0) { while (num != 0) {
ary.push(num); ary.push(num);
num--; num--;
} }
...@@ -216,7 +216,7 @@ class Group extends Component { ...@@ -216,7 +216,7 @@ class Group extends Component {
groupInfo.now_groupon_list && groupInfo.now_groupon_list.length > 0 && groupInfo.now_groupon_list.map((item, index) => { groupInfo.now_groupon_list && groupInfo.now_groupon_list.length > 0 && groupInfo.now_groupon_list.map((item, index) => {
return ( return (
<li key={index} className='group-item'> <li key={index} className='group-item'>
<img className='avatar' src={item.avatar} alt=""/> <img className='avatar' src={item.avatar} alt="" />
<div className='user-name text-overflow-one'> <div className='user-name text-overflow-one'>
{item.user_name} {item.user_name}
</div> </div>
...@@ -224,7 +224,7 @@ class Group extends Component { ...@@ -224,7 +224,7 @@ class Group extends Component {
<p>还差<span className='red'>{item.number}</span>拼成</p> <p>还差<span className='red'>{item.number}</span>拼成</p>
<p>剩余 {this.formatTimeByMillisecond(item.end_time)}</p> <p>剩余 {this.formatTimeByMillisecond(item.end_time)}</p>
</div> </div>
<span onClick={()=>{this.toPay(item.pdd_order_id)}} className='topay'>去参团</span> <span onClick={() => { this.toPay(item.pdd_order_id) }} className='topay'>去参团</span>
</li> </li>
) )
}) })
...@@ -258,13 +258,13 @@ class Group extends Component { ...@@ -258,13 +258,13 @@ class Group extends Component {
groupInfo.now_groupon_list && groupInfo.now_groupon_list.length > 0 && groupInfo.now_groupon_list.map((item, index) => { groupInfo.now_groupon_list && groupInfo.now_groupon_list.length > 0 && groupInfo.now_groupon_list.map((item, index) => {
return ( return (
<li key={index} className='group-item'> <li key={index} className='group-item'>
<img className='avatar' src={item.avatar} alt=""/> <img className='avatar' src={item.avatar} alt="" />
<div className='user-name'> <div className='user-name'>
<p className='name text-overflow-one'>{item.user_name}</p> <p className='name text-overflow-one'>{item.user_name}</p>
<p className='time'>剩余 {this.formatTimeByMillisecond(item.end_time)}</p> <p className='time'>剩余 {this.formatTimeByMillisecond(item.end_time)}</p>
</div> </div>
<p className='group-status'>还差{item.number}</p> <p className='group-status'>还差{item.number}</p>
<span onClick={()=>{this.toPay(item.pdd_order_id)}} className='topay'>去参团</span> <span onClick={() => { this.toPay(item.pdd_order_id) }} className='topay'>去参团</span>
</li> </li>
) )
}) })
...@@ -285,6 +285,6 @@ class Group extends Component { ...@@ -285,6 +285,6 @@ class Group extends Component {
} }
export default connect( export default connect(
state => ({courseInfo: state}), state => ({ courseInfo: state }),
null null
)(Group) )(Group)
...@@ -82,7 +82,14 @@ class ToGroup extends Component { ...@@ -82,7 +82,14 @@ class ToGroup extends Component {
console.log(resultList); console.log(resultList);
let res = resultList[0], let res = resultList[0],
userInfo = resultList[1]; userInfo = resultList[1];
if(res.data.errno !== 0) {
Toast.info(res.data.msg, 2);
return;
}
if(userInfo.data.code !== 200) {
Toast.info(res.data.msg, 2);
return;
}
this.setState({ this.setState({
data: res.data.data.course_info, data: res.data.data.course_info,
pdd_price: res.data.data.pdd_price, pdd_price: res.data.data.pdd_price,
......
import axios from "axios"; import axios from "axios";
import qs from 'qs' import qs from 'qs'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
const instance = axios.create({ const instance = axios.create({
transformRequest: [ transformRequest: [
(data) => qs.stringify(data) (data) => qs.stringify(data)
], ],
headers: { headers: {
HTTP_PLAT_FORM: 5, HTTP_PLAT_FORM: 5,
HTTP_PLAT: 5 HTTP_PLAT: 5,
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment