Commit d9af01f6 authored by beisir's avatar beisir

fix: 提交本地

parent 3c966ed7
......@@ -9,6 +9,7 @@ module.exports = {
'max-len': ['error', { code: 200 }],
'no-param-reassign': 0,
'no-console': 0,
'no-plusplus': ['off'],
'@typescript-eslint/camelcase': ['off'],
'@typescript-eslint/no-unused-vars': ['off'],
},
......
import React from 'react';
import { Button, Badge } from 'antd';
import styles from './style.less';
import { resetTime } from '../../utils/utils';
export const productType = [
{
......@@ -257,6 +258,36 @@ export const ProcessEditData = (data, row) => {
const orginSpecItem = filterSpecData(data.skuList);
const imageList = filterCarouseList(data.carouseList);
const servesItemParams =
data.productType === 3
? {
serviceItem: {
useTime: [resetTime(serviceItem.useStartTime), resetTime(serviceItem.useEndTime)],
purchaseTime: [
resetTime(serviceItem.purchaseStartTime),
resetTime(serviceItem.purchaseEndTime),
], // 购买开始时间
shopIds: serviceItem.shopIds || [], // 适用门店列表
unavailableDate: serviceItem.unavailableDate, // 不可用日期
useTimeDescription: serviceItem.useTimeDescription, // 使用时间
useMethod: serviceItem.useMethod, // 使用方法
ruleDescription: serviceItem.ruleDescription, // 规则说明
applyScope: serviceItem.applyScope, // 适用范围
tips: serviceItem.tips, // 温馨提示
},
settlementItem: {
settlementMethod: 1,
limitPurchase: Boolean(serviceItem.limitPurchase), // 是否限购1:限购/0:不限购
limitPurchaseType: serviceItem.limitPurchaseType, // 限购类型,如果限购必填1:长期限购/2:周期限购
limitPurchaseCycle: serviceItem.limitPurchaseCycle, // 限购周期1:每天/7:7天/30:30天
limitPurchaseQuantity: serviceItem.limitPurchaseQuantity, // 限购数量
packageContent: serviceItem.packageContent,
appointment: serviceItem.appointment, // 预约
receptionVolume: serviceItem.receptionVolume, // 接待数量
},
}
: {};
const SourceData = {
productType: data.productType,
pageProductType: row.productType,
......@@ -277,14 +308,15 @@ export const ProcessEditData = (data, row) => {
secondSpecId: oneItem.secondSpecId,
secondSpecValue: orginSpecItem.secondSpecValue,
},
infoImageData: {
imageList,
commonImageList: data.commonImageList,
detailImageList: data.detailImageList,
},
skuList: data.skuList,
...servesItemParams,
};
return SourceData;
// data.state = state;
......
......@@ -72,3 +72,9 @@
}
}
}
.pullImage {
position: absolute;
top: 30px;
right: -80px;
}
......@@ -9,6 +9,7 @@ import React, {
} from 'react';
import { ServiceContext } from '../context';
import { CreateFormInput } from './CommonTemplate';
import UUID from '../../../utils/uuid';
const UpdateSkuName = ({ skuVisble, value, confirmEvent, cancelEvent }) => {
const [skuForm] = Form.useForm();
......@@ -92,7 +93,7 @@ const EditableCell = props => {
style={{ margin: 0 }}
hidden={roleHidden}
name={['tableList', rowIndex, dataIndex]}
rules={[{ required: roleRules.required, message: `${title} is required.` }]}
rules={[{ required: roleRules.required, message: `请输入${title}.` }]}
>
{editable ? (
<CreateFormInput
......@@ -223,7 +224,7 @@ const EditFormTable = forwardRef((props, ref) => {
}}
bordered
dataSource={dataSource}
rowKey={(row, rowInd) => (customer.isEdit ? row.id : rowInd)}
rowKey={row => UUID.createUUID()}
columns={columns}
/>
</EditableContext.Provider>
......
......@@ -19,10 +19,12 @@ const FormInformationBasic = forwardRef((props, ref) => {
const { editData, categoryList, brandList, afterAddressList, specListData } = props;
const [form] = Form.useForm();
const [noreBrandList, setNoreBrandList] = useState([]);
const customer = useContext(ServiceContext);
const onCheck = async () => {
try {
const values = await form.validateFields();
values.temp = 'infoMation';
return values;
} catch (errorInfo) {
return null;
......@@ -33,7 +35,6 @@ const FormInformationBasic = forwardRef((props, ref) => {
onCheck,
reset: form.resetFields,
}));
const customer = useContext(ServiceContext);
useEffect(() => {
const noreList = (brandList || []).filter(item => item.name === '虚拟商品');
......@@ -91,6 +92,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
options={categoryList}
/>
</Form.Item>
{!customer.isCard && (
<Form.Item
name="brandId"
label="商品品牌"
......@@ -106,6 +108,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
{CreateSelectOption(customer.productType === 2 ? noreBrandList : brandList)}
</Select>
</Form.Item>
)}
<Popover content={form.getFieldValue('name')} trigger="hover">
<Form.Item
key="name"
......@@ -139,7 +142,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
rules={[{ required: true, message: '请选择售后地址!' }]}
>
<Select showSearch placeholder="请选择商品品牌" filterOption={fileterBrandOptions}>
{afterAddressList.map(item => (
{([{ id: 9527, addressName: '测试地址' }] || afterAddressList).map(item => (
<Select.Option key={item.id} value={item.id}>
{item.addressName}
</Select.Option>
......
......@@ -229,7 +229,8 @@ const FormPriceOrStock = forwardRef((props, ref) => {
const onCheck = async () => {
try {
const values = await form.validateFields();
return values;
const { tableList: items } = await editRef.current.onCheck();
return items ? { ...values, items, temp: 'infoSpecData' } : null;
} catch (errorInfo) {
return null;
}
......@@ -384,7 +385,6 @@ const FormPriceOrStock = forwardRef((props, ref) => {
</div>
<CreateBatchFormItems
batchChange={batchChange}
editRef={editRef}
specInitValue={specInitValue}
defaultColumns={defaultColumns}
/>
......
......@@ -3,6 +3,7 @@ import React, { useState, useEffect, forwardRef, useImperativeHandle, useContext
import moment from 'moment';
import { WeeksList, formItemLayout } from '../config';
import { ServiceContext } from '../context';
import { formatTime } from '../../../utils/utils';
const { Option } = Select;
const { RangePicker } = DatePicker;
......@@ -14,9 +15,6 @@ const WeekCheckBox = () =>
</Checkbox>
));
const formatTime = (time, crm = 'YYYY-MM-DD HH') => time.format(crm);
const resetTime = (time, crm = 'YYYY-MM-DD HH') => moment(time, crm);
const rangeConfig = {
rules: [{ type: 'array', required: true, message: 'Please select time!' }],
};
......@@ -25,30 +23,28 @@ const FormRuleSetting = forwardRef((props, ref) => {
const { editData } = props;
const [form] = Form.useForm();
const customer = useContext(ServiceContext);
const [imageList, setImageList] = useState([]);
const [commonImageList, setCommonImageList] = useState([]);
const [detailImageList, setDetailImageList] = useState([]);
useEffect(() => {
if (customer.isEdit) {
if (!Object.keys(editData).length) return;
setImageList(editData.commonImageList);
setCommonImageList(editData.commonImageList);
setDetailImageList(editData.detailImageList);
const { serviceItem } = editData.skuList[0];
form.setFieldsValue({
useTime: [resetTime(serviceItem.useStartTime), resetTime(serviceItem.useEndTime)],
purchaseTime: [
resetTime(serviceItem.purchaseStartTime),
resetTime(serviceItem.purchaseEndTime),
], // 购买开始时间
shopIds: serviceItem.shopIds || [], // 适用门店列表
unavailableDate: serviceItem.unavailableDate, // 不可用日期
useTimeDescription: serviceItem.useTimeDescription, // 使用时间
useMethod: serviceItem.useMethod, // 使用方法
ruleDescription: serviceItem.ruleDescription, // 规则说明
applyScope: serviceItem.applyScope, // 适用范围
tips: serviceItem.tips, // 温馨提示
});
if (!editData) return;
form.setFieldsValue(editData);
// setImageList(editData.commonImageList);
// setCommonImageList(editData.commonImageList);
// setDetailImageList(editData.detailImageList);
// const { serviceItem } = editData.skuList[0];
// form.setFieldsValue({
// useTime: [resetTime(serviceItem.useStartTime), resetTime(serviceItem.useEndTime)],
// purchaseTime: [
// resetTime(serviceItem.purchaseStartTime),
// resetTime(serviceItem.purchaseEndTime),
// ], // 购买开始时间
// shopIds: serviceItem.shopIds || [], // 适用门店列表
// unavailableDate: serviceItem.unavailableDate, // 不可用日期
// useTimeDescription: serviceItem.useTimeDescription, // 使用时间
// useMethod: serviceItem.useMethod, // 使用方法
// ruleDescription: serviceItem.ruleDescription, // 规则说明
// applyScope: serviceItem.applyScope, // 适用范围
// tips: serviceItem.tips, // 温馨提示
// });
}
}, [customer.isEdit, editData]);
......@@ -61,6 +57,7 @@ const FormRuleSetting = forwardRef((props, ref) => {
purchaseStartTime: formatTime(purchaseTime[0]),
purchaseEndTime: formatTime(purchaseTime[1]),
temp: 'serviceItem',
...values,
};
} catch (errorInfo) {
......@@ -95,10 +92,6 @@ const FormRuleSetting = forwardRef((props, ref) => {
ruleDescription: '', // 规则说明
applyScope: '', // 适用范围
tips: '', // 温馨提示
imageList,
commonImageList,
detailImageList,
}}
scrollToFirstError
>
......
import React, { useState, useEffect, useContext, forwardRef, useImperativeHandle } from 'react';
import { Form } from 'antd';
import { Form, Button } from 'antd';
import { ServiceContext } from '../context';
import { TaskList, formItemLayout } from '../config';
import UploadImage from './UploadImage';
import { formItemLayout } from '../config';
import commonStyle from '../common.less';
const { imgConfig: defaultImgConfig } = TaskList[0];
const FormRuleVPictures = forwardRef((props, ref) => {
const { editData, specKeyItem } = props;
......@@ -10,27 +13,10 @@ const FormRuleVPictures = forwardRef((props, ref) => {
const [imageList, setImageList] = useState({});
const [commonImageList, setCommonImageList] = useState([]);
const [detailImageList, setDetailImageList] = useState([]);
const customer = useContext(ServiceContext);
useEffect(() => {
if (customer.isEdit) {
// if (!Object.keys(editData).length) return;
// setCommonImageList(editData.commonImageList); // 编辑状态下设置公共图
// setDetailImageList(editData.detailImageList); // 编辑状态下设置详情图
// const commImg = editData.skuList.reduce((orgin, item) => {
// const keyString = `${item.firstSpecValue}`; // _${item.firstSpecId}
// if (!Object.keys(orgin).includes(keyString)) {
// orgin[keyString] = item.imageList;
// }
// return orgin;
// }, {});
// setImageList(commImg);
// form.setFieldsValue({
// imageList: commImg,
// commonImageList: editData.commonImageList,
// detailImageList: editData.detailImageList,
// });
if (editData) {
setImageList(editData.imageList);
setCommonImageList(editData.commonImageList); // 编辑状态下设置公共图
......@@ -45,6 +31,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
}, [customer.isEdit, editData]);
useEffect(() => {
if (customer.isCard) return;
if (specKeyItem.length) {
const newImageList = specKeyItem.reduce((origin, item) => {
const showItem = imageList[item] || [];
......@@ -58,7 +45,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
const onCheck = async () => {
try {
const values = await form.validateFields();
console.log(values);
values.temp = 'infoImageData';
return values;
} catch (errorInfo) {
return null;
......@@ -81,11 +68,29 @@ const FormRuleVPictures = forwardRef((props, ref) => {
console.log('Received values of form: ', values);
};
const onPictureSuccessEvent = (imgList, key) => {
setImageList({
...imageList,
[key]: imgList,
const newImgList = { ...imageList, [key]: imgList };
setImageList(newImgList);
form.setFieldsValue({
imageList: newImgList,
});
};
const onCommonSuccessEvent = imgList => {
setCommonImageList(imgList);
form.setFieldsValue({
commonImageList: imgList,
});
};
const onDetailSuccessImageList = imgList => {
setDetailImageList(imgList);
form.setFieldsValue({
detailImageList: imgList,
});
};
const { imgConfig } = TaskList[customer.productType - 1];
return (
<>
<Form
......@@ -105,18 +110,34 @@ const FormRuleVPictures = forwardRef((props, ref) => {
name="commonImageList"
extra={`建议尺寸: ##宽##高 (${commonImageList.length} / 1) `}
rules={[
{ required: true, type: 'array', message: '请输入温馨提示', validateTrigger: 'submit' },
{
required: imgConfig.commonImageList.rule,
type: 'array',
message: '请上传图片!',
validateTrigger: 'submit',
},
{
validator(rule, value, callback) {
if (customer.productType !== 1) callback();
const checkImageList = form.getFieldValue('imageList');
const check = Object.keys(checkImageList).length;
return check > 0 ? callback() : callback('请上传封面图片');
},
validateTrigger: 'submit',
},
]}
>
<UploadImage
disabled={customer.isService}
name="commonImageList"
limit={1}
pictures={commonImageList}
setPictureList={setCommonImageList}
setPictureList={list => onCommonSuccessEvent(list)}
/>
</Form.Item>
{Object.keys(imageList).map(key => (
{!customer.isCard &&
Object.keys(imageList).map(key => (
<Form.Item
key={key}
label={`商品图片(${key})`}
......@@ -124,34 +145,44 @@ const FormRuleVPictures = forwardRef((props, ref) => {
extra={`建议尺寸: ##宽##高 (${imageList[key].length} / 11) `}
rules={[
{
required: true,
required: imgConfig.imageList.rule,
type: 'array',
message: '请输入温馨提示',
message: '请上传图片!',
validateTrigger: 'submit',
},
]}
>
<UploadImage
disabled={customer.isService}
name={key}
limit={11}
pictures={imageList[key]}
setPictureList={list => onPictureSuccessEvent(list, key)}
/>
<Button className={commonStyle.pullImage} type="primary">
拉取公共图
</Button>
</Form.Item>
))}
<Form.Item
label="商品详情图"
name="detailImageList"
extra={`最多上传30张,${detailImageList.length} / 30`}
rules={[
{ required: true, type: 'array', message: '请输入温馨提示', validateTrigger: 'submit' },
{
type: 'array',
required: imgConfig.detailImageList.rule,
message: '请上传商品详情图!',
validateTrigger: 'submit',
},
]}
>
<UploadImage
disabled={customer.isService}
name="detailImageList"
limit={4}
pictures={detailImageList}
setPictureList={setDetailImageList}
setPictureList={list => onDetailSuccessImageList(list)}
/>
</Form.Item>
</Form>
......
......@@ -4,15 +4,30 @@ import { Title } from './CommonTemplate';
import { formItemLayout } from '../config';
import { ServiceContext } from '../context';
const createInitValues = () => ({
settlementMethod: 1,
limitPurchase: null, // 是否限购1:限购/0:不限购
limitPurchaseType: null, // 限购类型,如果限购必填1:长期限购/2:周期限购
limitPurchaseCycle: null, // 限购周期1:每天/7:7天/30:30天
limitPurchaseQuantity: null, // 限购数量
packageContent: '',
appointment: null, // 预约
receptionVolume: null,
});
const FormSettlementOthers = forwardRef((props, ref) => {
const { editData } = props;
const [form] = Form.useForm();
const [initValue, setInitValue] = useState(createInitValues());
const customer = useContext(ServiceContext);
const onCheck = async () => {
try {
const values = await form.validateFields();
return {
...values,
temp: 'settlementItem',
limitPurchase: values.limitPurchase ? 1 : 0,
};
} catch (errorInfo) {
......@@ -20,45 +35,34 @@ const FormSettlementOthers = forwardRef((props, ref) => {
}
};
useImperativeHandle(ref, () => ({
onCheck,
reset: form.resetFields,
}));
const customer = useContext(ServiceContext);
const [initValue, setInitValue] = useState({
settlementMethod: 1,
limitPurchase: null, // 是否限购1:限购/0:不限购
limitPurchaseType: null, // 限购类型,如果限购必填1:长期限购/2:周期限购
limitPurchaseCycle: null, // 限购周期1:每天/7:7天/30:30天
limitPurchaseQuantity: null, // 限购数量
packageContent: '',
appointment: null, // 预约
receptionVolume: null,
});
useEffect(() => {
if (customer.isEdit) {
if (!Object.keys(editData).length) return;
const { serviceItem } = editData.skuList[0];
const data = {
settlementMethod: 1,
limitPurchase: Boolean(serviceItem.limitPurchase), // 是否限购1:限购/0:不限购
limitPurchaseType: serviceItem.limitPurchaseType, // 限购类型,如果限购必填1:长期限购/2:周期限购
limitPurchaseCycle: serviceItem.limitPurchaseCycle, // 限购周期1:每天/7:7天/30:30天
limitPurchaseQuantity: serviceItem.limitPurchaseQuantity, // 限购数量
packageContent: serviceItem.packageContent,
appointment: serviceItem.appointment, // 预约
receptionVolume: serviceItem.receptionVolume, // 接待数量
};
form.setFieldsValue(data);
setInitValue({ ...data });
if (!editData) return;
form.setFieldsValue(editData);
setInitValue({ ...editData });
// const { serviceItem } = editData.skuList[0];
// const data = {
// settlementMethod: 1,
// limitPurchase: Boolean(serviceItem.limitPurchase), // 是否限购1:限购/0:不限购
// limitPurchaseType: serviceItem.limitPurchaseType, // 限购类型,如果限购必填1:长期限购/2:周期限购
// limitPurchaseCycle: serviceItem.limitPurchaseCycle, // 限购周期1:每天/7:7天/30:30天
// limitPurchaseQuantity: serviceItem.limitPurchaseQuantity, // 限购数量
// packageContent: serviceItem.packageContent,
// appointment: serviceItem.appointment, // 预约
// receptionVolume: serviceItem.receptionVolume, // 接待数量
// };
// form.setFieldsValue(data);
// setInitValue({ ...data });
}
}, [customer.isEdit, editData]);
useEffect(() => {}, [form]);
useImperativeHandle(ref, () => ({
onCheck,
reset: () => {
setInitValue(createInitValues());
form.resetFields();
},
}));
const onFinish = values => {
console.log('Received values of form: ', values);
......
......@@ -25,7 +25,9 @@ const uploadButton = (
const UploadImage = props => {
const {
name = `${Date.now()}`,
limit = 1,
limit = null,
multiple = true,
disabled,
uploadParams,
pictures = [],
onChange = () => {},
......@@ -59,7 +61,6 @@ const UploadImage = props => {
const bundleChange = imgFile => {
const imgList = imgFile.map(item => item.url);
setPictureList(imgList);
onChange(imgList);
};
const handleRemove = file => {
......@@ -145,7 +146,7 @@ const UploadImage = props => {
(file, fileArray) =>
// 文件显示
new Promise(async () => {
if (fileListRef.current.length + fileArray.length > limit) {
if (limit && fileListRef.current.length + fileArray.length > limit) {
Modal.warning({
maskClosable: true,
title: '超出上传个数',
......@@ -180,8 +181,9 @@ const UploadImage = props => {
return (
<Spin tip="正在上传..." spinning={uploadLoading} delay={100}>
<Upload
disabled={disabled}
{...uploadParams}
multiple={limit > 1}
multiple={multiple}
name={name}
customRequest={() => {}}
listType="picture-card"
......
......@@ -12,21 +12,61 @@ export const TaskList = [
name: '实体商品',
type: 1,
desc: '物流发货',
imgConfig: {
imageList: {
tip: '(图片最大上传2M)',
rule: false,
limit: null,
},
commonImageList: {
tip: '(图片最大上传2M)',
rule: false,
limit: null,
},
detailImageList: {
tip: '(图片最大上传2M)',
rule: true,
limit: null,
},
},
},
{
name: '虚拟商品',
type: 2,
desc: '无需物流',
imgConfig: {
imageList: {
rule: false,
limit: null,
},
commonImageList: {
rule: false,
limit: false,
},
detailImageList: {
rule: false,
limit: false,
},
},
},
{
name: '电子卡卷',
type: 3,
desc: '无需物流',
imgConfig: {
imageList: {
rule: true,
limit: 1,
},
commonImageList: {
rule: true,
limit: 11,
},
detailImageList: {
rule: true,
limit: 30,
},
},
{
name: '服务类商品',
type: 4,
desc: '无需物流',
},
];
......
......@@ -15,8 +15,9 @@ import {
merchantSpecList,
afterSalesAddrsPage,
merchantgetJdPicList,
merchantProductAdd,
} from './service';
import { isUrl } from './utils';
import { isUrl, filterSendData } from './utils';
import { ServiceContext } from './context';
/**
......@@ -62,23 +63,13 @@ const ServiceGoods = options => {
});
};
// useEffect(() => {
// const timer = setTimeout(() => {
// console.log(checkFormList);
// clearTimeout(timer);
// }, 1000);
// }, [checkFormList, options.visible]);
const productChange = task => {
setProductType(task.type);
changeCheckList(task.type);
};
const submitEvent = async () => {
const checkPromiseList = checkFormList.map(({ current }) => current.onCheck());
const resuslt = await Promise.all(checkPromiseList);
console.log(resuslt);
const timer = setTimeout(() => {
resetForm();
clearTimeout(timer);
}, 1000);
};
// 编辑回显详情数据
......@@ -121,6 +112,31 @@ const ServiceGoods = options => {
}
};
const sendMerchantProductAdd = async sendData => {
const addResponse = await merchantProductAdd(sendData);
console.log(addResponse);
};
const submitEvent = async () => {
const checkPromiseList = checkFormList.map(({ current }) => current.onCheck());
const resuslt = await Promise.all(checkPromiseList);
if (!resuslt.includes(null)) {
const params = resuslt.reduce((origin, item) => {
const { temp, ...other } = item;
origin[temp] = other;
return origin;
}, {});
const sendData = filterSendData(productType, params);
console.log('==============>生成发送数据,===>', sendData);
sendMerchantProductAdd(sendData);
// sendAsyncPost({ ...sendData, type: productType });
console.log();
}
};
const getMerchantgetJdPicList = async params => {
const result = await merchantgetJdPicList(params);
if (result) {
......@@ -249,15 +265,19 @@ const ServiceGoods = options => {
skuList={editData.skuList}
/>
{/* <Title title="规则设置" />
{productType === 3 && <FormRuleSetting ref={settingRef} editData={editData} />} */}
<Title title="规则设置" />
{productType === 3 && (
<FormRuleSetting ref={settingRef} editData={editData.serviceItem} />
)}
<FormRuleVPictures
ref={picturesRef}
specKeyItem={specKeyList}
editData={editData.infoImageData}
/>
{/* {productType === 3 && <FormSettlementOthers ref={settleOtrRef} editData={editData} />} */}
{productType === 3 && (
<FormSettlementOthers ref={settleOtrRef} editData={editData.settlementItem} />
)}
<Button type="primary" onClick={submitEvent}>
Register
</Button>
......
......@@ -66,3 +66,9 @@ export const merchantgetJdPicList = async params => {
});
return data;
};
export const merchantProductAdd = data =>
request.post('/product/api/merchant/add', {
prefix: goodsApi,
data,
});
......@@ -54,6 +54,7 @@ const createSecondProduct = (secondSpecList, initItem, secondSpec, dataSource, c
}
specSecond.secondSpecId = secondSpec;
specSecond.secondSpecValue = secondItem.secondSpecValue;
// specSecond.uuid = UUID.createUUID();
dataSource.push(specSecond);
});
};
......@@ -67,6 +68,7 @@ export const createProductData = ({ firstValues, secondValues, firstSpecId, seco
const specFirst = createInitProduct(fisrtItem, true);
specFirst.firstSpecId = firstSpecId;
specFirst.firstSpecValue = fisrtItem.firstSpecValue;
// specFirst.uuid = UUID.createUUID();
if (secondSpecId && secondValues.length) {
createSecondProduct(secondValues, specFirst, secondSpecId, dataSource, specSecond => {
if (!countRowSpan[specFirst.firstSpecValue]) {
......@@ -126,3 +128,40 @@ export const batchTableSourceData = ({ batchItem, tableData, bacthSecon, bacthFi
return item;
});
};
const filterItems = (type, props) => {
const { infoSpecData, serviceItem, infoImageData, infoMation, settlementItem } = props;
const { imageList = {}, commonImageList } = infoImageData;
return infoSpecData.items.map(item => {
const imgList = imageList[item.firstSpecValue] || [];
item.imageList = imgList.length ? imgList : commonImageList;
item.firstSpecId = infoSpecData.firstSpecId;
item.secondSpecId = infoSpecData.secondSpecId || null;
if (type === 3) {
item.serviceItem = {
...serviceItem,
...settlementItem,
description: infoMation.description || '',
};
}
return item;
});
};
export const filterSendData = (type, params) => {
console.log('===============>生成数据', params);
const { infoMation, infoImageData } = params;
const items = filterItems(type, params);
return {
type,
items,
name: infoMation.name,
brandId: infoMation.brandId || null,
character: infoMation.character,
categoryId: infoMation.categoryId[2],
afterAddressId: infoMation.afterAddressId,
detailImageList: infoImageData.detailImageList,
commonImageList: infoImageData.commonImageList,
};
};
import { parse } from 'querystring';
import pathRegexp from 'path-to-regexp';
import moment from 'moment';
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
......@@ -52,3 +53,6 @@ export function toThousands(data, num) {
}
return result;
}
export const formatTime = (time, crm = 'YYYY-MM-DD HH') => time.format(crm);
export const resetTime = (time, crm = 'YYYY-MM-DD HH') => moment(time, crm);
/**
* [UUID 生成UUID]
*/
class UUID {
constructor() {
this.id = this.createUUID();
}
/**
* [valueOf 重写 valueOf 方法]
* @return {String} [description]
*/
valueOf() {
return this.id;
}
/**
* [valueOf 重写 toString 方法]
* @return {String} [description]
*/
toString() {
return this.id;
}
/**
* [createUUID 创建UUID]
* @return {String} [description]
*/
createUUID() {
const dg = new Date(1582, 10, 15, 0, 0, 0, 0);
const dc = new Date();
const t = dc.getTime() - dg.getTime();
const h = '';
const tl = this.getIntegerBits(t, 0, 31);
const tm = this.getIntegerBits(t, 32, 47);
const thv = `${this.getIntegerBits(t, 48, 59)}1`; // version 1, security version is 2
const csar = this.getIntegerBits(this.rand(4095), 0, 7);
const csl = this.getIntegerBits(this.rand(4095), 0, 7);
const n =
this.getIntegerBits(this.rand(8191), 0, 7) +
this.getIntegerBits(this.rand(8191), 8, 15) +
this.getIntegerBits(this.rand(8191), 0, 7) +
this.getIntegerBits(this.rand(8191), 8, 15) +
this.getIntegerBits(this.rand(8191), 0, 15); // this last number is two octets long
return tl + h + tm + h + thv + h + csar + csl + h + n;
}
/**
* [getIntegerBits description]
* @param {[type]} val [description]
* @param {[type]} start [description]
* @param {[type]} end [description]
* @return {[type]} [description]
*/
getIntegerBits(val, start, end) {
const base16 = this.returnBase(val, 16);
const quadArray = [];
let quadString = '';
let i = 0;
for (i = 0; i < base16.length; i++) {
quadArray.push(base16.substring(i, i + 1));
}
for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
if (!quadArray[i] || quadArray[i] === '') {
quadString += '0';
} else {
quadString += quadArray[i];
}
}
return quadString;
}
/**
* [returnBase description]
* @param {[type]} number [description]
* @param {[type]} base [description]
* @return {[type]} [description]
*/
returnBase(number, base) {
const convert = [
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
];
let output;
if (number < base) {
output = convert[number];
} else {
const MSD = `${Math.floor(number / base)}`;
const LSD = number - MSD * base;
if (MSD >= base) {
output = this.returnBase(MSD, base) + convert[LSD];
} else {
output = convert[MSD] + convert[LSD];
}
}
return output;
}
/**
* [rand description]
* @param {[type]} max [description]
* @return {[type]} [description]
*/
// eslint-disable-next-line class-methods-use-this
rand(max) {
return Math.floor(Math.random() * max);
}
}
export default new UUID();
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