|
|
@@ -1,45 +1,27 @@
|
|
|
import React, {Component} from 'react';
|
|
|
-import {Input, Spin, Button, Icon} from 'antd';
|
|
|
+import {Input, Spin, Button, Icon, Modal} from 'antd';
|
|
|
import './index.css';
|
|
|
-import {idGen} from "../../../func";
|
|
|
-import {SHOW_WXCONTENT} from "../../../gql";
|
|
|
+import {UPDATE_WXCONFIG, SHOW_WXCONTENT, DELETE_WXCONFIG, SHOW_WXCONFIG} from "../../../gql";
|
|
|
import gql from "graphql-tag";
|
|
|
import {Mutation, Query} from "react-apollo";
|
|
|
+import {getCookie} from "../../../cookie";
|
|
|
|
|
|
-class WxConfig extends Component {
|
|
|
+const confirm = Modal.confirm;
|
|
|
|
|
|
+class WxConfig extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
- configs: ['AppName', 'AppID', 'AppSecret', 'URL', 'Token', 'welcome_words', 'pay_api_key', 'attach', 'mch_id', 'body', 'spbill_create_ip', 'notify_url'],
|
|
|
- mch_id: '',
|
|
|
- notify_url: '',
|
|
|
- appSecret: '',
|
|
|
- appID: '',
|
|
|
- token: '',
|
|
|
- spbill_create_ip: '',
|
|
|
- enter_url: '',
|
|
|
- pay_api_key: '',
|
|
|
- body: '',
|
|
|
- welcome_words: '',
|
|
|
- attach: '',
|
|
|
- configID: props.location.state === undefined ? props.configID : props.location.state.configID,
|
|
|
- appName: props.location.state === undefined ? props.appName : props.location.state.appName,
|
|
|
+ configs: ['appName', 'appID', 'appSecret', 'enter_url', 'token', 'welcome_words', 'pay_api_key', 'attach', 'mch_id', 'body', 'spbill_create_ip', 'notify_url'],
|
|
|
+ configID: props.location.state === undefined ? props.defaultConfigID : props.location.state.configID,
|
|
|
+ appName: props.location.state === undefined ? props.defaultAppName : props.location.state.appName,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- switchConfig = (label) => {
|
|
|
- return (e) => {
|
|
|
- this.setState({
|
|
|
- [label]: e.target.value
|
|
|
- })
|
|
|
- };
|
|
|
- };
|
|
|
-
|
|
|
componentWillReceiveProps(next) {
|
|
|
this.setState({
|
|
|
- configID: next.configID,
|
|
|
- appName: next.appName,
|
|
|
+ configID: next.location.state === undefined ? next.defaultConfigID : next.location.state.configID,
|
|
|
+ appName: next.location.state === undefined ? next.defaultAppName : next.location.state.appName,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -54,26 +36,191 @@ class WxConfig extends Component {
|
|
|
if (error) {
|
|
|
return 'error!';
|
|
|
}
|
|
|
- console.log(data);
|
|
|
+ let {history, location, defaultConfigID, defaultAppName, trialcase} = this.props;
|
|
|
+ let {appName, configID, configs} = this.state;
|
|
|
return (
|
|
|
<div>
|
|
|
- {
|
|
|
- this.state.configs.map(config => (
|
|
|
- <div key={config} style={{marginBottom: 10}}>
|
|
|
- <span className='vice-title'>{config}: </span>
|
|
|
- <Input value={this.state[config]} style={{width: 200}} onChange={this.switchConfig(config)}/>
|
|
|
- </div>
|
|
|
- ))
|
|
|
- }
|
|
|
- <Button type={'primary'}>save</Button>
|
|
|
+ <Display
|
|
|
+ configs={configs}
|
|
|
+ configID={configID}
|
|
|
+ appName={appName}
|
|
|
+ location={location}
|
|
|
+ history={history}
|
|
|
+ defaultConfigID={defaultConfigID}
|
|
|
+ defaultAppName={defaultAppName}
|
|
|
+ trialcase={trialcase}
|
|
|
+ data={data.wxConfig_by_id}
|
|
|
+ />
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
</Query>
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default WxConfig;
|
|
|
+
|
|
|
+class Display extends Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.state = {
|
|
|
+ configID: props.configID,
|
|
|
+ appName: props.appName,
|
|
|
+ mch_id: props.data === null? '' : props.data.mch_id,
|
|
|
+ notify_url: props.data === null? '' : props.data.notify_url,
|
|
|
+ appSecret: props.data === null? '' : props.data.appSecret,
|
|
|
+ appID: props.data === null? '' : props.data.appID,
|
|
|
+ token: props.data === null? '' : props.data.token,
|
|
|
+ spbill_create_ip: props.data === null? '' : props.data.spbill_create_ip,
|
|
|
+ enter_url: props.data === null? '' : props.data.enter_url,
|
|
|
+ pay_api_key: props.data === null? '' : props.data.pay_api_key,
|
|
|
+ body: props.data === null? '' : props.data.body,
|
|
|
+ welcome_words: props.data === null? '' : props.data.welcome_words,
|
|
|
+ attach: props.data === null? '' : props.data.attach,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ switchConfig = (label) => {
|
|
|
+ return (e) => {
|
|
|
+ this.setState({
|
|
|
+ [label]: e.target.value
|
|
|
+ })
|
|
|
+ };
|
|
|
+ };
|
|
|
|
|
|
+ render() {
|
|
|
+ let {configs} = this.props;
|
|
|
+ let {configID, appName, mch_id, notify_url, appSecret, appID, token, spbill_create_ip, enter_url, pay_api_key, body, welcome_words, attach} = this.state;
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ {
|
|
|
+ configs.map(config => (
|
|
|
+ <div key={config} style={{marginBottom: 10}}>
|
|
|
+ <span className='vice-title'>{config}: </span>
|
|
|
+ <Input value={this.state[config]} style={{width: 200}} onChange={this.switchConfig(config)}/>
|
|
|
+ </div>
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ {
|
|
|
+ this.props.trialcase?
|
|
|
+ <Button type={'primary'}> need copy</Button>
|
|
|
+ :
|
|
|
+ <div>
|
|
|
+ <UpdateWXConfigButton
|
|
|
+ id={configID}
|
|
|
+ appName={appName}
|
|
|
+ mch_id={mch_id}
|
|
|
+ notify_url={notify_url}
|
|
|
+ appSecret={appSecret}
|
|
|
+ appID={appID}
|
|
|
+ token={token}
|
|
|
+ spbill_create_ip={spbill_create_ip}
|
|
|
+ enter_url={enter_url}
|
|
|
+ pay_api_key={pay_api_key}
|
|
|
+ body={body}
|
|
|
+ welcome_words={welcome_words}
|
|
|
+ attach={attach}
|
|
|
+ />
|
|
|
+ <DeleteWXConfigButton
|
|
|
+ id={configID}
|
|
|
+ history={this.props.history}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ }
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class UpdateWXConfigButton extends Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.state = {}
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ return (
|
|
|
+ <Mutation mutation={gql(UPDATE_WXCONFIG)}>
|
|
|
+ {(update_wxConfig, {loading, error}) => {
|
|
|
+ if (loading)
|
|
|
+ return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
|
|
|
+ if (error)
|
|
|
+ return 'error';
|
|
|
+ let {id, appName, mch_id, notify_url, appSecret, appID, token, spbill_create_ip, enter_url, pay_api_key, body, welcome_words, attach} = this.props;
|
|
|
+ return (
|
|
|
+ <Button type={'primary'} onClick={()=>{
|
|
|
+ update_wxConfig({
|
|
|
+ variables: {
|
|
|
+ id,
|
|
|
+ appName,
|
|
|
+ mch_id,
|
|
|
+ notify_url,
|
|
|
+ appSecret,
|
|
|
+ appID,
|
|
|
+ token,
|
|
|
+ spbill_create_ip,
|
|
|
+ enter_url,
|
|
|
+ pay_api_key,
|
|
|
+ body,
|
|
|
+ welcome_words,
|
|
|
+ attach,
|
|
|
+ updateAt: new Date().getTime()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}>save</Button>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </Mutation>
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export default WxConfig;
|
|
|
+class DeleteWXConfigButton extends Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.state = {
|
|
|
+ userID: getCookie('user_id')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ showConfirm = (delete_wxConfig, id) => {
|
|
|
+ let _this = this;
|
|
|
+ confirm({
|
|
|
+ title: 'Do you want to delete this config?',
|
|
|
+ content: 'It cannot be found back!',
|
|
|
+ onOk() {
|
|
|
+ delete_wxConfig({variables: {id}});
|
|
|
+ _this.props.history.push({
|
|
|
+ pathname: `/wechat-service/trial-case/index`,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onCancel() {
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ render() {
|
|
|
+ return (
|
|
|
+ <Mutation
|
|
|
+ mutation={gql(DELETE_WXCONFIG)}
|
|
|
+ refetchQueries={[{query: gql(SHOW_WXCONFIG), variables: {user_id: this.state.userID}}]}
|
|
|
+ >
|
|
|
+ {(delete_wxConfig, {loading, error}) => {
|
|
|
+ if (loading)
|
|
|
+ return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
|
|
|
+ if (error)
|
|
|
+ return 'error';
|
|
|
+ let {id} = this.props;
|
|
|
+ return (
|
|
|
+ <Button type={'danger'} onClick={()=>{
|
|
|
+ this.showConfirm(delete_wxConfig, id);
|
|
|
+ }}>delete</Button>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </Mutation>
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|