Jelajahi Sumber

Merge branch 'master' of http://192.168.0.115:3000/shaogen1995/qingDao_goods into master

shaogen1995 2 minggu lalu
induk
melakukan
0edc56ad21

+ 4 - 1
src/components/Z3upFilesRef/index.tsx

@@ -256,7 +256,10 @@ function Z3upFilesRef(
         fd.append('dirCode', dirCode)
         fd.append('isCompress', 'true')
         fd.append('isDb', 'true')
-        fd.append('moduleId', moduleId + '')
+        if (moduleId) {
+          fd.append('moduleId', moduleId + '')
+        }
+
         fd.append('file', file)
 
         if (fromData) {

+ 5 - 1
src/components/ZRichTextOne/index.tsx

@@ -79,7 +79,11 @@ function ZRichTextOne(
         fd.append('type', 'img')
         fd.append('dirCode', dirCode)
         fd.append('isCompress', 'true')
-        fd.append('moduleId', moduleId + '')
+        console.log(moduleId)
+        if (moduleId) {
+          fd.append('moduleId', moduleId + '')
+        }
+
         fd.append('file', filesInfo)
 
         e.target.value = ''

+ 21 - 0
src/pages/Eculture/E2story/E2edit/index.module.scss

@@ -42,6 +42,9 @@
         }
         .Edtop1rr {
           width: calc(100% - 100px);
+          .ant-table-cell {
+            padding: 8px !important;
+          }
           & > div {
             width: 100%;
           }
@@ -56,3 +59,21 @@
     }
   }
 }
+
+.EditBtn {
+  position: absolute;
+  bottom: 0;
+  left: 0;
+  width: 100%;
+  height: 60px;
+  display: flex;
+  align-items: center;
+  padding: 0 40px;
+  display: flex;
+  justify-content: space-between;
+  :global {
+    .ant-btn {
+      margin-right: 15px;
+    }
+  }
+}

+ 107 - 23
src/pages/Eculture/E2story/E2edit/index.tsx

@@ -3,59 +3,117 @@ import styles from './index.module.scss'
 import Z3upFilesRef from '@/components/Z3upFilesRef'
 import MyTable from '@/components/MyTable'
 import ZRichTextOne from '@/components/ZRichTextOne'
-import EditBtn from '@/pages/Zother/EditBtn'
-import { E2_APIgetInfo } from '@/store/action/Eculture/E2story'
-import { InfoProvider } from '@/pages/Zother/InfoContext'
+import { MessageFu } from '@/utils/message'
+import { E2_APIgetInfo, E2_APIsave } from '@/store/action/Eculture/E2story'
 import TextArea from 'antd/es/input/TextArea'
 import MyPopconfirm from '@/components/MyPopconfirm'
-import { storyAndGoodsTableC } from '@/utils/tableData'
+import { storyAndGoodsTableC, goodsSonTableC } from '@/utils/tableData'
 import { Button, Input } from 'antd'
-import history from '@/utils/history'
+import history, { backPageFu } from '@/utils/history'
 import { useParams } from 'react-router-dom'
