Commit db9068cd by zhangleyuan

feat:修改课程分类的数据的显示

parent 389411ac
...@@ -71,25 +71,28 @@ function CourseCatalogPage() { ...@@ -71,25 +71,28 @@ function CourseCatalogPage() {
categoryId:record.id categoryId:record.id
} }
StoreService.delCourseCategory(param).then((res: any) =>{ StoreService.delCourseCategory(param).then((res: any) =>{
let _courseCatalogList:any = [...courseCatalogList];
if(record.type ==='parent'){ if(record.type ==='parent'){
let _courseCatalogList:any = [...courseCatalogList];
for(let i=0;i<_courseCatalogList.length;i++){ for(let i=0;i<_courseCatalogList.length;i++){
if(_courseCatalogList[i].id === record.id){ if(_courseCatalogList[i].id === record.id){
_courseCatalogList.splice(i,1); _courseCatalogList.splice(i,1);
} }
} }
setCourseCatalogList(_courseCatalogList)
}else{ }else{
for(let i=0;i<_courseCatalogList.length;i++){ let _courseCatalogListClone:any = JSON.parse(JSON.stringify(courseCatalogList));
if(_courseCatalogList[i].child){ for(let i=0;i<_courseCatalogListClone.length;i++){
for(let j=0;j<_courseCatalogList[i].child.length;j++){ if(_courseCatalogListClone[i].child){
if(_courseCatalogList[i].child[j].id === record.id){ for(let j=0;j<_courseCatalogListClone[i].child.length;j++){
_courseCatalogList[i].child.splice(j,1); if(_courseCatalogListClone[i].child[j].id === record.id){
_courseCatalogListClone[i].child.splice(j,1);
} }
} }
} }
} }
setCourseCatalogList(_courseCatalogListClone)
} }
setCourseCatalogList(_courseCatalogList)
message.success("分类已删除"); message.success("分类已删除");
}); });
} }
...@@ -147,8 +150,6 @@ function CourseCatalogPage() { ...@@ -147,8 +150,6 @@ function CourseCatalogPage() {
}); });
} }
function refreshCatalogList(data:any):any{ function refreshCatalogList(data:any):any{
// const _courseCatalogList = [...courseCatalogList];
// setCourseCatalogList(_courseCatalogList)
let _courseCatalogList:any = [...courseCatalogList]; let _courseCatalogList:any = [...courseCatalogList];
const { type} = data; const { type} = data;
switch (type){ switch (type){
...@@ -161,7 +162,6 @@ function CourseCatalogPage() { ...@@ -161,7 +162,6 @@ function CourseCatalogPage() {
type:'parent' type:'parent'
} }
_courseCatalogList.push(item); _courseCatalogList.push(item);
setCourseCatalogList(_courseCatalogList) setCourseCatalogList(_courseCatalogList)
break; break;
case 'editCatalog': case 'editCatalog':
...@@ -179,8 +179,8 @@ function CourseCatalogPage() { ...@@ -179,8 +179,8 @@ function CourseCatalogPage() {
id:data.id, id:data.id,
key:data.id key:data.id
} }
let _courseCatalogList2:any = [...courseCatalogList]; let _courseCatalogListClone:any = JSON.parse(JSON.stringify(courseCatalogList));
_courseCatalogList2.map((item:any,index:any)=>{ _courseCatalogListClone.map((item:any,index:any)=>{
if(item.id === data.parentId){ if(item.id === data.parentId){
if(!item.child){ if(!item.child){
item.child=[]; item.child=[];
...@@ -189,8 +189,28 @@ function CourseCatalogPage() { ...@@ -189,8 +189,28 @@ function CourseCatalogPage() {
} }
return item return item
}); });
setCourseCatalogList(_courseCatalogList2) setCourseCatalogList(_courseCatalogListClone)
console.log("courseCatalogList",courseCatalogList); break;
case 'editSecondCatalog':
const secondEditItem = {
categoryName:data.catalogName,
id:data.id,
key:data.id
}
let _courseCatalogListEditClone:any = JSON.parse(JSON.stringify(courseCatalogList));
_courseCatalogListEditClone.map((item:any,index:any)=>{
if(item.id === data.parentId){
if(item.child){
item.child.map((_item:any,_index:any)=>{
if(_item.id === data.id){
_item.categoryName =data.catalogName;
}
})
}
}
return item
});
break; break;
default: default:
break; break;
...@@ -209,7 +229,6 @@ function CourseCatalogPage() { ...@@ -209,7 +229,6 @@ function CourseCatalogPage() {
} }
function editCatalog(record:any){ function editCatalog(record:any){
if(record.type ==="parent"){ if(record.type ==="parent"){
setCatalogModalType('edit'); setCatalogModalType('edit');
setCatalogModalVisible(true); setCatalogModalVisible(true);
...@@ -254,19 +273,19 @@ function CourseCatalogPage() { ...@@ -254,19 +273,19 @@ function CourseCatalogPage() {
<Table <Table
columns={ parseColumn() } columns={ parseColumn() }
pagination={false} pagination={false}
expandedRowRender={(record:RecordTypes) => { expandedRowRender={(record:RecordTypes) => {
if(!record.child){ if(!record.child){
return return
} }
if (record.child.length !== 0){ if (record.child.length !== 0){
// return <Table columns={parseColumn()} dataSource={record.child} pagination={false} className="child-table"/> console.log("record.child",record.child);
return <div>{ return <Table columns={parseColumn()} dataSource={record.child} pagination={false} className="child-table"/>
record.child.map((item:any,index:any)=>{ // return <div>{
return <span>{item.categoryName}</span> // record.child.map((item:any,index:any)=>{
}) // return <span>{item.categoryName}</span>
} // })
</div> // }
// </div>
}else{ }else{
return <div>还未添加任何子分类</div>; return <div>还未添加任何子分类</div>;
} }
......
...@@ -11,6 +11,7 @@ import React, { useState, useEffect } from "react"; ...@@ -11,6 +11,7 @@ import React, { useState, useEffect } from "react";
import { Modal,Form,Input,Button,Select} from "antd"; import { Modal,Form,Input,Button,Select} from "antd";
import './SecondCatalogAddOrEditModal.less' import './SecondCatalogAddOrEditModal.less'
import User from '@/common/js/user'; import User from '@/common/js/user';
import _ from "underscore";
import StoreService from "@/domains/store-domain/storeService"; import StoreService from "@/domains/store-domain/storeService";
...@@ -24,20 +25,35 @@ interface SecondCatalogAddOrEditModalProps { ...@@ -24,20 +25,35 @@ interface SecondCatalogAddOrEditModalProps {
} }
function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) { function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) {
const {onClose,modalType,parentId,refreshCatalogList} = props; const {onClose,modalType,parentId,refreshCatalogList,choosedItem} = props;
const [secondCatalogName,setSecondCatalogName] = useState(''); const [secondCatalogName,setSecondCatalogName] = useState('');
useEffect(() => { const [selectParentId,setSelectParentId] = useState(parentId);
const [optionList,setOptionList] = useState([]);
const [query, setQuery] = useState({
current: 0,
size: 100,
storeId: User.getStoreId(),
}); });
useEffect(() => {
getOptionList();
},[query]);
function getOptionList():any {
let _query = _.clone(query);
_query.current = query.current + 1;
StoreService.getCourseCatalogList(_query).then((res: any) => {
setOptionList(res.result.records);
});
}
function handleConfirm(){ function handleConfirm(){
if(modalType === "add"){ if(modalType === "add"){
addSecondcatalog(); addSecondcatalog();
}else{
editSecondcatalog();
} }
} }
function addSecondcatalog():any{ function addSecondcatalog():any{
const param = { const param = {
parentId, parentId:selectParentId,
storeId: User.getStoreId(), storeId: User.getStoreId(),
categoryName:secondCatalogName categoryName:secondCatalogName
} }
...@@ -45,13 +61,30 @@ function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) { ...@@ -45,13 +61,30 @@ function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) {
const data = { const data = {
type:'addSecondCatalog', type:'addSecondCatalog',
catalogName:secondCatalogName, catalogName:secondCatalogName,
parentId, parentId:selectParentId,
id:res.result id:res.result
} }
refreshCatalogList(data); refreshCatalogList(data);
onClose(); onClose();
}); });
} }
function editSecondcatalog():any{
const param = {
parentId:selectParentId,
categoryId:choosedItem.id,
categoryName: secondCatalogName,
}
StoreService.editCourseCategory(param).then((res: any) => {
const data = {
type:'editSecondCatalog',
catalogName:secondCatalogName,
id:choosedItem.id,
parentId:selectParentId,
}
refreshCatalogList(data);
onClose();
});
}
return ( return (
<Modal <Modal
visible={true} visible={true}
...@@ -96,10 +129,18 @@ function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) { ...@@ -96,10 +129,18 @@ function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) {
name="所属分类" name="所属分类"
rules={[{ required: true}]} rules={[{ required: true}]}
> >
<Select style={{ width: 240 }}> <Select
<Option value="china">全部</Option> style={{ width: 240 }}
<Option value="usa">一阶培训</Option> defaultValue={parentId}
</Select> onChange={(value) => {
setSelectParentId(String(value))
}}
>
{_.map(optionList, (item:any, index) => {
return <Option id={item.id} value={item.id}>{item.categoryName}</Option>
})}
</Select>
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
......
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