Commit 611cc269 authored by beisir's avatar beisir

fix: 修复测试问题&图片上传校验

parent f58cfccc
const isProduction = process.env.NODE_ENV === 'production'; const isProduction = process.env.NODE_ENV === 'production';
let envAPi = { let envAPi = {
api: '//backstms-test1.liangkebang.net', api: '//backstms-gyl2.liangkebang.net',
kdspOpApi: 'https://kdsp-operation-test1.liangkebang.net', kdspOpApi: 'https://kdsp-operation-gyl2.liangkebang.net',
// kdspApi: 'http://192.168.28.107:7000', // kdspApi: 'http://192.168.28.107:7000',
kdspApi: 'https://sc-op-api-test1.liangkebang.net', kdspApi: 'https://sc-op-api-gyl2.liangkebang.net',
prologueDomain: 'https://prologue-test1.liangkebang.net', prologueDomain: 'https://prologue-gyl2.liangkebang.net',
qiniuHost: 'https://appsync.lkbang.net', qiniuHost: 'https://appsync.lkbang.net',
opapiHost: 'https://opapi-test1.liangkebang.net', opapiHost: 'https://opapi-gyl2.liangkebang.net',
// opapiHost: 'http://192.168.29.45:7000', // opapiHost: 'http://192.168.29.45:7000',
}; };
......
...@@ -27,8 +27,8 @@ class goodsManage extends Component { ...@@ -27,8 +27,8 @@ class goodsManage extends Component {
if (!data.firstSpecValue && !data.secondSpecValue) { if (!data.firstSpecValue && !data.secondSpecValue) {
editData.forEach(item => { editData.forEach(item => {
item.marketPrice = data.marketPrice; item.marketPrice = data.marketPrice;
// item.salePrice = data.salePrice; // if (!isEdit) item.productStock = data.productStock; // 编辑状态不可修改库存
if (!isEdit) item.productStock = data.productStock; // 编辑状态不可修改库存 item.productStock = data.productStock;
item.supplyPrice = data.supplyPrice; item.supplyPrice = data.supplyPrice;
item.weight = data.weight; item.weight = data.weight;
item.productStockWarning = data.productStockWarning; item.productStockWarning = data.productStockWarning;
...@@ -38,8 +38,7 @@ class goodsManage extends Component { ...@@ -38,8 +38,7 @@ class goodsManage extends Component {
editData.forEach(item => { editData.forEach(item => {
if (item.firstSpecValue === data.firstSpecValue) { if (item.firstSpecValue === data.firstSpecValue) {
item.marketPrice = data.marketPrice; item.marketPrice = data.marketPrice;
// item.salePrice = data.salePrice; item.productStock = data.productStock;
if (!isEdit) item.productStock = data.productStock;
item.supplyPrice = data.supplyPrice; item.supplyPrice = data.supplyPrice;
item.weight = data.weight; item.weight = data.weight;
item.productStockWarning = data.productStockWarning; item.productStockWarning = data.productStockWarning;
...@@ -50,8 +49,7 @@ class goodsManage extends Component { ...@@ -50,8 +49,7 @@ class goodsManage extends Component {
editData.forEach(item => { editData.forEach(item => {
if (item.secondSpecValue === data.secondSpecValue) { if (item.secondSpecValue === data.secondSpecValue) {
item.marketPrice = data.marketPrice; item.marketPrice = data.marketPrice;
// item.salePrice = data.salePrice; item.productStock = data.productStock;
if (!isEdit) item.productStock = data.productStock;
item.supplyPrice = data.supplyPrice; item.supplyPrice = data.supplyPrice;
item.weight = data.weight; item.weight = data.weight;
item.productStockWarning = data.productStockWarning; item.productStockWarning = data.productStockWarning;
...@@ -65,8 +63,7 @@ class goodsManage extends Component { ...@@ -65,8 +63,7 @@ class goodsManage extends Component {
item.secondSpecValue === data.secondSpecValue item.secondSpecValue === data.secondSpecValue
) { ) {
item.marketPrice = data.marketPrice; item.marketPrice = data.marketPrice;
// item.salePrice = data.salePrice; item.productStock = data.productStock;
if (!isEdit) item.productStock = data.productStock;
item.supplyPrice = data.supplyPrice; item.supplyPrice = data.supplyPrice;
item.weight = data.weight; item.weight = data.weight;
item.productStockWarning = data.productStockWarning; item.productStockWarning = data.productStockWarning;
...@@ -148,20 +145,18 @@ class goodsManage extends Component { ...@@ -148,20 +145,18 @@ class goodsManage extends Component {
)} )}
</FormItem> </FormItem>
)} )}
{!isEdit && ( <FormItem>
<FormItem> {getFieldDecorator('productStock', {})(
{getFieldDecorator('productStock', {})( <InputNumber
<InputNumber precision={0}
precision={0} step={1}
step={1} // eslint-disable-next-line radix
// eslint-disable-next-line radix formatter={val => parseInt(val, '10') || ''}
formatter={val => parseInt(val, '10') || ''} placeholder="库存"
placeholder="库存" style={{ width: 100 }}
style={{ width: 100 }} />,
/>, )}
)} </FormItem>
</FormItem>
)}
<FormItem> <FormItem>
{getFieldDecorator('productStockWarning', {})( {getFieldDecorator('productStockWarning', {})(
<InputNumber <InputNumber
......
...@@ -242,7 +242,7 @@ export function editColumns(methods, firstData, firstSpec, secondSpec, isJDGoods ...@@ -242,7 +242,7 @@ export function editColumns(methods, firstData, firstSpec, secondSpec, isJDGoods
precision={0} precision={0}
min={0} min={0}
onChange={value => inputChange(value, 'productStock', index)} onChange={value => inputChange(value, 'productStock', index)}
disabled={isEdit && row.id} // disabled={isEdit && row.id}
/> />
), ),
}, },
......
...@@ -31,6 +31,7 @@ import SearchForm from './SearchForm'; ...@@ -31,6 +31,7 @@ import SearchForm from './SearchForm';
class goodsManage extends Component { class goodsManage extends Component {
state = { state = {
pageNo: 1, pageNo: 1,
loading: false,
treeData: [], treeData: [],
virtualTreeData: [], virtualTreeData: [],
pageSize: 20, pageSize: 20,
...@@ -51,8 +52,6 @@ class goodsManage extends Component { ...@@ -51,8 +52,6 @@ class goodsManage extends Component {
type: 1, type: 1,
}; };
loading = false;
currentLog = null; currentLog = null;
supplierId = null; supplierId = null;
...@@ -77,11 +76,11 @@ class goodsManage extends Component { ...@@ -77,11 +76,11 @@ class goodsManage extends Component {
}; };
handleSearch = page => { handleSearch = page => {
this.loading = true;
const currentPage = this.state.pageNo; const currentPage = this.state.pageNo;
this.setState( this.setState(
{ {
pageNo: page || currentPage, pageNo: page || currentPage,
loading: true,
}, },
() => { () => {
const { dispatch } = this.props; const { dispatch } = this.props;
...@@ -93,8 +92,11 @@ class goodsManage extends Component { ...@@ -93,8 +92,11 @@ class goodsManage extends Component {
pageSize, pageSize,
...this.searchForm.getFieldsValue(), ...this.searchForm.getFieldsValue(),
}, },
}).finally(() => {
this.setState({
loading: false,
});
}); });
this.loading = false;
}, },
); );
}; };
...@@ -313,7 +315,7 @@ class goodsManage extends Component { ...@@ -313,7 +315,7 @@ class goodsManage extends Component {
addSpu={() => this.setState({ createVisible: true, initData: {} })} addSpu={() => this.setState({ createVisible: true, initData: {} })}
/> />
</Card> </Card>
<Spin spinning={this.loading}> <Spin spinning={this.state.loading}>
<Table <Table
dataSource={tableData?.records} dataSource={tableData?.records}
bordered bordered
......
...@@ -87,7 +87,7 @@ export function column() { ...@@ -87,7 +87,7 @@ export function column() {
dataIndex: 'skuName', dataIndex: 'skuName',
}, },
{ {
title: '价格', title: '供应商价格',
dataIndex: 'marketPrice', dataIndex: 'marketPrice',
width: 150, width: 150,
align: 'center', align: 'center',
...@@ -105,17 +105,23 @@ export function column() { ...@@ -105,17 +105,23 @@ export function column() {
dataIndex: 'stock', dataIndex: 'stock',
align: 'center', align: 'center',
sorter: (a, b) => a.stock - b.stock, sorter: (a, b) => a.stock - b.stock,
render: (_, row) => ( render: (_, row) => {
<> const stockView =
<p> row.state !== 4 ? (
当前库存:<a onClick={() => this.openModal(row, 'productStock')}>{row.productStock}</a> <a onClick={() => this.openModal(row, 'productStock')}>{row.productStock}</a>
</p> ) : (
<p>可售库存:{_}</p> <span>{row.productStock}</span>
{row.type === 1 && row.productStockWarning > -1 && ( );
<p>预警值:{row.productStockWarning}</p> return (
)} <>
</> <p>当前库存:{stockView}</p>
), <p>可售库存:{_}</p>
{row.type === 1 && row.productStockWarning > 0 && (
<p>预警值:{row.productStockWarning}</p>
)}
</>
);
},
}, },
{ {
title: '审核状态', title: '审核状态',
......
import { Upload, Icon, Modal, notification } from 'antd'; import { Upload, Icon, Modal, notification } from 'antd';
import React from 'react'; import React from 'react';
import { ReactSortable } from 'react-sortablejs'; import { ReactSortable } from 'react-sortablejs';
import lodash from 'lodash';
import { uploadImg } from '../../GoodsManage/service'; import { uploadImg } from '../../GoodsManage/service';
import styles from './styles.less'; import styles from './styles.less';
const DETAIL_IMG_MAX_WIDTH = 750; const DETAIL_IMG_MAX_WIDTH = 750;
const LOOP_IMG_WIDTH_HEIGHT = 800; const LOOP_IMG_WIDTH_HEIGHT = 800;
const cleanArray = actual => {
const newArray = [];
// eslint-disable-next-line no-plusplus
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i]);
}
}
return newArray;
};
const warningTip = description => {
notification.warning({
duration: null,
message: '图片上传失败',
description,
});
};
const getBase64 = (img, callback) => { const getBase64 = (img, callback) => {
const reader = new FileReader(); const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result)); reader.addEventListener('load', () => callback(reader.result));
reader.readAsDataURL(img); reader.readAsDataURL(img);
}; };
const ImageInfo = file => const ImageInfo = file =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
console.log(file.size / 1024 / 1024); const LtMB = file.size / 1024 / 1024;
const isLt2M = file.size / 1024 / 1024 < 2; if (LtMB > 2) {
if (!isLt2M) { warningTip(`[${file.name}] 图片不可以大于2MB`);
notification.warning({ resolve(null);
message: '上传图片不可以大于2MB',
});
reject();
} }
getBase64(file, url => { getBase64(file, url => {
const image = new Image(); const image = new Image();
image.addEventListener('load', () => { image.addEventListener('load', () => {
const { width } = image; const { width } = image;
const { height } = image; const { height } = image;
resolve({ width, height }); file.width = width;
file.height = height;
file.LtMB = LtMB;
console.log(file);
resolve(file);
}); });
image.addEventListener('error', () => { image.addEventListener('error', () => {
notification.warning({ warningTip(`${file.name}图片上传失败!`);
message: '图片上传失败!', resolve(null);
});
reject();
}); });
image.src = url; image.src = url;
}); });
}); });
const isUploadNext = async ({ width, height }, id) => { const CheckImageInfoList = async files => {
if (id === 'detailImageList') { const promiseImage = files.map(file => ImageInfo(file));
if (width > DETAIL_IMG_MAX_WIDTH) { const clearImage = await Promise.all(promiseImage);
notification.warning({ return cleanArray(clearImage);
message: `详情图宽度不可大于${DETAIL_IMG_MAX_WIDTH}`, };
});
const isUploadNext = async (imgFileList, id) => {
const filterImage = imgFileList.filter(({ width, height, name }) => {
if (id === 'detailImageList') {
if (width > DETAIL_IMG_MAX_WIDTH) {
warningTip(`[${name}] 详情图宽度不可大于${DETAIL_IMG_MAX_WIDTH}`);
return false;
}
return true;
}
if (width > LOOP_IMG_WIDTH_HEIGHT || height > LOOP_IMG_WIDTH_HEIGHT) {
warningTip(`[${name}] 滑动图尺寸不可大于 ${LOOP_IMG_WIDTH_HEIGHT}*${LOOP_IMG_WIDTH_HEIGHT}`);
return false; return false;
} }
} return true;
});
if (width > LOOP_IMG_WIDTH_HEIGHT || height > LOOP_IMG_WIDTH_HEIGHT) { return filterImage;
notification.warning({
message: `滑动图尺寸不可大于 ${LOOP_IMG_WIDTH_HEIGHT}*${LOOP_IMG_WIDTH_HEIGHT}`,
});
return false;
}
return true;
}; };
class PicturesWall extends React.Component { class PicturesWall extends React.Component {
state = { state = {
previewVisible: false, previewVisible: false,
...@@ -137,17 +159,16 @@ class PicturesWall extends React.Component { ...@@ -137,17 +159,16 @@ class PicturesWall extends React.Component {
const { max } = this.props; const { max } = this.props;
const that = this; const that = this;
const uploadProps = { const uploadProps = {
beforeUpload: async file => { beforeUpload: lodash.debounce(async (file, files) => {
console.log(file); const optionsArray = await CheckImageInfoList(files);
const options = await ImageInfo(file); const onRightImgList = await isUploadNext(optionsArray, that.props.id);
console.log(options); if (!onRightImgList.length) {
const isNext = await isUploadNext(options, that.props.id);
if (!isNext) {
return; return;
} }
console.log('校验通过的队列=======>', onRightImgList);
this.setState( this.setState(
state => ({ state => ({
newFile: [...state.newFile, file], newFile: [...state.newFile, ...onRightImgList],
}), }),
async () => { async () => {
const data = await uploadImg(that.state.newFile); const data = await uploadImg(that.state.newFile);
...@@ -171,7 +192,7 @@ class PicturesWall extends React.Component { ...@@ -171,7 +192,7 @@ class PicturesWall extends React.Component {
); );
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
return false; return false;
}, }, 500),
listType: 'picture-card', listType: 'picture-card',
}; };
return ( return (
......
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