前端:商品添加。提交部分,让小范帮忙看看~

This commit is contained in:
YunaiV 2019-03-18 20:17:10 +08:00
parent 92b5f6baff
commit 344623e0c9
3 changed files with 67 additions and 88 deletions

View File

@ -119,10 +119,23 @@ export default {
if (callback) { if (callback) {
callback(response); callback(response);
} }
yield put({ // yield put({
type: 'tree', // type: 'tree',
payload: {}, // payload: {},
}); // });
alert('添加成功!后续改成跳转到手机站的详情');
},
*update({ payload }, { call, put }) {
const { callback, body } = payload;
const response = yield call(productSpuAdd, body);
if (callback) {
callback(response);
}
// yield put({
// type: 'tree',
// payload: {},
// });
alert('修改成功!后续改成跳转到手机站的详情');
}, },
}, },

View File

@ -1,5 +1,6 @@
import { message } from 'antd'; import { message } from 'antd';
import { productSpuPage, productCategoryAdd, productCategoryUpdate, productCategoryUpdateStatus, productCategoryDelete } from '../../services/product'; import { productSpuPage, productCategoryAdd, productCategoryUpdate, productCategoryUpdateStatus, productCategoryDelete } from '../../services/product';
import {routerRedux} from "dva/router";
export default { export default {
namespace: 'productSpuList', namespace: 'productSpuList',
@ -9,46 +10,50 @@ export default {
}, },
effects: { effects: {
*add({ payload }, { call, put }) { // *add({ payload }, { call, put }) {
const { callback, body } = payload; // const { callback, body } = payload;
const response = yield call(productCategoryAdd, body); // const response = yield call(productCategoryAdd, body);
if (callback) { // if (callback) {
callback(response); // callback(response);
} // }
yield put({ // yield put({
type: 'tree', // type: 'tree',
payload: {}, // payload: {},
}); // });
}, // },
*update({ payload }, { call, put }) { // *update({ payload }, { call, put }) {
const { callback, body } = payload; // const { callback, body } = payload;
const response = yield call(productCategoryUpdate, body); // const response = yield call(productCategoryUpdate, body);
if (callback) { // if (callback) {
callback(response); // callback(response);
} // }
yield put({ // yield put({
type: 'tree', // type: 'tree',
payload: {}, // payload: {},
}); // });
}, // },
*updateStatus({ payload }, { call, put }) { // *updateStatus({ payload }, { call, put }) {
const { callback, body } = payload; // const { callback, body } = payload;
const response = yield call(productCategoryUpdateStatus, body); // const response = yield call(productCategoryUpdateStatus, body);
if (callback) { // if (callback) {
callback(response); // callback(response);
} // }
yield put({ // yield put({
type: 'tree', // type: 'tree',
payload: {}, // payload: {},
}); // });
}, // },
*delete({ payload }, { call, put }) { // *delete({ payload }, { call, put }) {
const response = yield call(productCategoryDelete, payload); // const response = yield call(productCategoryDelete, payload);
message.info('删除成功!'); // message.info('删除成功!');
yield put({ // yield put({
type: 'tree', // type: 'tree',
payload: {}, // payload: {},
}); // });
// },
*redirectToAdd({ payload }, { call, put }) {
// const { callback, body } = payload;
yield put(routerRedux.replace('/product/product-spu-add'));
}, },
*page({ payload }, { call, put }) { *page({ payload }, { call, put }) {
const { queryParams } = payload; const { queryParams } = payload;

View File

@ -77,52 +77,13 @@ class ProductSpuList extends PureComponent {
}); });
} }
handleModalVisible = (flag, modalType, initValues) => { redirectToAdd = () => {
this.setState({ const { dispatch } = this.props;
modalVisible: !!flag, dispatch({
initValues: initValues || {}, type: 'productSpuList/redirectToAdd',
modalType: modalType || 'add',
}); });
}; };
handleAdd = ({ fields, modalType, initValues }) => {
const { dispatch, data } = this.props;
const queryParams = {
pageNo: data.pageNo,
pageSize: data.pageSize,
};
if (modalType === 'add') {
dispatch({
type: 'roleList/add',
payload: {
body: {
...fields,
},
queryParams,
callback: () => {
message.success('添加成功');
this.handleModalVisible();
},
},
});
} else {
dispatch({
type: 'roleList/update',
payload: {
body: {
...initValues,
...fields,
},
queryParams,
callback: () => {
message.success('更新成功');
this.handleModalVisible();
},
},
});
}
};
render() { render() {
// debugger; // debugger;
const { list, data } = this.props; const { list, data } = this.props;
@ -199,7 +160,7 @@ class ProductSpuList extends PureComponent {
<Button <Button
icon="plus" icon="plus"
type="primary" type="primary"
onClick={() => this.handleModalVisible(true, 'add', {})} onClick={this.redirectToAdd}
> >
发布商品 发布商品
</Button> </Button>