From 582837fee001c02eb1e235af0de980e3ef3de196 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Thu, 2 May 2019 23:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=EF=BC=8C=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=20sku=20=E7=BC=96=E8=BE=91=E7=9A=84?= =?UTF-8?q?=20bug=20=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Product/ProductAttrSelectFormItem.js | 106 ++++++++++++------ admin-web/src/defaultSettings.js | 2 +- admin-web/src/layouts/UserLayout.js | 2 +- .../src/models/product/productAttrList.js | 25 ++++- .../pages/Product/ProductSpuAddOrUpdate.js | 14 +-- admin-web/src/pages/document.ejs | 2 +- admin-web/src/services/product.js | 7 ++ 7 files changed, 113 insertions(+), 45 deletions(-) diff --git a/admin-web/src/components/Product/ProductAttrSelectFormItem.js b/admin-web/src/components/Product/ProductAttrSelectFormItem.js index ed2be81c7..958e3e06e 100644 --- a/admin-web/src/components/Product/ProductAttrSelectFormItem.js +++ b/admin-web/src/components/Product/ProductAttrSelectFormItem.js @@ -3,9 +3,72 @@ import {Select} from "antd"; const Option = Select.Option; +class AttrValueSelect extends Select { + + handleSelectAttrValue = (value, option) => { + + }; + + render() { + const {index, attrValues, attrValueOptions, attr} = this.props; + + const handleChangeAttrValue = async (values, options) => { + let attrValues = []; + const {dispatch, index} = this.props; + // debugger; + // console.log('x' + this.children[0]); + // let firstOption = this.children[0]; + // let attrIndex = firstOption.key.substring(firstOption.key.indexOf('option-attr-value-') + 'option-attr-value-'.length, firstOption.key.lastIndexOf('-')); + for (let i in options) { + let option = options[i]; + // TODO 芋艿,这个做法很不优雅,后面看俺。需要问下 answer 。 + let attrValueId = undefined; + if (option.key.indexOf('option-attr-value-') === -1) { + await dispatch({ + type: 'productAttrList/addValue', + payload: { + attrId: attr.id, + name: option.props.children, + }, + callback: function (data) { + attrValueId = data.id; + } + }); + } else { + attrValueId = parseInt(option.props.value); + } + // 添加到 attrValues 中。 + // debugger; + attrValues.push({ + id: attrValueId, + name: option.props.children, + }); + } + dispatch({ + type: 'productSpuAddOrUpdate/selectAttrValues', + payload: { + attrIndex: index, + attrValues: attrValues, + }, + }); + // debugger; + + // console.log(value); + }; + + return ; + } + +} + export default class ProductAttrSelectFormItem extends PureComponent { handleSelectAttr = (value, option) => { + debugger; // console.log(value); // console.log(option); // debugger; @@ -26,34 +89,8 @@ export default class ProductAttrSelectFormItem extends PureComponent { }); }; - handleSelectAttrValue = (values, options) => { - let attrValues = []; - const { dispatch, index } = this.props; - // debugger; - // console.log('x' + this.children[0]); - // let firstOption = this.children[0]; - // let attrIndex = firstOption.key.substring(firstOption.key.indexOf('option-attr-value-') + 'option-attr-value-'.length, firstOption.key.lastIndexOf('-')); - for (let i in options) { - let option = options[i]; - attrValues.push({ - id: parseInt(option.props.value), - name: option.props.children, - }); - } - dispatch({ - type: 'productSpuAddOrUpdate/selectAttrValues', - payload: { - attrIndex: index, - attrValues: attrValues, - }, - }); - // debugger; - - // console.log(value); - } - render() { - const {attr, allAttrTree, selectedAttrIds, index} = this.props; + const {attr, allAttrTree, selectedAttrIds, index, dispatch} = this.props; // console.log('i: ' + i); // 1. 规格 let attrOptions = []; @@ -92,14 +129,19 @@ export default class ProductAttrSelectFormItem extends PureComponent { for (let i in attr.values) { attrValues.push(attr.values[i].id + ''); // Select 传入数组时,如果不 + '' ,选不中。 } + let attrValueSelectProps = { + index: index, + attrValues: attrValues, + dispatch: dispatch, + attrValueOptions: attrValueOptions, + attr: attr, + }; + // TODO BUG ,规格不能搜索添加 return
- {attrOptions} - +
; } diff --git a/admin-web/src/defaultSettings.js b/admin-web/src/defaultSettings.js index 8809961b6..5a3dc1b2e 100644 --- a/admin-web/src/defaultSettings.js +++ b/admin-web/src/defaultSettings.js @@ -9,7 +9,7 @@ module.exports = { menu: { disableLocal: false, }, - title: '小商城管理平台', + title: '一个商城管理平台', pwa: true, // your iconfont Symbol Scrip Url // eg://at.alicdn.com/t/font_1039637_btcrd5co4w.js diff --git a/admin-web/src/layouts/UserLayout.js b/admin-web/src/layouts/UserLayout.js index b3ddd0430..c1250f42b 100644 --- a/admin-web/src/layouts/UserLayout.js +++ b/admin-web/src/layouts/UserLayout.js @@ -61,7 +61,7 @@ class UserLayout extends Component {
logo - 小商城管理平台 + 一个商城管理平台
{/*
TODO....
*/} diff --git a/admin-web/src/models/product/productAttrList.js b/admin-web/src/models/product/productAttrList.js index 034187b7c..54ffaf64c 100644 --- a/admin-web/src/models/product/productAttrList.js +++ b/admin-web/src/models/product/productAttrList.js @@ -1,5 +1,5 @@ import { message } from 'antd'; -import { productAttrTree } from '../../services/product'; +import { productAttrTree, productAttrValueAdd } from '../../services/product'; export default { namespace: 'productAttrList', @@ -62,6 +62,29 @@ export default { }, }); }, + *addValue({ payload, callback }, { call, put }) { + // debugger; + // const {queryParams} = payload; + const response = yield call(productAttrValueAdd, payload); + // message.info('查询成功!'); + // yield put({ + // type: 'treeSuccess', + // payload: { + // tree: response.data, + // }, + // }); + if (response.code === 0) { + // 刷新规格列表 + yield put({ + type: 'tree', + payload: {}, + }); + // 回调方法 + if (callback) { + callback(response.data); + } + } + } }, reducers: { diff --git a/admin-web/src/pages/Product/ProductSpuAddOrUpdate.js b/admin-web/src/pages/Product/ProductSpuAddOrUpdate.js index 21f6839ac..93963f17e 100644 --- a/admin-web/src/pages/Product/ProductSpuAddOrUpdate.js +++ b/admin-web/src/pages/Product/ProductSpuAddOrUpdate.js @@ -119,7 +119,7 @@ class ProductSpuAddOrUpdate extends Component { } // debugger; this.props.form.validateFields((err, values) => { - debugger; + // debugger; if (!err) { if (modalType === 'add') { dispatch({ @@ -228,14 +228,10 @@ class ProductSpuAddOrUpdate extends Component { )} - {form.getFieldDecorator('visible', { - initialValue: 1, // TODO 修改 - })( -
- {attrTreeHTML} - -
- )} +
+ {attrTreeHTML} + +
{ attrTree.length > 0 ? diff --git a/admin-web/src/pages/document.ejs b/admin-web/src/pages/document.ejs index 9900e4aaf..d0d8610c5 100644 --- a/admin-web/src/pages/document.ejs +++ b/admin-web/src/pages/document.ejs @@ -7,7 +7,7 @@ name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> - 小商城管理平台 + 一个商城管理平台 diff --git a/admin-web/src/services/product.js b/admin-web/src/services/product.js index cba11bd90..197378fc1 100644 --- a/admin-web/src/services/product.js +++ b/admin-web/src/services/product.js @@ -71,3 +71,10 @@ export async function productAttrTree(params) { method: 'GET', }); } + +export async function productAttrValueAdd(params) { + return request(`/product-api/admins//attr_value/add?${stringify(params)}`, { + method: 'POST', + body: {}, + }); +}