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