From 334b1a6b105cdd277d290f304498a5f412a7f61e Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Thu, 15 Aug 2024 15:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8E=A8=E5=95=86=E5=93=81=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA=E4=BF=AE=E6=94=B9=E5=8F=8A=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=86=E7=B1=BB=E4=BF=AE=E6=94=B920240815?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.js | 9 +- src/app.jsx | 2 +- src/pages/database/goods/goodsInfo/index.jsx | 4 +- .../goodsattribute/components/CreateForm.jsx | 4 +- .../database/goods/goodsattribute/index.jsx | 2 +- .../goods/goodsattributeprice/index.jsx | 2 +- .../goods/goodsbom/components/CreateBom.jsx | 2 +- .../goodsclassify/components/CreateForm.jsx | 51 ++ .../database/goods/goodsclassify/index.jsx | 329 ++++++++++ .../database/goods/goodsclassify/service.js | 41 ++ .../goods/goodstechnology/components/From.jsx | 2 +- .../components/goodstechnologymaken.jsx | 4 +- .../components/CreateAttribute.jsx | 2 +- .../goodstypemanage/components/CreateForm.jsx | 2 +- .../database/goods/goodstypemanage/service.js | 8 +- .../goods/newgoods/components/ChooseForm.jsx | 56 ++ .../goods/newgoods/components/CreateForm.jsx | 22 +- src/pages/database/goods/newgoods/index.jsx | 560 ++++++------------ src/pages/database/goods/newgoods/service.js | 17 +- src/pages/device/deviceInfo/index.jsx | 22 +- .../deviceVesion/components/CreateForm.jsx | 9 +- src/pages/device/deviceVesion/index.jsx | 10 +- src/pages/device/productmanage/index.jsx | 2 +- .../components/CreateRemarkForm.jsx | 38 ++ src/pages/device/technology/index.jsx | 68 ++- src/pages/device/technology/services.js | 6 + .../components/CreateForm.jsx | 8 +- src/pages/order/orderflow/service.js | 2 +- .../push/goodspush/components/PushFrom.jsx | 2 +- .../technologypush/components/PushFrom.jsx | 2 +- .../foodmenu/components/FoodMenuGoods.jsx | 2 +- 31 files changed, 851 insertions(+), 439 deletions(-) create mode 100644 src/pages/database/goods/goodsclassify/components/CreateForm.jsx create mode 100644 src/pages/database/goods/goodsclassify/index.jsx create mode 100644 src/pages/database/goods/goodsclassify/service.js create mode 100644 src/pages/database/goods/newgoods/components/ChooseForm.jsx create mode 100644 src/pages/device/technology/components/CreateRemarkForm.jsx diff --git a/config/routes.js b/config/routes.js index 1cfbb42..afd3b72 100644 --- a/config/routes.js +++ b/config/routes.js @@ -131,7 +131,14 @@ export default [ path: '/database', routes: [ { - name: '商品类型', + name: '商品分类', + icon: 'smile', + path: '/database/goods/goodsclassify', + component: './database/goods/goodsclassify', + access: 'k7', + }, + { + name: '工艺分类', icon: 'smile', path: '/database/goods/goodstypemanage', component: './database/goods/goodstypemanage', diff --git a/src/app.jsx b/src/app.jsx index 6f6b4f6..3b82f0a 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -230,7 +230,7 @@ export async function getInitialState() { routes:[ { code: 'goods-type', - name: '商品类型', + name: '工艺分类', icon: 'smile', path: '/database/goods/goodstypemanage', component: './database/goods/goodstypemanage', diff --git a/src/pages/database/goods/goodsInfo/index.jsx b/src/pages/database/goods/goodsInfo/index.jsx index e7d645a..1f21f6e 100644 --- a/src/pages/database/goods/goodsInfo/index.jsx +++ b/src/pages/database/goods/goodsInfo/index.jsx @@ -237,7 +237,7 @@ const Advanced = (props) => { - + { onChange={onChange} filterTreeNode={filterOption} value={goodsTypeIdvalue} - placeholder="请选择商品类型" + placeholder="请选择工艺分类" treeDefaultExpandAll /> diff --git a/src/pages/database/goods/goodsattribute/components/CreateForm.jsx b/src/pages/database/goods/goodsattribute/components/CreateForm.jsx index df08eca..4ab8dc1 100644 --- a/src/pages/database/goods/goodsattribute/components/CreateForm.jsx +++ b/src/pages/database/goods/goodsattribute/components/CreateForm.jsx @@ -74,7 +74,7 @@ const headleOk=()=>{ - {/* + {/* { style={{ width: '100%' }} dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} treeData={props.treeDatas} - placeholder="请选择商品类型" + placeholder="请选择工艺分类" treeDefaultExpandAll /> */} diff --git a/src/pages/database/goods/goodsattribute/index.jsx b/src/pages/database/goods/goodsattribute/index.jsx index 3654ca2..c63cbb3 100644 --- a/src/pages/database/goods/goodsattribute/index.jsx +++ b/src/pages/database/goods/goodsattribute/index.jsx @@ -143,7 +143,7 @@ const handleUpdate = async (fields) => { }, // { - // title: '商品类型', + // title: '工艺分类', // dataIndex: 'goodsTypeName', // valueType: 'treeSelect', // fieldProps: { diff --git a/src/pages/database/goods/goodsattributeprice/index.jsx b/src/pages/database/goods/goodsattributeprice/index.jsx index 6404e95..0a42d90 100644 --- a/src/pages/database/goods/goodsattributeprice/index.jsx +++ b/src/pages/database/goods/goodsattributeprice/index.jsx @@ -232,7 +232,7 @@ const onresetsubmit=()=>{ *商品属性 { - goodsAttriburteData==undefined || goodsAttriburteData.length ==0 ? (
当前商品分类还未配置属性点击跳转 当前商品的工艺分类还未配置属性点击跳转 { diff --git a/src/pages/database/goods/goodsbom/components/CreateBom.jsx b/src/pages/database/goods/goodsbom/components/CreateBom.jsx index 07b8048..9554575 100644 --- a/src/pages/database/goods/goodsbom/components/CreateBom.jsx +++ b/src/pages/database/goods/goodsbom/components/CreateBom.jsx @@ -244,7 +244,7 @@ const GoodsbomFrom = (props) => { > *商品属性 { - props.goodsAttriburteData == undefined || props.goodsAttriburteData.length==0 ? (
当前商品分类还未配置属性点击跳转 当前商品的工艺分类还未配置属性点击跳转 { diff --git a/src/pages/database/goods/goodsclassify/components/CreateForm.jsx b/src/pages/database/goods/goodsclassify/components/CreateForm.jsx new file mode 100644 index 0000000..5215024 --- /dev/null +++ b/src/pages/database/goods/goodsclassify/components/CreateForm.jsx @@ -0,0 +1,51 @@ +import React from 'react'; +import { Modal, Form, Input, Button, InputNumber } from 'antd'; + +const CreateForm = (props) => { + + return ( + { + props.onCancel(); + }} + maskClosable={false} + destroyOnClose={true} + > +
+ + + + + + + + + + + + + + +
+
+ ); +}; + +export default CreateForm; \ No newline at end of file diff --git a/src/pages/database/goods/goodsclassify/index.jsx b/src/pages/database/goods/goodsclassify/index.jsx new file mode 100644 index 0000000..51ceabd --- /dev/null +++ b/src/pages/database/goods/goodsclassify/index.jsx @@ -0,0 +1,329 @@ +import { Button, message, Popconfirm, Modal, Transfer } from 'antd'; +import { PlusOutlined } from '@ant-design/icons'; +import CreateForm from './components/CreateForm'; +import React, { useState, useRef, useEffect } from 'react'; +import { PageContainer } from '@ant-design/pro-layout'; +import ProTable from '@ant-design/pro-table'; +import { getGoodsClassifyPage, updateGoodsClassify, deleteGoodsClassify, getgoodslist, getRelation, setRelation } from './service'; + +const GoodsClassify = () => { + const [goodsClassifyVisible, setGoodsClassifyVisible] = useState(false); + const actionRef = useRef(); + const [currentRow, setCurrentRow] = useState(); + const [selectedRowsState, setSelectedRows] = useState([]); + const [targetKeys, setTargetKeys] = useState([]); + const [isModalOpen, setIsModalOpen] = useState(false); + const [mockData, setMockData] = useState([]); + const [classifyId, setClassifyId] = useState([]); + useEffect(() => { + getgoodslist().then((item) => { + var data = item.data; + const tempMockData = []; + data.forEach((item) => { + tempMockData.push({ + key: item.id, + title: item.name, + description: item.name, + }); + }) + setMockData(tempMockData); + }); + }, []); + /** + * 添加节点 + * + * @param fields + */ + const handleAdd = async (fields) => { + const hide = message.loading('正在添加'); + try { + await updateGoodsClassify(JSON.stringify(fields)).then((r) => { + if (r.succeeded) { + message.success('添加成功'); + } else { + message.error(r.errors); + } + }); + hide(); + return true; + } catch (error) { + hide(); + message.error('添加失败请重试!'); + return false; + } + }; + + /** + * 更新节点去 + * + * @param fields + */ + const handleUpdate = async (fields) => { + const hide = message.loading('正在修改'); + try { + await updateGoodsClassify(JSON.stringify(fields)).then((r) => { + if (r.succeeded) { + message.success('修改成功'); + } else { + message.error(r.errors); + } + }); + hide(); + return true; + } catch (error) { + hide(); + message.error('修改失败请重试!'); + return false; + } + }; + const BatchDeletion = () => { + return ( + selectedRowsState?.length > 0 && + ( + + + + )) + } + const onClickdele = () => { + handleRemove(selectedRowsState); + setSelectedRows([]); + actionRef.current?.reloadAndRest?.(); + } + /** + * 批量删除 + * + * @param selectedRows + */ + const handleRemove = async (selectedRows) => { + if (!selectedRows) return true; + await deleteGoodsClassify(selectedRows.map((row) => row.id)).then((r) => { + if (r.succeeded) { + message.success('删除成功'); + actionRef.current.reload(); + } else { + message.error(r.errors); + } + }); + return true; + }; + + const editGoodsClassify = async () => { + const tempMockData = []; + targetKeys.forEach(function (item, index, array) { + tempMockData.push({ + "goodsId": item + }); + }) + var data = { + "classifyId": classifyId, + "goodsIdList": tempMockData + } + setRelation(data).then((r) => { + console.log(r); + if (r.succeeded) { + message.success('编辑成功'); + } else { + message.error(r.errors) + } + }); + setIsModalOpen(false); + actionRef.current.reload(); + }; + + const getGoodsList = async (classifyId) => { + var list = []; + getRelation(classifyId).then((item) => { + item.data.forEach(function (item) { + list.push(item.goodsId); + }) + setTargetKeys(list); + }); + }; + + const handleChange = (newTargetKeys) => { + setTargetKeys(newTargetKeys); + }; + + const columns = [ + { + title: '主键', + dataIndex: 'id', + hideInSearch: true, + hideInTable: true, + tip: '规则名称是唯一的 key', + render: (dom, entity) => { + return ( +
{ + setCurrentRow(entity); + }} + > + {dom} + + ); + }, + }, + { + title: '名称', + dataIndex: 'name', + valueType: 'textarea', + ellipsis: true, + }, + + { + title: '备注', + dataIndex: 'remark', + ellipsis: true, + hideInForm: true, + hideInSearch: true, + }, + { + title: '排序', + dataIndex: 'sort', + hideInSearch: true, + }, + { + title: '操作', + dataIndex: 'option', + valueType: 'option', + render: (_, record) => [ + { + setGoodsClassifyVisible(true); + setCurrentRow(record); + }} + > + 更新 + , + { + await deleteGoodsClassify(record.id).then((r) => { + if (r.succeeded) { + message.success('删除成功'); + actionRef.current.reload(); + } else { + message.error(r.errors); + } + }); + }} + onCancel={() => { }} + > + 删除 + , + { + getGoodsList(record.id); + setClassifyId(record.id); + setIsModalOpen(true); + }} + > + 设置设备商品 + , + ], + }, + ]; + + return ( + + [ + , + + ]} + request={async (params) => { + var goodsClassifyData = []; + var total = 0; + await getGoodsClassifyPage(params).then((r) => { + goodsClassifyData = r.data.data; + total = r.data.total; + }); + return { + data: goodsClassifyData, + success: true, + total: total + }; + }} + columns={columns} + rowSelection={{ + onChange: (_, selectedRows) => { + setSelectedRows(selectedRows); + } + }} + /> + { + var success = false; + if (value.id) { + success = await handleUpdate(value); + } else { + success = await handleAdd(value); + } + if (success) { + setGoodsClassifyVisible(false); + setCurrentRow(undefined); + actionRef.current.reload(); + } + }} + onCancel={() => { + setGoodsClassifyVisible(false); + setCurrentRow(undefined); + }} + goodsClassifyVisible={goodsClassifyVisible} + values={currentRow || {}} + /> + { editGoodsClassify() }} + onCancel={() => { setIsModalOpen(false) }}> + { }} + render={(item) => item.title} + /> + + + ); +} +export default GoodsClassify; \ No newline at end of file diff --git a/src/pages/database/goods/goodsclassify/service.js b/src/pages/database/goods/goodsclassify/service.js new file mode 100644 index 0000000..b6fdd4b --- /dev/null +++ b/src/pages/database/goods/goodsclassify/service.js @@ -0,0 +1,41 @@ +import { request } from 'umi'; +import { getDataBaseUrl } from '@/global_data'; + +export async function getGoodsClassifyPage(data) { + return request(getDataBaseUrl() + `/api/goodsClassify/getGoodsClassifyPage`, { + method: 'POST', + data: data + }); +} + +export async function updateGoodsClassify(data) { + return request(getDataBaseUrl() + `/api/goodsClassify/updateGoodsClassify`, { + method: 'POST', + data: data + }); +} + +export async function deleteGoodsClassify(data) { + return request(getDataBaseUrl() + `/api/goodsClassify/deleteGoodsClassify?ids=${data}`, { + method: 'Get' + }); +} + +export async function getgoodslist() { + return request(getDataBaseUrl() + `/api/goods/getgoodslist`, { + method: 'Get', + }); +} + +export async function getRelation(classifyId) { + return request(getDataBaseUrl() + `/api/goodsClassify/getRelation?classifyId=${classifyId}`, { + method: 'Get', + }); +} + +export async function setRelation(data) { + return request(getDataBaseUrl() + `/api/goodsClassify/setRelation`, { + method: 'POST', + data: data + }); +} diff --git a/src/pages/database/goods/goodstechnology/components/From.jsx b/src/pages/database/goods/goodstechnology/components/From.jsx index 55786da..e550e55 100644 --- a/src/pages/database/goods/goodstechnology/components/From.jsx +++ b/src/pages/database/goods/goodstechnology/components/From.jsx @@ -81,7 +81,7 @@ const From = (props) => { { props.propsdata.length > 0 ? props.propsdata.map((x, index) => { - let value=props.optiondata.find(p=>p.id==x.technologyactionId && p.actionName==x.actionName).actionValue; + let value=props.optiondata.find(p=>p.id==x.technologyactionId && p.actionName==x.actionName)?.actionValue; if (x.actionType == "text") { return <>
diff --git a/src/pages/database/goods/goodstechnology/components/goodstechnologymaken.jsx b/src/pages/database/goods/goodstechnology/components/goodstechnologymaken.jsx index c657894..922b096 100644 --- a/src/pages/database/goods/goodstechnology/components/goodstechnologymaken.jsx +++ b/src/pages/database/goods/goodstechnology/components/goodstechnologymaken.jsx @@ -116,7 +116,7 @@ const goodstechnologymaken = (props) => { // {key:'1',label:'',children:(
)}, { key: '1', label: '商品名称', children: res.data.name }, { key: '2', label: '商品价格', children: res.data.price }, - { key: '3', label: '商品类型', children: res.data.goodsTypeName }, + { key: '3', label: '工艺分类', children: res.data.goodsTypeName }, { key: '4', label: '商品单位', children: res.data.goodsUintName }, ] setItems(it) @@ -618,7 +618,7 @@ const goodstechnologymaken = (props) => {
商品属性
{ - goodsinfo.goodsAttributeList == undefined || goodsinfo.goodsAttributeList == "" ? (
当前商品分类还未配置属性点击跳转 当前商品的工艺分类还未配置属性点击跳转 { diff --git a/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx b/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx index b53e670..5d28ccb 100644 --- a/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx +++ b/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx @@ -136,7 +136,7 @@ const handleUpdate = async (fields) => { }, // { - // title: '商品类型', + // title: '工艺分类', // dataIndex: 'goodsTypeName', // valueType: 'treeSelect', // fieldProps: { diff --git a/src/pages/database/goods/goodstypemanage/components/CreateForm.jsx b/src/pages/database/goods/goodstypemanage/components/CreateForm.jsx index 8b9d197..8ceafd6 100644 --- a/src/pages/database/goods/goodstypemanage/components/CreateForm.jsx +++ b/src/pages/database/goods/goodstypemanage/components/CreateForm.jsx @@ -38,7 +38,7 @@ const CreateForm = (props) => { treeDefaultExpandAll /> - + diff --git a/src/pages/database/goods/goodstypemanage/service.js b/src/pages/database/goods/goodstypemanage/service.js index bea3c6f..ea518ca 100644 --- a/src/pages/database/goods/goodstypemanage/service.js +++ b/src/pages/database/goods/goodstypemanage/service.js @@ -3,7 +3,7 @@ /* eslint-disable */ import { request } from 'umi'; import { getDataBaseUrl } from '@/global_data'; -/** 获取商品类型 sdsa GET /kitchen/api/rule */ +/** 获取工艺分类 sdsa GET /kitchen/api/rule */ export async function goodsType(data) { return request(getDataBaseUrl()+`/api/goodstype/page`, { method: 'POST', @@ -12,7 +12,7 @@ export async function goodsType(data) { // ...(options || {}), }); } -/** 新建商品类型 POST /kitchen/api/rule */ +/** 新建工艺分类 POST /kitchen/api/rule */ export async function GetDicList(TypeCode) { return request(getDataBaseUrl()+`/api/dict-data/dic-list/${TypeCode}`, { method: 'Get', @@ -29,7 +29,7 @@ export async function addGoodsType(data) { }); } -/** 更新商品类型 PUT /kitchen/api/rule */ +/** 更新工艺分类 PUT /kitchen/api/rule */ export async function updateGoodsType(data) { return request(getDataBaseUrl()+'/api/goodstype/update', { @@ -39,7 +39,7 @@ export async function updateGoodsType(data) { }); } -/** 删除商品类型 DELETE /kitchen/api/rule */ +/** 删除工艺分类 DELETE /kitchen/api/rule */ export async function DeleteGoodsType(data) { return request(getDataBaseUrl()+`/api/goodstype/delete?id=${data}`, { diff --git a/src/pages/database/goods/newgoods/components/ChooseForm.jsx b/src/pages/database/goods/newgoods/components/ChooseForm.jsx new file mode 100644 index 0000000..e886f45 --- /dev/null +++ b/src/pages/database/goods/newgoods/components/ChooseForm.jsx @@ -0,0 +1,56 @@ +import React, { useRef, useState, useEffect } from 'react'; +import { message, Modal, Form, Input, Button, Upload, Select, InputNumber, TreeSelect, Switch, Divider, Space } from 'antd'; +import { } from '../service'; + +const ChooseForm = (props) => { + const inputRef = useRef(); + + return ( + +
+ {Array.isArray(props.values) && props.values.map((t, index) => ( +
+
+ + {t.goodsName} + +
+
+ + + +
+
+ ))} + + + + +
+
+ ); +}; + + +export default ChooseForm; \ No newline at end of file diff --git a/src/pages/database/goods/newgoods/components/CreateForm.jsx b/src/pages/database/goods/newgoods/components/CreateForm.jsx index ec0fb1f..df951aa 100644 --- a/src/pages/database/goods/newgoods/components/CreateForm.jsx +++ b/src/pages/database/goods/newgoods/components/CreateForm.jsx @@ -9,17 +9,14 @@ const CreateForm = (props) => { const [goodsTypeIdvalue, setgoodsTypeIdvalue] = useState(); const inputRef = useRef(); const [unitname, setunitname] = useState(''); - const [url, setUrl] = useState(props.values ? props.values.imgUrl : null); + const [url, setUrl] = useState(null); const [hovered, setHovered] = useState(false); const [imageError, setImageError] = useState(false); useEffect(() => { initGoodsUnit(); initGoodsType(); - if (props.values) { - setUrl(props.values.imgUrl); - } else { - setUrl(null); - } + props.form.setFieldsValue(props.values); + setUrl(props.values.imgUrl); }, [props.values]) function initGoodsUnit() { unitList().then((r) => { @@ -29,7 +26,6 @@ const CreateForm = (props) => { list.push({ text: item.name, value: item.id, label: item.name }); }); } - console.log("list", list) setGoodsUnit(list); }); } @@ -94,8 +90,10 @@ const CreateForm = (props) => { } }; const handleDeleteImage = () => { + props.values.imgUrl = null; setUrl(null); - }; + props.form.setFieldsValue({ imgUrl: props.values.imgUrl }); + }; const handleImageError = () => { setImageError(true); }; @@ -116,12 +114,12 @@ const CreateForm = (props) => { labelCol={{ span: 4 }} layout="horizontal" preserve={false} - initialValues={props.values} + form={props.form} onFinish={props.onFinish}> - + { onChange={onChange} filterTreeNode={filterOption} value={goodsTypeIdvalue} - placeholder="请选择商品类型" + placeholder="请选择工艺分类" treeDefaultExpandAll /> @@ -169,7 +167,7 @@ const CreateForm = (props) => { )} /> - + diff --git a/src/pages/database/goods/newgoods/index.jsx b/src/pages/database/goods/newgoods/index.jsx index 1de3f50..9b233c4 100644 --- a/src/pages/database/goods/newgoods/index.jsx +++ b/src/pages/database/goods/newgoods/index.jsx @@ -1,14 +1,15 @@ import { PlusOutlined, UploadOutlined, QuestionCircleOutlined, DownloadOutlined } from '@ant-design/icons'; -import { Button, message, Input, Drawer, Popconfirm, Upload, Spin, Tooltip, Modal, Select } from 'antd'; +import { Button, message, Input, Drawer, Popconfirm, Upload, Spin, Tooltip, Modal, Select, Form } from 'antd'; import React, { useState, useRef, useEffect } from 'react'; import { PageContainer } from '@ant-design/pro-layout'; import ProTable from '@ant-design/pro-table'; import ProDescriptions from '@ant-design/pro-descriptions'; import { history } from 'umi'; import CreateForm from './components/CreateForm'; +import ChooseForm from './components/ChooseForm'; import { getDataBaseUrl } from '@/global_data'; -import { gettree, goods, removeGoods, addGoods, updateGoods, GetDeviceTechnology, TechnologyTemplateExport, GoodsTechnologyExport, GetgoodsWithIds, Getgoodslist, GoodsSimpleExport } from './service'; -import { getdevicegoods } from '../../../device/deviceInfo/services' +import { gettree, goods, removeGoods, addGoods, updateGoods, GetDeviceTechnology, GetgoodsWithIds, Getgoodslist, GoodsExport } from './service'; +import axios from 'axios'; const aliyunHostUrl = 'https://bpa.oss-cn-chengdu.aliyuncs.com/hkerp/test/goods/'; @@ -17,29 +18,30 @@ const GoodsManage = () => { /** 新建/更新窗口的弹窗 */ const [createModalVisible, handleModalVisible] = useState(false); /** 分布更新窗口的弹窗 */ - + const [form] = Form.useForm(); const [showDetail, setShowDetail] = useState(false); + //表单 + const myformRef = useRef(); + //列表 const actionRef = useRef(); const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); - const [treeData, setTreeData] = useState(); + const [treeData, setTreeData] = useState([]); const [loading, setLoading] = useState(false); - const [isModalOpen, setIsModalOpen] = useState(false); const [deviceData, setDeviceData] = useState([]); - const [goodData, setGoodData] = useState([]); - const [deviceGoodData, setDeviceGoodData] = useState([]); const [deviceId, setDeviceId] = useState(''); const [deviceName, setDeviceName] = useState(''); const [goodsId, setGoodsId] = useState([]); - const [isDataModalOpen, setIsDataModalOpen] = useState(false); - const [ids, setIds] =useState(''); + const [importFile, setImportFile] = useState(); + const [showChooseForm, setShowChooseForm] = useState(false); + const [chooseFormData, setChooseFormData] = useState([]); /** 国际化配置 */ useEffect(() => { gettree().then((r) => { setTreeData(r.data); }); + initGetDeviceTechnology(); - initGetgoodslist(); }, []); const initGetDeviceTechnology = () =>{ @@ -57,46 +59,6 @@ const GoodsManage = () => { } }); } - const initGetgoodslist = () =>{ - Getgoodslist().then((r)=>{ - var arr = r.data; - if (r.succeeded) { - var list = []; - arr.forEach((item) => { - list.push({ - value: item.id, - label: item.name - }); - }); - setGoodData(list); - } - }); - } - const initGetdevicegoodsList = async (deviceId) => { - getdevicegoods(deviceId).then((r) => { - var arr = r.data; - if (r.succeeded) { - var idList = []; - arr.forEach((item) => { - idList.push(item.goodsId); - }); - setIds(idList); - GetgoodsWithIds(idList).then((t) => { - var a = t.data; - if (t.succeeded) { - var list = []; - a.forEach((i) => { - list.push({ - value: i.id, - label: i.name - }) - }) - setDeviceGoodData(list); - } - }) - } - }); - }; /** * 添加节点 @@ -104,7 +66,7 @@ const GoodsManage = () => { * @param fields */ const handleAdd = async (fields) => { - fields.createBy = 'admin'; + fields.price = fields.price ? fields.price : 0; fields.isAttrubute = true; fields.ImgUrl = fields.imgUrl1 ? aliyunHostUrl + fields.imgUrl1.file.name : null; await addGoods(JSON.stringify(fields)).then((r) => { @@ -130,10 +92,10 @@ const GoodsManage = () => { goodsTypeId: fields.goodsTypeId, name: fields.name, goodsUintId: fields.goodsUintId, - price: fields.price, + price: fields.price ? fields.price : 0, isWeigh: fields.isWeigh, descritption: fields.descritption, - imgUrl: fields.imgUrl1 ? aliyunHostUrl + fields.imgUrl1.file.name : null + imgUrl: fields.imgUrl1 ? aliyunHostUrl + fields.imgUrl1.file.name : fields.imgUrl }).then((r) => { if (r.succeeded) { message.success('修改成功'); @@ -208,15 +170,36 @@ const GoodsManage = () => { renderText: (val) => `${val}¥`, hideInSearch: true, }, - { - title: '商品类型', + title: '设备', + dataIndex: 'deviceId', + valueType: 'treeSelect', + hideInTable: true, + fieldProps: { + showSearch:true, + allowClear:true, + options: deviceData, + treeNodeFilterProp: 'label', + onChange: (val, row) => { + setDeviceId(val) + setDeviceName(row[0]) + myformRef.current.submit() + } + }, + }, + { + title: '工艺分类', dataIndex: 'goodsTypeName', valueType: 'treeSelect', fieldProps: { showSearch:true, allowClear:true, - options: treeData + fieldNames: { + children: 'children', + label: 'title', + }, + options: treeData, + treeNodeFilterProp: 'title', }, }, { @@ -286,23 +269,32 @@ const GoodsManage = () => { > 工艺配置
, - { - history.push({ - pathname: '/database/goods/goodsattributeprice', - query: { - isAdd: false, - values: record, - }, - }); - // handleModalVisible(true); - // setCurrentRow(record); - }} - > - 价格配置 - + // { + // history.push({ + // pathname: '/database/goods/goodsattributeprice', + // query: { + // isAdd: false, + // values: record, + // }, + // }); + // // handleModalVisible(true); + // // setCurrentRow(record); + // }} + // > + // 价格配置 + // + { + handleDownload(record.id) + }} + > + 下载商品 + , { }, ]; + const importMessage = (json) =>{ + const formDataAll = new FormData(); + formDataAll.append('file', importFile); + formDataAll.append('json', json); + formDataAll.append('deviceId', deviceId); + const headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + localStorage.getItem('token') + }; + axios.post(getDataBaseUrl() + '/api/goods/goodsImport', formDataAll, { headers }).then(r => { + if(r.data.succeeded == true){ + message.success("导入成功"); + actionRef.current.reload(); + }else{ + message.error(r.data.errors); + } + }).catch(error => { + message.error(error); + }); + } + /** * 删除节点 * @@ -345,182 +358,95 @@ const GoodsManage = () => { }); return true; }; - const props = { + const importProps = { beforeUpload: (file) => { - setLoading(true); - if ( - file.type !== 'application/vnd.ms-excel' && - file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' - ) { - message.error(`${file.name} 不是 exelce 文件`); - } - return file.type == 'application/vnd.ms-excel' || - file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' - ? true - : Upload.LIST_IGNORE; - }, - name: 'file', - action: getDataBaseUrl()+'/api/goods/GoodsImport', - headers: { - // authorization: 'authorization-text', - Authorization: 'Bearer ' + localStorage.getItem('token') - }, - onChange(info) { - if (info.file.status !== 'uploading') { - console.log(info.file, info.fileList); + setImportFile(file); + if (deviceName == '' || deviceId == undefined) { + message.error('请选择一个设备!'); + return Upload.LIST_IGNORE; } - if (info.file.status === 'done') { - setLoading(false); - message.success(`${info.file.name}导入成功`); - actionRef.current.reload(); - } else if (info.file.status === 'error') { - setLoading(false); - message.error(`${info.file.name}:${info.file.response} `); - } - } - }; - const technologprops = { - beforeUpload: (file) => { if ( file.type !== 'application/vnd.ms-excel' && - file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' && + file.type !== 'application/x-zip-compressed' ) { - message.error(`${file.name} 不是 exelce 文件`); + message.error(`${file.name} 不是excel或zip文件`); } return file.type == 'application/vnd.ms-excel' || - file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || + file.type == 'application/x-zip-compressed' ? true : Upload.LIST_IGNORE; }, name: 'file', - action: getDataBaseUrl() + '/api/goods/goodsTechnologyImport', + action: getDataBaseUrl() + '/api/goods/getFileToChoose', headers: { - // authorization: 'authorization-text', Authorization: 'Bearer ' + localStorage.getItem('token') }, onChange(info) { setLoading(true); - if (info.file.status !== 'uploading') { - console.log(info.file, info.fileList); - } if (info.file.status === 'done') { setLoading(false); - message.success(`${info.file.name}导入成功`); - actionRef.current.reload(); - } else if (info.file.status === 'error') { - setLoading(false); - message.error(`${info.file.name}:${info.file.response} `); + if(info.file.response.data.length > 0){ + setChooseFormData(info.file.response.data); + setShowChooseForm(true); + } + else{ + importMessage([]); + myformRef.current.submit() + } } + // setLoading(true); + // if (info.file.status !== 'uploading') { + // console.log(info.file, info.fileList); + // } + // if (info.file.status === 'done') { + // setLoading(false); + // message.success(`${info.file.name}导入成功`); + // actionRef.current.reload(); + // } else if (info.file.status === 'error') { + // setLoading(false); + // message.error(`${info.file.name}:${info.file.response} `); + // } } }; - const handleDataDeviceChange = (value, option) => { - setDeviceId(option?.value); - setDeviceName(option?.label); - initGetdevicegoodsList(option?.value); - } - const handleDeviceChange = (value, option) => { - setDeviceId(option?.value); - setDeviceName(option?.label); - } - const handleGoodChange = (value, option) => { - setGoodsId(value); - } - const handleDataDownload = async()=>{ - if(deviceName == '') - { - message.error('请选择一个设备!'); - return; - } - if(goodsId == '') - { - message.error('请选择至少一个商品!'); - return; - } - const base64String = await GoodsSimpleExport({ goodsId: goodsId, deviceId: deviceId, ids: ids }); - // 解码 Base64 数据 - const binaryString = atob(base64String); - // 转换为 Uint8Array - const bytes = new Uint8Array(binaryString.length); - for (let i = 0; i < binaryString.length; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - // 创建 Blob 对象 - const blob = new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); - // 创建一个临时的 URL,指向 Blob 对象 - const url = window.URL.createObjectURL(blob); - // 创建 元素,用于下载文件 - const link = document.createElement('a'); - const fileName = "商品.xlsx"; - link.href = url; - link.setAttribute('download', fileName); - // 将 元素添加到页面中 - document.body.appendChild(link); - // 模拟用户点击下载链接,触发文件下载 - link.click(); - // 下载完成后,移除 元素 - document.body.removeChild(link); - setDeviceId(''); - setDeviceName(''); - setGoodsId([]); - setIds(''); - setIsDataModalOpen(false); - } - const handleDownload = async () => { - if(deviceName == '') - { + const handleDownload = async (goodId) => { + if (deviceName == '' || deviceId == undefined) { message.error('请选择一个设备!'); return; } - try { - // 第一次下载操作 - const r = await TechnologyTemplateExport(deviceId); - if (!r) { - message.error('未能获取第一个文件下载链接'); - return; - } - const fileName1 = r.substring(r.lastIndexOf('/') + 1); - const link1 = document.createElement('a'); - link1.href = r; - link1.setAttribute('download', fileName1); - document.body.appendChild(link1); - link1.click(); - document.body.removeChild(link1); - // 第二次下载操作 - const base64String = await GoodsTechnologyExport({ goodsId: goodsId, deviceId: deviceId, fileName: fileName1 }); - if (!base64String) { - message.error('未能获取第二个文件Base64数据'); - return; - } - // 解码 Base64 数据 - const binaryString = atob(base64String); - // 转换为 Uint8Array - const bytes = new Uint8Array(binaryString.length); - for (let i = 0; i < binaryString.length; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - // 创建 Blob 对象 - const blob = new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); - // 创建一个临时的 URL,指向 Blob 对象 - const url = window.URL.createObjectURL(blob); - // 创建第二个 元素,用于下载第二个文件 - const link2 = document.createElement('a'); - const fileName2 = "商品.xlsx"; - link2.href = url; - link2.setAttribute('download', fileName2); - // 将第二个 元素添加到页面中 - document.body.appendChild(link2); - // 模拟用户点击下载链接,触发第二个文件下载 - link2.click(); - // 下载完成后,移除第二个 元素 - document.body.removeChild(link2); - setDeviceId(''); - setDeviceName(''); - setGoodsId([]); - setIsModalOpen(false); - } catch (error) { - message.error('下载过程中发生错误:', error); - } + await GoodsExport({ goodId: goodId, deviceId: deviceId, goodsId: goodsId }).then((r) => { + if (r.succeeded) { + const base64String = r.data; + // 解码 Base64 数据 + const binaryString = atob(base64String); + // 转换为 Uint8Array + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + // 创建 Blob 对象 + const blob = new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); + // 创建一个临时的 URL,指向 Blob 对象 + const url = window.URL.createObjectURL(blob); + // 创建 元素,用于下载文件 + const link = document.createElement('a'); + const fileName = "商品.zip"; + link.href = url; + link.setAttribute('download', fileName); + // 将 元素添加到页面中 + document.body.appendChild(link); + // 模拟用户点击下载链接,触发文件下载 + link.click(); + // 下载完成后,移除 元素 + document.body.removeChild(link); + message.success("下载成功"); + }else{ + message.error(r.errors); + } + }) } + return ( { { , , - - + + , - , - - - , - , ]} request={async (params) => { var goodsData = []; + var goodsIds = []; if (params.goodsTypeId != undefined) { params.goodsTypeId = goodsTypes[params.goodsTypeId].goodsTypeId; } var total = 0; await goods(params).then((r) => { goodsData = r.data.data; - console.log(goodsData) goodsData.forEach((x) => { + goodsIds.push(x.id); if (x.defaultMate != null) { x.defaultMate = x.defaultMate.split(","); } - }); - console.log(goodsData) total = r.data.total; }); + setGoodsId(goodsIds); return { data: goodsData, success: true, total: total, }; + }} columns={columns} rowSelection={{ @@ -644,125 +547,34 @@ const GoodsManage = () => { }} createModalVisible={createModalVisible} values={currentRow || {}} + form={form} /> - { - setDeviceId('') - setDeviceName('') - setIsModalOpen(false) - }}> -
- *选择设备: - (option?.label ?? '').includes(input)} - filterSort={(optionA, optionB) => - (optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase()) - } - onChange={async (value, option) => { handleGoodChange(value, option) }} - options={goodData} - /> -
- -
- { + const transformedData = Object.entries(data).map(([key, value]) => ({ + key, + value + })); + var list = []; + transformedData.forEach((item) => { + list.push({ + key: item.key, + value: item.value == true ? true : false + }); + }); + importMessage(JSON.stringify(list)); + setShowChooseForm(false); + setChooseFormData(undefined); + myformRef.current.submit() + }} onCancel={() => { - setDeviceGoodData([]) - setDeviceId('') - setDeviceName('') - setGoodsId([]) - setIds('') - setIsDataModalOpen(false) - }}> -
- *选择设备: - (option?.label ?? '').includes(input)} - filterSort={(optionA, optionB) => - (optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase()) - } - onChange={async (value, option) => { handleGoodChange(value, option) }} - options={deviceGoodData} - /> -
- -
+ setShowChooseForm(false); + setChooseFormData(undefined); + }} + showChooseForm={showChooseForm} + values={chooseFormData || {}} + form={form} + /> { dataIndex: 'option', valueType: 'option', fixed: 'right', - width: 400, + width: 300, render: (_, record) => [
{ 导出工艺模版 , - { - GetdevicegoodsList(record.id); - setCurrentRow(record); - setIsModalOpen(true); - }} - > - 设置设备商品 - , + // { + // GetdevicegoodsList(record.id); + // setCurrentRow(record); + // setIsModalOpen(true); + // }} + // > + // 设置设备商品 + // , ], }, diff --git a/src/pages/device/deviceVesion/components/CreateForm.jsx b/src/pages/device/deviceVesion/components/CreateForm.jsx index b161587..b3b7001 100644 --- a/src/pages/device/deviceVesion/components/CreateForm.jsx +++ b/src/pages/device/deviceVesion/components/CreateForm.jsx @@ -2,11 +2,10 @@ import React, { useRef, useState, useEffect } from 'react'; import { Modal, Form, Input, Button, Select, Upload, InputNumber, message } from 'antd'; import { PlusOutlined, UploadOutlined, DeleteOutlined } from '@ant-design/icons'; import { GetAliyunRequestURL } from '../services'; -import $ from 'jquery'; const CreateForm = (props) => { const [modalVisible, setModalVisible] = useState(false); const [modalContent, setModalContent] = useState(''); - const [url, setUrl] = useState(props.values ? props.values.productUrl : null); + const [url, setUrl] = useState(null); const [hovered, setHovered] = useState(false); const [imageError, setImageError] = useState(false); const uploadProp = { @@ -53,7 +52,9 @@ const CreateForm = (props) => { props.onCancel(); }; const handleDeleteImage = () => { + props.values.productUrl = null; setUrl(null); + props.form.setFieldsValue({ productUrl: props.values.productUrl }); }; const handleImageError = () => { setImageError(true); @@ -73,7 +74,6 @@ const CreateForm = (props) => { layout="vertical" preserve={false} form={props.form} - // initialValues={props.values} onFinish={props.onFinish} > + + { valueType: 'textarea', }, { - title: '商品类型', + title: '工艺分类', dataIndex: 'goodsTypeName', valueType: 'treeSelect', fieldProps: { diff --git a/src/pages/push/technologypush/components/PushFrom.jsx b/src/pages/push/technologypush/components/PushFrom.jsx index 767ee8d..a2cddbc 100644 --- a/src/pages/push/technologypush/components/PushFrom.jsx +++ b/src/pages/push/technologypush/components/PushFrom.jsx @@ -88,7 +88,7 @@ const handleStopChange=(value)=>{ valueType: 'textarea', }, { - title: '商品类型', + title: '工艺分类', dataIndex: 'goodsTypeName', valueType: 'treeSelect', fieldProps: { diff --git a/src/pages/scene/foodmenu/components/FoodMenuGoods.jsx b/src/pages/scene/foodmenu/components/FoodMenuGoods.jsx index 233d46e..f2b7034 100644 --- a/src/pages/scene/foodmenu/components/FoodMenuGoods.jsx +++ b/src/pages/scene/foodmenu/components/FoodMenuGoods.jsx @@ -37,7 +37,7 @@ const FoodMenuGoods = (props) => { tip: '规则名称是唯一的 key', }, { - title: '商品类型', + title: '工艺分类', dataIndex: 'goodsTypeName', valueType: 'treeSelect', hideInTable: true,