Commit 2830efb3 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix:

parent de69ff87
...@@ -15,6 +15,7 @@ import { PublicApi } from '@/services/api'; ...@@ -15,6 +15,7 @@ import { PublicApi } from '@/services/api';
import TabTree from '@/components/TabTree'; import TabTree from '@/components/TabTree';
import { createFormActions } from '@formily/antd'; import { createFormActions } from '@formily/antd';
import { useTreeTabs } from '@/hooks/useTreeTabs'; import { useTreeTabs } from '@/hooks/useTreeTabs';
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable';
const formActions = createFormActions() const formActions = createFormActions()
...@@ -35,6 +36,7 @@ const CategoryAttributes: React.FC<{}> = () => { ...@@ -35,6 +36,7 @@ const CategoryAttributes: React.FC<{}> = () => {
const [selectTableRow, setSelectTableRow] = useState<any[]>([]) const [selectTableRow, setSelectTableRow] = useState<any[]>([])
const [selectedTableRowKeys, setSelectedTableRowKeys] = useState<Array<number>>([]) //表格选择 const [selectedTableRowKeys, setSelectedTableRowKeys] = useState<Array<number>>([]) //表格选择
const [linkTableRowData, setLinkTableRowData] = useState<any[]>([]) const [linkTableRowData, setLinkTableRowData] = useState<any[]>([])
const [goodsRowSelection, goodsRowCtl] = useRowSelectionTable()
const { const {
treeStatus, treeStatus,
...@@ -84,8 +86,8 @@ const CategoryAttributes: React.FC<{}> = () => { ...@@ -84,8 +86,8 @@ const CategoryAttributes: React.FC<{}> = () => {
const handleSelectOk = () => { const handleSelectOk = () => {
setRoleVisible(false) setRoleVisible(false)
if (selectTableRow.length) { if (goodsRowCtl.selectRow.length) {
PublicApi.postProductCustomerSaveCustomerCategoryAttribute({ customerCategoryId: selectKey, customerAttributeIds: selectedTableRowKeys }).then(res=>{ PublicApi.postProductCustomerSaveCustomerCategoryAttribute({ customerCategoryId: selectKey, customerAttributeIds: goodsRowCtl.selectedRowKeys }).then(res=>{
//@ts-ignore //@ts-ignore
ref.current.reload() ref.current.reload()
}) })
...@@ -344,7 +346,8 @@ const CategoryAttributes: React.FC<{}> = () => { ...@@ -344,7 +346,8 @@ const CategoryAttributes: React.FC<{}> = () => {
<StandardTable <StandardTable
columns={columnsLink} columns={columnsLink}
currentRef={refLink} currentRef={refLink}
rowSelection={rowSelection} // rowSelection={rowSelection}
rowSelection={goodsRowSelection}
fetchTableData={(params: any) => fetchAttributeData(params)} fetchTableData={(params: any) => fetchAttributeData(params)}
tableProps={{ tableProps={{
rowKey: 'id' rowKey: 'id'
......
...@@ -22,7 +22,7 @@ import { GetProductCustomerGetCustomerAttributeResponse } from '@/services'; ...@@ -22,7 +22,7 @@ import { GetProductCustomerGetCustomerAttributeResponse } from '@/services';
const formActions = createFormActions() const formActions = createFormActions()
const fetchAttributeTreeData = async (params?) => { const fetchAttributeTreeData = async (params?) => {
const res = await PublicApi.getProductCustomerGetCustomerAttributeTree() const res = await PublicApi.getProductCustomerGetCustomerAttributeTree({filterInput: true})
return res return res
} }
......
...@@ -108,7 +108,7 @@ const AddGoods = () => { ...@@ -108,7 +108,7 @@ const AddGoods = () => {
} }
const onFinish = (values:any) => { const onFinish = (values:any) => {
PublicApi.postProductGoodsSaveOrUpdateGoods({...values}).then(res => { PublicApi.postProductGoodsSaveOrUpdateGoods({...values, id: queryId?queryId:null}).then(res => {
if(res.code === 1000) if(res.code === 1000)
history.goBack() history.goBack()
}) })
......
...@@ -30,6 +30,8 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -30,6 +30,8 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
const [logisticsAddressList, setLogisticsAddressList] = useState<GetLogisticsSelectListShipperAddressResponse>() const [logisticsAddressList, setLogisticsAddressList] = useState<GetLogisticsSelectListShipperAddressResponse>()
const [logisticsTemplateList, setLogisticsTemplateList] = useState<GetLogisticsSelectListFreightTemplateResponse>() const [logisticsTemplateList, setLogisticsTemplateList] = useState<GetLogisticsSelectListFreightTemplateResponse>()
const [isTemplate, setIsTemplate] = useState<boolean>(false) const [isTemplate, setIsTemplate] = useState<boolean>(false)
const [deliveryType, setDeliveryType] = useState<number>(1)
const [carriageType, setCarriageType] = useState<number>()
const { productInfoByEdit } = ProductStore const { productInfoByEdit } = ProductStore
useEffect(()=>{ useEffect(()=>{
...@@ -51,8 +53,17 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -51,8 +53,17 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
}, []) }, [])
const changeDeliveryType = (e) => {
setDeliveryType(e.target.value)
setCarriageType(1)
setIsTemplate(false)
logisticsForm.resetFields()
logisticsForm.setFieldsValue({deliveryType: e.target.value})
}
const onChangeTemplate = (e) => { const onChangeTemplate = (e) => {
setIsTemplate(e.target.checked) setIsTemplate(e.target.checked)
logisticsForm.setFieldsValue({weight: null})
} }
return (<> return (<>
...@@ -77,50 +88,54 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -77,50 +88,54 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
]} ]}
initialValue={1} initialValue={1}
> >
<Radio.Group> <Radio.Group onChange={changeDeliveryType}>
<Radio value={1}>物流(默认)</Radio> <Radio value={1}>物流(默认)</Radio>
<Radio value={2}>自提</Radio> <Radio value={2}>自提</Radio>
<Radio value={3}>无需配送</Radio> <Radio value={3}>无需配送</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Form.Item {
name="carriageType" deliveryType === 1 && <><Form.Item
label="运费方式" name="carriageType"
rules={[ label="运费方式"
{ rules={[
required: true, {
message: '请选择运费方式' required: true,
}, message: '请选择运费方式'
]} },
initialValue={1} ]}
> initialValue={1}
<Radio.Group> >
<Radio value={1}>卖家承担运费(默认)</Radio> <Radio.Group onChange={(e)=>setCarriageType(e.target.value)}>
<Radio value={2}>买家承担运费</Radio> <Radio value={1}>卖家承担运费(默认)</Radio>
</Radio.Group> <Radio value={2}>买家承担运费</Radio>
</Form.Item> </Radio.Group>
<Form.Item </Form.Item>
name="weight" <Form.Item
label="重量" name="weight"
rules={[ label="重量"
{ rules={[
required: true, {
type: 'number', required: true,
message: '请填入重量', type: 'number',
min: 0, message: '请填入重量',
transform: (value) => Number(value) min: 0,
}, transform: (value) => Number(value)
]} },
> ]}
<Input suffix="KG" placeholder="请输入重量" /> >
</Form.Item> <Input suffix="KG" placeholder="请输入重量" />
<Form.Item </Form.Item></>
name="useTemplate" }
valuePropName="checked" {
label=" " carriageType === 2 && <Form.Item
> name="useTemplate"
<Checkbox onChange={onChangeTemplate}>使用运费模板(只有买家承担运费才能选择)</Checkbox> valuePropName="checked"
</Form.Item> label=" "
>
<Checkbox onChange={onChangeTemplate}>使用运费模板(只有买家承担运费才能选择)</Checkbox>
</Form.Item>
}
{ {
isTemplate && <Form.Item isTemplate && <Form.Item
name="templateId" name="templateId"
...@@ -136,32 +151,36 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -136,32 +151,36 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
</Select> </Select>
</Form.Item> </Form.Item>
} }
<Form.Item {
name="sendAddress" deliveryType !== 3 && <Form.Item
label="发货地址" name="sendAddress"
> label="发货地址"
<Select
placeholder="请选择发货地址"
allowClear
> >
{ <Select
logisticsAddressList?.length > 0 && logisticsAddressList.map(_=><Option key={_.id} value={_.id}>{_.fullAddress}</Option>) placeholder="请选择发货地址"
} allowClear
</Select> >
</Form.Item> {
<Form.Item logisticsAddressList?.length > 0 && logisticsAddressList.map(_=><Option key={_.id} value={_.id}>{_.fullAddress}</Option>)
name="company" }
label="物流公司" </Select>
> </Form.Item>
<Select }
placeholder="请选择物流公司" {
allowClear deliveryType === 1 && <Form.Item
name="company"
label="物流公司"
> >
{ <Select
logisticsCompanyLists?.length > 0 && logisticsCompanyLists.map(_=><Option key={_.id} value={_.id}>{_.name}</Option>) placeholder="请选择物流公司"
} allowClear
</Select> >
</Form.Item> {
logisticsCompanyLists?.length > 0 && logisticsCompanyLists.map(_=><Option key={_.id} value={_.id}>{_.name}</Option>)
}
</Select>
</Form.Item>
}
</Form> </Form>
</>) </>)
} }
......
import React, { useState, useEffect, useRef, useContext, useCallback, useMemo } from 'react' import React, { useState, useEffect, useRef, useContext, useCallback, useMemo } from 'react'
import {history} from 'umi' import {history} from 'umi'
import { Button, Form, Select, Checkbox, Tooltip, Radio, Input, Table, Modal, Row, Col, InputNumber } from 'antd' import { Button, Form, Select, Checkbox, Tooltip, Radio, Input, Table, Modal, Row, Col, InputNumber, message } from 'antd'
import styles from './index.less' import styles from './index.less'
import { PublicApi } from '@/services/api' import { PublicApi } from '@/services/api'
import { StandardTable } from 'god' import { StandardTable } from 'god'
...@@ -47,8 +47,8 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -47,8 +47,8 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const [combineAttributeArray, setCombineAttributeArray] = useState<any[]>([]) const [combineAttributeArray, setCombineAttributeArray] = useState<any[]>([])
const [attributeObjArr, setAttributeObjArr] = useState<any[]>([]) const [attributeObjArr, setAttributeObjArr] = useState<any[]>([])
const [attributeValObjArr, setAttributeValObjArr] = useState<any[]>([]) const [attributeValObjArr, setAttributeValObjArr] = useState<any[]>([])
const [minOrderNumber, setMinOrderNumber] = useState<number>()
const [validatorArray, setValidatorArray] = useState<any>([])
const [colums, setColumns] = useState<ColumnType<any>[]>() const [colums, setColumns] = useState<ColumnType<any>[]>()
const { ProductStore } = store const { ProductStore } = store
...@@ -286,8 +286,8 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -286,8 +286,8 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const setPriceOk = () => { const setPriceOk = () => {
setPriceForm.validateFields().then(v => { setPriceForm.validateFields().then(v => {
setSetPriceModal(false)
console.log(v, 'ladder') console.log(v, 'ladder')
setSetPriceModal(false)
const { ladderPrice, ladderRange } = v const { ladderPrice, ladderRange } = v
let _priceRange = {} let _priceRange = {}
if(ladderPrice){ // 判断阶梯价格 if(ladderPrice){ // 判断阶梯价格
...@@ -303,7 +303,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -303,7 +303,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
newTabeData[curretSetPriceRow['索引']] = _row newTabeData[curretSetPriceRow['索引']] = _row
_tableDataSource = newTabeData _tableDataSource = newTabeData
setTableDataSource(_tableDataSource) setTableDataSource(_tableDataSource)
console.log(_tableDataSource, curretSetPriceRow, v,'setPriceOk') // console.log(_tableDataSource, curretSetPriceRow, v,'setPriceOk')
}) })
} }
...@@ -315,12 +315,30 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -315,12 +315,30 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const clickSetPrice = (record: any) => { const clickSetPrice = (record: any) => {
setCurrentSetPriceRow(record) setCurrentSetPriceRow(record)
setSetPriceModal(true) setSetPriceModal(true)
setPriceForm.resetFields() // 若需要价格回显 在此处处理 console.log(record, 'record') // 通过判断key字符串'0-0' 是否是阶梯价格 注:空对象时候{}为新建状态
setLadderPrice(false) setPriceForm.resetFields() // 先清空 若需要价格回显 在此处处理
if(Object.keys(record['单价'])[0] === '0-0') { // 状态为非阶梯价格
setLadderPrice(false)
setPriceForm.setFieldsValue({ladderPrice: false, uniquePrice: Object.values(record['单价'])[0]})
}else if(JSON.stringify(record['单价']) === '{}'){ // 新建情况下默认为{}
setLadderPrice(false)
}else{ // 否则编辑情况下
setLadderPrice(true)
let numberArray = Object.keys(record['单价']).map(item => item.split('-').map(_ => Number(_)))
let priceArray = Object.values(record['单价'])
let tempArr = [];
numberArray.map((_item, _index) => {
tempArr.push({ numberPrice: priceArray[_index], numberRange: { numberMin: _item[0], numberMax: _item[1] } })
})
setPriceForm.setFieldsValue({ladderPrice: true, ladderRange: tempArr})
}
} }
const changeLadderPrice = (e: any) => { const changeLadderPrice = (e: any) => {
setLadderPrice(e.target.checked) setLadderPrice(e.target.checked)
if(e.target.checked && minOrderNumber){
setPriceForm.setFieldsValue({ladderRange: [{numberPrice: null, numberRange: {numberMin: minOrderNumber, numberMax: null}}]})
}
} }
const handleUnitSearch = (value:any) => { const handleUnitSearch = (value:any) => {
...@@ -341,16 +359,28 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -341,16 +359,28 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
priceForm.setFieldsValue({unitName: option.children}) priceForm.setFieldsValue({unitName: option.children})
} }
// 校验数值范围 // 校验阶梯范围
const validatorNumberRange = (rule, value, callback) => { const validatorNumberRange = (rule, value, callback) => {
console.log(value, 'value')
try { try {
setValidatorArray([...validatorArray, value]) if(Array.isArray(value)){
console.log(value, [...validatorArray, value], 'rule') console.log(value, 'array')
if(value.numberMin >= value.numberMax){ let range = value.map(item => {
throw new Error('请正确输入数值范围') if(item)
return Object.values(item.numberRange)
}).reduce(
function(a, b) {
return a.concat(b);
},
[]
)
let result = range.reduce((a, b) => { console.log(a, b); if(a<b) return b })
console.log(result, 'result')
if(!result) throw new Error('请正确输入阶梯数量范围');
callback()
} }
} catch (err) { } catch (err) {
// callback(err) callback(err)
} }
} }
...@@ -422,7 +452,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -422,7 +452,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
transform: (value) => Number(value) transform: (value) => Number(value)
}]} }]}
> >
<InputNumber style={{width: '100%'}} min={0} placeholder="请输入最小起订数" /> <InputNumber style={{width: '100%'}} min={0} placeholder="请输入最小起订数" onChange={(e: number) => setMinOrderNumber(e)} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="priceType" name="priceType"
...@@ -436,7 +466,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -436,7 +466,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
} }
rules={[{ rules={[{
required: true, required: true,
message: '请输入最小起订数' message: '请选择产品定价类型'
}]} }]}
initialValue={planPrice} initialValue={planPrice}
> >
...@@ -497,6 +527,15 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -497,6 +527,15 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
name="ladderRange" name="ladderRange"
label="" label=""
shouldUpdate={true} shouldUpdate={true}
rules={[
{
required: true,
message: '阶梯范围为必填项'
},
{
validator: validatorNumberRange
}
]}
> >
<Form.List name="ladderRange" key={Math.random()}> <Form.List name="ladderRange" key={Math.random()}>
{(fields, { add, remove }) => { {(fields, { add, remove }) => {
...@@ -516,18 +555,23 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -516,18 +555,23 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
noStyle noStyle
// rules={[ // rules={[
// { // {
// validator: validatorNumberRange // required: true,
// } // message: '阶梯价格为必填项'
// },
// ]} // ]}
> >
<Input.Group compact> <Input.Group compact>
<Form.Item <Form.Item
name={[field.name, 'numberRange', 'numberMin']} name={[field.name, 'numberRange', 'numberMin']}
noStyle noStyle
rules={[ rules={[
{ {
required: true,
message: '阶梯最小数量为必填项'
},
{
pattern: /^\d+(\.\d{1,3})?$/, pattern: /^\d+(\.\d{1,3})?$/,
message: '小数点后仅限三位', message: '阶梯数值小数点后仅限三位',
} }
]} ]}
> >
...@@ -548,8 +592,12 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -548,8 +592,12 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
noStyle noStyle
rules={[ rules={[
{ {
required: true,
message: '阶梯最大数量为必填项'
},
{
pattern: /^\d+(\.\d{1,3})?$/, pattern: /^\d+(\.\d{1,3})?$/,
message: '小数点后仅限三位', message: '阶梯数值小数点后仅限三位',
} }
]} ]}
> >
...@@ -572,8 +620,12 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -572,8 +620,12 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
noStyle noStyle
rules={[ rules={[
{ {
required: true,
message: '阶梯单价为必填项'
},
{
pattern: /^\d+(\.\d{1,4})?$/, pattern: /^\d+(\.\d{1,4})?$/,
message: '小数点后仅限四位', message: '阶梯单价小数点后仅限四位',
} }
]} ]}
> >
......
...@@ -431,13 +431,13 @@ const Products: React.FC<{}> = () => { ...@@ -431,13 +431,13 @@ const Products: React.FC<{}> = () => {
} }
if(isUp) if(isUp)
PublicApi.postProductCommodityPublishCommodity(params).then(res => { PublicApi.postProductCommodityPublishCommodity(params).then(res => {
if(res.code === 1000) setUpDownModal(false)
setUpDownModal(false) ref.current.reload()
}) })
else else
PublicApi.postProductCommodityOffPublishCommodity(params).then(res => { PublicApi.postProductCommodityOffPublishCommodity(params).then(res => {
if(res.code === 1000) setUpDownModal(false)
setUpDownModal(false) ref.current.reload()
}) })
} }
...@@ -448,8 +448,10 @@ const Products: React.FC<{}> = () => { ...@@ -448,8 +448,10 @@ const Products: React.FC<{}> = () => {
const clickCopy = (record: any) => { const clickCopy = (record: any) => {
console.log('复制商品') console.log('复制商品')
const { id } = record; const { id } = record;
if(id) if(id){
PublicApi.postProductCommodityCopyCommodity({id: id}) PublicApi.postProductCommodityCopyCommodity({id: id})
ref.current.reload()
}
} }
const clickSubmitCheck = (record:any) => { const clickSubmitCheck = (record:any) => {
...@@ -474,7 +476,10 @@ const Products: React.FC<{}> = () => { ...@@ -474,7 +476,10 @@ const Products: React.FC<{}> = () => {
const handleBatchDelete = (ids: string[]) => { const handleBatchDelete = (ids: string[]) => {
console.log('删除', ids) console.log('删除', ids)
//@ts-ignore //@ts-ignore
PublicApi.postProductCommodityDeleteBatchCommodity({idList: ids}) PublicApi.postProductCommodityDeleteBatchCommodity({idList: ids}).then(res => {
if(res.code === 1000)
ref.current.reload()
})
} }
const handleReset = () => { const handleReset = () => {
......
...@@ -25,7 +25,7 @@ class ProductStore implements IProductModule { ...@@ -25,7 +25,7 @@ class ProductStore implements IProductModule {
slogan: this.productInfoByEdit?.slogan, slogan: this.productInfoByEdit?.slogan,
sellingPoint: this.productInfoByEdit?.sellingPoint, sellingPoint: this.productInfoByEdit?.sellingPoint,
commodityAreaList: this.productInfoByEdit?.commodityAreaList.map(item => [item.provinceCode, item.cityCode]), commodityAreaList: this.productInfoByEdit?.commodityAreaList.map(item => [item.provinceCode, item.cityCode]),
customerCategoryId: [this.productInfoByEdit?.customerCategory.parentId + '', this.productInfoByEdit?.customerCategory.id + ''] customerCategoryId: this.productInfoByEdit?.customerCategory.parentId ? [this.productInfoByEdit?.customerCategory.parentId + '', this.productInfoByEdit?.customerCategory.id + ''] : [this.productInfoByEdit?.customerCategory.id + '']
} }
} }
......
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