前端:商品编辑,部分逻辑
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { message } from 'antd';
|
||||
import { productSpuPage, productAttrTree, productCategoryUpdate, productCategoryUpdateStatus, productCategoryDelete } from '../../services/product';
|
||||
import { productAttrTree } from '../../services/product';
|
||||
|
||||
export default {
|
||||
namespace: 'productAttrList',
|
||||
@@ -54,7 +54,7 @@ export default {
|
||||
*tree({ payload }, { call, put }) {
|
||||
const { queryParams } = payload;
|
||||
const response = yield call(productAttrTree, queryParams);
|
||||
message.info('查询成功!');
|
||||
// message.info('查询成功!');
|
||||
yield put({
|
||||
type: 'treeSuccess',
|
||||
payload: {
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
import { message } from 'antd';
|
||||
import { productCategoryTree, productSpuAdd, productCategoryUpdate, productCategoryUpdateStatus, productCategoryDelete } from '../../services/product';
|
||||
import {
|
||||
productCategoryTree,
|
||||
productSpuAdd,
|
||||
productCategoryUpdate,
|
||||
productCategoryUpdateStatus,
|
||||
productCategoryDelete,
|
||||
productSpuInfo
|
||||
} from '../../services/product';
|
||||
|
||||
export default {
|
||||
namespace: 'productSpuAddOrUpdate',
|
||||
|
||||
state: {
|
||||
list: [],
|
||||
attrTree: [
|
||||
// list: [],
|
||||
loading: false,
|
||||
spu: { // 商品 SPU
|
||||
|
||||
},
|
||||
|
||||
attrTree: [ // 商品规格
|
||||
// {
|
||||
// id: //
|
||||
// name: //
|
||||
@@ -16,7 +28,7 @@ export default {
|
||||
// }]
|
||||
// }
|
||||
],
|
||||
skus: [
|
||||
skus: [ // 商品 SKU
|
||||
// {
|
||||
// attrs: [{
|
||||
// id: // 规格值编号
|
||||
@@ -29,17 +41,6 @@ export default {
|
||||
},
|
||||
|
||||
effects: {
|
||||
// *add({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
// const response = yield call(productCategoryAdd, body);
|
||||
// if (callback) {
|
||||
// callback(response);
|
||||
// }
|
||||
// yield put({
|
||||
// type: 'tree',
|
||||
// payload: {},
|
||||
// });
|
||||
// },
|
||||
// *update({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
// const response = yield call(productCategoryUpdate, body);
|
||||
@@ -51,25 +52,87 @@ export default {
|
||||
// payload: {},
|
||||
// });
|
||||
// },
|
||||
// *updateStatus({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
// const response = yield call(productCategoryUpdateStatus, body);
|
||||
// if (callback) {
|
||||
// callback(response);
|
||||
// }
|
||||
// yield put({
|
||||
// type: 'tree',
|
||||
// payload: {},
|
||||
// });
|
||||
// },
|
||||
// *delete({ payload }, { call, put }) {
|
||||
// const response = yield call(productCategoryDelete, payload);
|
||||
// message.info('删除成功!');
|
||||
// yield put({
|
||||
// type: 'tree',
|
||||
// payload: {},
|
||||
// });
|
||||
// },
|
||||
*info({ payload }, { call, put }) {
|
||||
// 显示加载中
|
||||
yield put({
|
||||
type: 'changeLoading',
|
||||
payload: true,
|
||||
});
|
||||
|
||||
// 请求
|
||||
const response = yield call(productSpuInfo, {
|
||||
id: payload,
|
||||
});
|
||||
// 响应
|
||||
let skus = [];
|
||||
let attrTree = [];
|
||||
// SKU
|
||||
for (let i in response.data.skus) {
|
||||
let sku = response.data.skus[i];
|
||||
// 处理 sku
|
||||
{
|
||||
let attrs = [];
|
||||
for (let j in sku.attrs) {
|
||||
let attr = sku.attrs[j];
|
||||
attrs.push({
|
||||
id: attr.attrValueId,
|
||||
name: attr.attrValueName,
|
||||
});
|
||||
}
|
||||
let newSku = {
|
||||
...sku,
|
||||
attrs,
|
||||
};
|
||||
skus.push(newSku);
|
||||
}
|
||||
// 处理 attrTree
|
||||
{
|
||||
for (let j in sku.attrs) {
|
||||
// debugger;
|
||||
let attr = sku.attrs[j];
|
||||
let attrTreeNode = undefined;
|
||||
for (let k in attrTree) {
|
||||
let item = attrTree[k];
|
||||
if (item.id === attr.attrId) {
|
||||
attrTreeNode = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!attrTreeNode) {
|
||||
attrTreeNode = {
|
||||
id: attr.attrId,
|
||||
name: attr.attrName,
|
||||
values: [{
|
||||
id: attr.attrValueId,
|
||||
name: attr.attrValueName,
|
||||
}]
|
||||
};
|
||||
attrTree.push(attrTreeNode);
|
||||
} else {
|
||||
// let values = attrTreeNode.values;
|
||||
// for (let k in ) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// debugger;
|
||||
yield put({
|
||||
type: 'setAll',
|
||||
payload: {
|
||||
spu: response.data,
|
||||
skus: skus,
|
||||
attrTree: attrTree,
|
||||
},
|
||||
});
|
||||
|
||||
// 隐藏加载中
|
||||
yield put({
|
||||
type: 'changeLoading',
|
||||
payload: false,
|
||||
});
|
||||
},
|
||||
*addAttr({ payload }, { call, put }) {
|
||||
// const { queryParams } = payload;
|
||||
// const response = yield call(productCategoryTree, queryParams);
|
||||
@@ -212,11 +275,31 @@ export default {
|
||||
...state
|
||||
}
|
||||
},
|
||||
treeSuccess(state, { payload }) {
|
||||
clear(state, {payload}) {
|
||||
return {
|
||||
...state,
|
||||
skus: [],
|
||||
attrTree: [],
|
||||
}
|
||||
},
|
||||
changeLoading(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
listLoading: payload,
|
||||
};
|
||||
},
|
||||
// 设置所有属性
|
||||
setAll(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
...payload,
|
||||
};
|
||||
},
|
||||
}
|
||||
// treeSuccess(state, { payload }) {
|
||||
// return {
|
||||
// ...state,
|
||||
// ...payload,
|
||||
// };
|
||||
// },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -55,6 +55,11 @@ export default {
|
||||
// const { callback, body } = payload;
|
||||
yield put(routerRedux.replace('/product/product-spu-add'));
|
||||
},
|
||||
*redirectToUpdate({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
debugger;
|
||||
yield put(routerRedux.replace('/product/product-spu-update?id=' + payload));
|
||||
},
|
||||
*page({ payload }, { call, put }) {
|
||||
// const { queryParams } = payload;
|
||||
const response = yield call(productSpuPage, payload);
|
||||
|
||||
Reference in New Issue
Block a user