Browse Source

改一波东哥需求

shaogen1995 2 tháng trước cách đây
mục cha
commit
b02286020b

+ 1 - 1
src/pages/C_goodsManage/C1register/C1look/index.tsx

@@ -196,7 +196,7 @@ function C1look() {
         {info.id ? (
           <div className='Y1info'>
             {goodType === '藏品信息' ? <Y11com info={info} /> : null}
-            {goodType === '藏品附件' ? <Y33com sId={info.id} /> : null}
+            {goodType === '藏品附件' ? <Y33com sId={info.id} info={info} /> : null}
           </div>
         ) : null}
 

+ 1 - 1
src/pages/Y_goodsDetails/Y1cathet/Y1main.tsx

@@ -49,7 +49,7 @@ function Y1main({ sId }: Props) {
         <div className='Y1info'>
           {tabAc === '藏品信息' ? <Y11com info={info} /> : null}
           {tabAc === '库存信息' ? <Y22com info={info} /> : null}
-          {tabAc === '藏品附件' ? <Y33com sId={sId} /> : null}
+          {tabAc === '藏品附件' ? <Y33com sId={sId} info={info} /> : null}
           {tabAc === '藏品日志' ? <Y44com sId={sId} /> : null}
         </div>
       ) : null}

+ 94 - 47
src/pages/Y_goodsDetails/Y1cathet/Y33com.tsx

@@ -14,13 +14,17 @@ import { MessageFu } from '@/utils/message'
 import { useSelector } from 'react-redux'
 import { RootState } from '@/store'
 import { GoodFileType } from '@/components/Z3upFiles'
+import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
+import { API_setGoodsCover } from '@/store/action/C1ledger'
 
 type Props = {
   isLook?: boolean
   sId: number
+  info: C1GoodType
+  setImgCover?: () => void
 }
 
-function Y33com({ isLook, sId }: Props) {
+function Y33com({ isLook, sId, info, setImgCover }: Props) {
   const [fileList, setFileList] = useState<GoodFileType[]>([])
 
   const getListFu = useCallback(async () => {
@@ -118,62 +122,105 @@ function Y33com({ isLook, sId }: Props) {
   // 获取下载权限
   const downImg = useSelector((state: RootState) => state.A0Layout.downImg)
 
+  // 设置封面图
+  const setCoverFu = useCallback(
+    async (thumb: string, thumbPc: string) => {
+      const res = await API_setGoodsCover({
+        id: info.id,
+        thumb,
+        thumbPc
+      })
+      if (res.code === 0) {
+        MessageFu.success('设置成功')
+        setImgCover && setImgCover()
+      }
+    },
+    [info.id, setImgCover]
+  )
+
   const tableLastBtn = useMemo(() => {
-    return [
-      {
-        title: '操作',
+    let arr: any[] = []
+
+    if (isLook)
+      arr.push({
+        title: '封面图设置',
         render: (item: GoodFileType) => {
           const fileNameArr = item.fileName.split('.')
           const fileNameLast = fileNameArr[fileNameArr.length - 1]
-          return (
-            <>
-              {downImg['图片'] === '原图和缩略图' &&
-              fileImgArr.includes(fileNameLast.toLowerCase()) ? (
-                <Popconfirm
-                  title='请选择图片规格'
-                  onConfirm={() => downFileFu(item.filePath)}
-                  onCancel={() => downFileFu(item.thumb)}
-                  okText='原图'
-                  cancelText='缩略图'
-                >
-                  <Button size='small' type='text'>
-                    下载
-                  </Button>
-                </Popconfirm>
-              ) : (
+
+          return fileImgArr.includes(fileNameLast.toLowerCase()) ? (
+            item.thumb === info.thumb ? (
+              '封面'
+            ) : (
+              <Button
+                size='small'
+                type='text'
+                onClick={() => setCoverFu(item.thumb, item.filePath)}
+              >
+                设为封面
+              </Button>
+            )
+          ) : (
+            ' - '
+          )
+        }
+      })
+
+    arr.push({
+      title: '操作',
+      render: (item: GoodFileType) => {
+        const fileNameArr = item.fileName.split('.')
+        const fileNameLast = fileNameArr[fileNameArr.length - 1]
+        return (
+          <>
+            {downImg['图片'] === '原图和缩略图' &&
+            fileImgArr.includes(fileNameLast.toLowerCase()) ? (
+              <Popconfirm
+                title='请选择图片规格'
+                onConfirm={() => downFileFu(item.filePath)}
+                onCancel={() => downFileFu(item.thumb)}
+                okText='原图'
+                cancelText='缩略图'
+              >
+                <Button size='small' type='text'>
+                  下载
+                </Button>
+              </Popconfirm>
+            ) : (
+              <Button
+                size='small'
+                type='text'
+                onClick={() => downFileFu(item.thumb || item.filePath)}
+              >
+                下载
+              </Button>
+            )}
+            {isLook ? (
+              <>
                 <Button
                   size='small'
                   type='text'
-                  onClick={() => downFileFu(item.thumb || item.filePath)}
+                  onClick={() =>
+                    setTypeMo({
+                      ids: [item.id],
+                      type: item.type,
+                      effect: item.effect,
+                      flag: '单个'
+                    })
+                  }
                 >
-                  下载
+                  设置
                 </Button>
-              )}
-              {isLook ? (
-                <>
-                  <Button
-                    size='small'
-                    type='text'
-                    onClick={() =>
-                      setTypeMo({
-                        ids: [item.id],
-                        type: item.type,
-                        effect: item.effect,
-                        flag: '单个'
-                      })
-                    }
-                  >
-                    设置
-                  </Button>
-                  <MyPopconfirm txtK='删除' onConfirm={() => delFu([item.id])} />
-                </>
-              ) : null}
-            </>
-          )
-        }
+                <MyPopconfirm txtK='删除' onConfirm={() => delFu([item.id])} />
+              </>
+            ) : null}
+          </>
+        )
       }
-    ]
-  }, [delFu, downImg, isLook])
+    })
+
+    return arr
+  }, [delFu, downImg, info.thumb, isLook, setCoverFu])
 
   const [typeMo, setTypeMo] = useState({} as infoType)
 

+ 3 - 1
src/pages/Y_goodsDetails/Y2look/index.tsx

@@ -249,7 +249,9 @@ function Y2look() {
         <div className='Y2info'>
           {tabAc === '藏品信息' ? <Y11com info={info} /> : null}
           {tabAc === '库存信息' ? <Y22com info={info} /> : null}
-          {tabAc === '藏品附件' ? <Y33com sId={sId} isLook={true} /> : null}
+          {tabAc === '藏品附件' ? (
+            <Y33com sId={sId} isLook={true} info={info} setImgCover={() => getInfoFu(sId)} />
+          ) : null}
           {tabAc === '藏品日志' ? <Y44com sId={sId} isLook={true} /> : null}
         </div>
       ) : null}

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

@@ -50,3 +50,10 @@ export const C1_APIgetList = (data: any, exportFlag?: boolean): any => {
 export const API_getInfoLogList = (data: any) => {
   return http.post('cms/goods/log', data)
 }
+
+/**
+ * 藏品详情-修改封面图
+ */
+export const API_setGoodsCover = (data: any) => {
+  return http.post('cms/goods/updateThumb', data)
+}