Commit 611cc269 authored by beisir's avatar beisir

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

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