+import { API_getFileListByIds } from '@/store/action/Cledger/C4file'
+import { API_getGoodsList } from '@/store/action/Cledger/C1ledger'
+import SelectGoods from '@/pages/Zother/SelectGoods'
+import { sgBaseFormDataGood, sgTopSelectDomGood } from '@/pages/Zother/SonGoodsList/data'
 
 function E2edit() {
   const [storyInfo, setStoryInfo] = useState({} as any)
-  // const [storyGoodsInfo, setStoryGoodsInfo] = useState([] as any[])
+  const [showSelectGoods, setShowSelectGoods] = useState(false)
   const ZRichTextRef = useRef<any>(null)
   const fileRef = useRef<any>(null)
   const { key, id } = useParams<any>()
-  const isLook = useMemo(() => {
-    return ['3', '4'].includes(key)
+  const isEdit = useMemo(() => {
+    return ['2'].includes(key)
   }, [key])
 
-  // 获取详情
-  const getInfoFu = useCallback(async (id: number) => {
-    const res = await E2_APIgetInfo(id)
+  // 保存附件
+  const getFileListByIdsFu = useCallback(async (ids: string[]) => {
+    const res = await API_getFileListByIds(ids)
     if (res.code === 0) {
-      setStoryInfo(res.data)
-      console.log(res.data)
+      // 设置附件
+      fileRef.current?.sonSetListFu(res.data)
     }
   }, [])
 
+  // 获取详情
+  const getInfoFu = useCallback(
+    async (id: number) => {
+      const res = await E2_APIgetInfo(id)
+      if (res.code === 0) {
+        // 设置数据和富文本和附件
+        setStoryInfo(res.data)
+        ZRichTextRef.current?.ritxtShowFu(res.data.rtf || '')
+        getFileListByIdsFu(res.data.fileIds.split(',') || [])
+        console.log(res.data)
+      }
+    },
+    [getFileListByIdsFu]
+  )
+
+  // 保存或修改
+  const saveFu = useCallback(async () => {
+    if (!storyInfo.name) return MessageFu.warning('请输入故事标题')
+
+    // 获取附件
+    const { list: flieList } = fileRef.current?.sonResListFu()
+
+    // 获取富文本
+    const rtf = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
+    const obj: any = {
+      name: storyInfo.name,
+      remark: storyInfo.remark,
+      goodIds: storyInfo.goods.map((v: any) => v.id).join(','),
+      id: storyInfo.id > 0 ? storyInfo.id : null,
+      fileIds: flieList.map((v: any) => v.id).join(','),
+      rtf: rtf.val
+    }
+    console.log(obj)
+    const res = await E2_APIsave(obj)
+    if (res.code === 0) {
+      backPageFu('-1')
+    }
+  }, [storyInfo])
+
+  // 初始获取详情
   useEffect(() => {
-    getInfoFu(id)
-  }, [getInfoFu, id, key])
+    if (isEdit) {
+      getInfoFu(id)
+    }
+  }, [getInfoFu, id, isEdit, key])
 
-  // 点击各种操作按钮
+  // table点击各种操作按钮
   const tableBtnFu = useCallback((id: number, key: string) => {
     history.push(`/story_edit/${key}/${id}`)
   }, [])
 
+  // 提交
+  const submitFu = useCallback(() => {
+    saveFu()
+  }, [saveFu])
+
   const tableLastBtn = useMemo(() => {
     return [
       {
         title: '操作',
         render: (item: any) => (
           <>
-            <Button size='small' type='text' onClick={() => tableBtnFu(item.id, '4')}>
+            <Button size='small' type='text' onClick={() => console.log('查看藏品')}>
               查看
             </Button>
-            <MyPopconfirm txtK='删除' onConfirm={() => tableBtnFu(item.id, '2')} />
+            <MyPopconfirm
+              txtK='删除'
+              onConfirm={() =>
+                setStoryInfo({
+                  ...storyInfo,
+                  goods: storyInfo.goods.filter((v: any) => v.id !== item.id)
+                })
+              }
+            />
           </>
         )
       }
     ]
-  }, [tableBtnFu])
+  }, [storyInfo])
   return (
     <div className={styles.D1edit} id='editBox'>
       <div className='editMain'>
@@ -74,8 +132,8 @@ function E2edit() {
                 <Input
                   readOnly={false}
                   placeholder='请输入内容,不超过30个字'
-                  value={storyInfo.title || ''}
-                  onChange={e => setStoryInfo({ ...storyInfo, title: e.target.value })}
+                  value={storyInfo.name || ''}
+                  onChange={e => setStoryInfo({ ...storyInfo, name: e.target.value })}
                   maxLength={30}
                   showCount
                 />
@@ -84,6 +142,9 @@ function E2edit() {
             <div className='Edtop1row Edtop1rowFull'>
               <div className='Edtop1ll'>关联产品 :</div>
               <div className='Edtop1rr'>
+                <Button type='primary' onClick={() => setShowSelectGoods(true)}>
+                  添加藏品
+                </Button>
                 <MyTable
                   classKey='storyList'
                   list={storyInfo.goods || []}
@@ -93,11 +154,24 @@ function E2edit() {
                 />
               </div>
             </div>
+            {/* 添加藏品 */}
+            {showSelectGoods && (
+              <SelectGoods
+                myType='藏品'
+                API_getList={API_getGoodsList}
+                closeFu={() => setShowSelectGoods(false)}
+                baseFormData={sgBaseFormDataGood}
+                topSelectDom={sgTopSelectDomGood}
+                columnsTemp={goodsSonTableC(true)}
+                oldCheckArr={storyInfo.goods || []}
+                dataResFu={res => setStoryInfo({ ...storyInfo, goods: res || [] })}
+              />
+            )}
             <div className='Edtop1row Edtop1rowFull'>
               <div className='Edtop1ll'>故事正文 :</div>
               <div className='Edtop1rr'>
                 <ZRichTextOne
-                  moduleId={1}
+                  moduleId={id !== 'null' ? Number(id) : 0}
                   dirCode='guShiText'
                   check={false}
                   myUrl='cms/story/upload'
@@ -123,8 +197,8 @@ function E2edit() {
               <div className='Edtop1ll'>上传附件 :</div>
               <div className='Edtop1rr'>
                 <Z3upFilesRef
+                  moduleId={id !== 'null' ? Number(id) : 0}
                   ref={fileRef}
-                  moduleId={1}
                   dirCode='guShiTextFile'
                   myUrl='cms/story/upload'
                 />
@@ -132,6 +206,16 @@ function E2edit() {
             </div>
           </div>
         </div>
+
+        {/* 操作按钮 */}
+        <div className={styles.EditBtn}>
+          <div>
+            <Button type='primary' onClick={() => submitFu()}>
+              提交
+            </Button>
+            <MyPopconfirm txtK='取消' onConfirm={() => backPageFu('-1')} />
+          </div>
+        </div>
       </div>
     </div>
   )

+ 7 - 0
src/store/action/Cledger/C1ledger.ts

@@ -7,6 +7,13 @@ export const API_getGoodsInfo = (id: number) => {
   return http.get(`cms/good/ledger/detail/${id}`)
 }
 
+/**
+ * 藏品总账-获取藏品列表
+ */
+export const API_getGoodsList = (data: any) => {
+  return http.post(`cms/good/ledger/page`, data)
+}
+
 // ----------------故事模块-----------
 /**
  * 故事-新增

+ 1 - 1
src/utils/tableData.ts

@@ -122,7 +122,7 @@ export const storyTableC = [
 // 故事管理里面的添加藏品
 export const storyAndGoodsTableC = [
   ['txt', '藏品登记号', 'num'],
-  ['txt', '封面', 'thumb'],
+  ['img', '封面', 'thumb'],
   ['txt', '藏品标签', 'tagName'],
   ['txt', '藏品名称', 'name']
 ]