shaogen1995 3 miesięcy temu
rodzic
commit
ae93a9b5f6

+ 65 - 21
src/pages/B_enterTibet/B1collect/B1edit/B1MoAdd/index.tsx

@@ -1,20 +1,45 @@
-import React, { useCallback, useRef } from 'react'
+import React, { useCallback, useEffect, useRef, useState } from 'react'
 import styles from './index.module.scss'
 import { Button, Form, FormInstance, Input, Modal, Select } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
 import TextArea from 'antd/es/input/TextArea'
 import Z3upFiles from '@/components/Z3upFiles'
 import ZRichTexts from '@/components/ZRichTexts'
+import { selectObj } from '@/utils/select'
+import { B1X_APIgetInfo, B1X_APIsave } from '@/store/action/B1collect'
+import { MessageFu } from '@/utils/message'
+import { B1Xtype } from '../../type'
 
 type Props = {
   sId: number
-  info: any
   closeFu: () => void
-  succFu: () => void
+  succFu: (val: B1Xtype, txt: '新增' | '编辑') => void
   look?: boolean
 }
 
-function B1MoAdd({ sId, info, closeFu, succFu, look = false }: Props) {
+function B1MoAdd({ sId, closeFu, succFu, look = false }: Props) {
+  const [file, setFile] = useState([])
+
+  const getInfoFu = useCallback(async (id: number) => {
+    const res = await B1X_APIgetInfo(id)
+    if (res.code === 0) {
+      const data: B1Xtype = res.data
+      FormBoxRef.current?.setFieldsValue({
+        ...data,
+        type: data.type ? data.type : null
+      })
+      // 设置富文本
+      ZRichTextRef.current?.ritxtShowFu(JSON.parse(data.rtf || '{}'))
+
+      // 设置附件
+      setFile(data.file || [])
+    }
+  }, [])
+
+  useEffect(() => {
+    if (sId > 0) getInfoFu(sId)
+  }, [getInfoFu, sId])
+
   // 设置表单初始数据(区分编辑和新增)
   const FormBoxRef = useRef<FormInstance>(null)
 
@@ -24,14 +49,33 @@ function B1MoAdd({ sId, info, closeFu, succFu, look = false }: Props) {
   }, [])
 
   // 通过校验点击确定
-  const onFinish = useCallback(async (values: any) => {
-    // const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
-    // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
-  }, [])
+  const onFinish = useCallback(
+    async (values: any) => {
+      const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
+
+      // 上传附件
+      const filesRes = filesRef.current.filesIdRes()
+
+      const obj = {
+        ...values,
+        fileIds: filesRes.join(','),
+        rtf: JSON.stringify(rtf1.val || ''),
+        id: sId > 0 ? sId : null
+      }
+
+      const res = await B1X_APIsave(obj)
+
+      if (res.code === 0) {
+        MessageFu.success(sId > 0 ? '编辑成功' : '新增成功')
+        succFu(res.data, sId > 0 ? '编辑' : '新增')
+        closeFu()
+      }
+    },
+    [closeFu, sId, succFu]
+  )
 
   // 上传附件的ref
   const filesRef = useRef<any>(null)
-  // const filesRes = filesRef.current.filesIdRes();
 
   // 富文本的ref
   const ZRichTextRef = useRef<any>(null)
@@ -44,7 +88,7 @@ function B1MoAdd({ sId, info, closeFu, succFu, look = false }: Props) {
       wrapClassName={styles.B1MoAdd}
       destroyOnClose
       open={true}
-      title={`征集线索-${look ? '查看' : info.id > 0 ? '编辑' : '新增'}`}
+      title={`征集线索-${look ? '查看' : sId > 0 ? '编辑' : '新增'}`}
       footer={
         [] // 设置footer为空,去掉 取消 确定默认按钮
       }
@@ -61,23 +105,23 @@ function B1MoAdd({ sId, info, closeFu, succFu, look = false }: Props) {
           <div className='B1MformBox'>
             <Form.Item
               label='线索名称'
-              name='aaaa'
+              name='name'
               rules={[{ required: true, message: '请输入线索名称' }]}
             >
               <Input readOnly={look} maxLength={30} showCount placeholder='请输入内容' />
             </Form.Item>
 
-            <Form.Item label='线索类别' name='bbbb'>
-              <Select disabled={look} placeholder='请选择' />
+            <Form.Item label='线索类别' name='type'>
+              <Select disabled={look} placeholder='请选择' options={selectObj['线索类别']} />
             </Form.Item>
 
-            <Form.Item label='联系人' name='aaaa'>
+            <Form.Item label='联系人' name='linkman'>
               <Input readOnly={look} maxLength={30} showCount placeholder='请输入内容' />
             </Form.Item>
-            <Form.Item label='联系电话' name='aaaa'>
+            <Form.Item label='联系电话' name='phone'>
               <Input readOnly={look} maxLength={30} showCount placeholder='请输入内容' />
             </Form.Item>
-            <Form.Item label='联系地址' name='aaaa'>
+            <Form.Item label='联系地址' name='addr'>
               <TextArea readOnly={look} maxLength={500} showCount placeholder='请输入内容' />
             </Form.Item>
 
@@ -89,9 +133,9 @@ function B1MoAdd({ sId, info, closeFu, succFu, look = false }: Props) {
                   isLook={look}
                   ref={filesRef}
                   fileCheck={false}
-                  dirCode={'xxxxxxx'}
-                  myUrl='xxxxxxxxxxxx'
-                  lookData={[]}
+                  dirCode='B1collectSon'
+                  myUrl='cms/orderCollect/upload'
+                  lookData={file}
                   size={500}
                 />
               </div>
@@ -102,10 +146,10 @@ function B1MoAdd({ sId, info, closeFu, succFu, look = false }: Props) {
               <div className='B1Mrowrr'>
                 <ZRichTexts
                   check={false}
-                  dirCode={'xxxxxxxx'}
+                  dirCode='B1collectSon'
+                  myUrl='cms/orderCollect/upload'
                   isLook={look}
                   ref={ZRichTextRef}
-                  myUrl='xxxxxxxxxx'
                   isOne={true}
                   upAudioBtnNone={true}
                 />

+ 282 - 107
src/pages/B_enterTibet/B1collect/B1edit/index.tsx

@@ -3,7 +3,7 @@ import styles from './index.module.scss'
 import { useParams } from 'react-router-dom'
 import X3auditInfo from '@/pages/X_stock/X3auditInfo'
 import { MessageFu } from '@/utils/message'
-import history from '@/utils/history'
+import history, { btnFlagFu2 } from '@/utils/history'
 import { Button, DatePicker, Input } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
 import dayjs from 'dayjs'
@@ -11,22 +11,89 @@ import { B3aForm1 } from '../../B3_4page/B3edit/data'
 import Z3upFiles from '@/components/Z3upFiles'
 import ZRichTexts from '@/components/ZRichTexts'
 import MyTable from '@/components/MyTable'
-import { B1TableC } from '@/utils/tableData'
+import { B1TableC, statusObj } from '@/utils/tableData'
 import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
 import B1MoAdd from './B1MoAdd'
 import B3flowTable from '../../B3flowTable'
 import B1appraisal from '../B1appraisal'
+import { FourTableType } from '../../B3_4page/type'
+import {
+  B1_APIcreate,
+  B1_APIdel,
+  B1_APIgetInfo,
+  B1_APIrevocation,
+  B1_APIsaveApply,
+  B1_APIsaveAudit,
+  B1_APIsaveCreate,
+  B1_APIsaveDraft
+} from '@/store/action/B1collect'
+import { EXbtnFu } from '@/utils/EXBtn'
+import { B1Xtype } from '../type'
 function B1edit() {
   const { key, id } = useParams<any>()
+  // key:1 新增 2编辑 3审批 4查看
 
   // 滚到顶部
   const sollrDom = useRef<HTMLDivElement>(null)
 
+  // -------征集线索-------------
+  const [openId, setOpenId] = useState(0)
+
+  const [clueArr, setClueArr] = useState<B1Xtype[]>([])
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: '操作',
+        render: (item: any) => {
+          return (
+            <>
+              <Button size='small' type='text' onClick={() => setOpenId(item.id)}>
+                {['3', '4'].includes(key) ? '查看' : '编辑'}
+              </Button>
+              {['3', '4'].includes(key) ? null : (
+                <MyPopconfirm
+                  txtK='删除'
+                  onConfirm={() => setClueArr(clueArr.filter(v => v.id !== item.id))}
+                />
+              )}
+            </>
+          )
+        }
+      }
+    ]
+  }, [clueArr, key])
+  // -------征集线索-------------
+
+  // 顶部数据
+  const [topInfo, setTopInfo] = useState({} as FourTableType)
+
+  // 创建订单
+  const creatFu = useCallback(async () => {
+    const res = await B1_APIcreate()
+    if (res.code === 0) {
+      setTopInfo(res.data)
+    }
+  }, [])
+
+  // 获取详情
+  const getInfoFu = useCallback(async () => {
+    const res = await B1_APIgetInfo(id)
+    if (res.code === 0) {
+      setTopInfo(res.data)
+      setClueArr(res.data.collects || [])
+
+      // 设置富文本
+      ZRichTextRef.current?.ritxtShowFu(JSON.parse(res.data.rtf || '{}'))
+    }
+  }, [id])
+
   useEffect(() => {
-    console.log('key:', key)
+    if (key === '1') creatFu()
+    else getInfoFu()
 
     if (sollrDom.current) sollrDom.current.scrollTop = 0
-  }, [key])
+  }, [creatFu, getInfoFu, key])
 
   // 上传附件的ref
   const filesRef = useRef<any>(null)
@@ -38,94 +105,193 @@ function B1edit() {
   // 审批意见的ref
   const ZAuditRef = useRef<any>(null)
 
-  // 设置富文本
-  //  ZRichTextRef.current?.ritxtShowFu(JSON.parse(data.rtf))
+  const timeChange = useCallback(
+    (e: any) => {
+      setTopInfo({ ...topInfo, date: dayjs(e).format('YYYY-MM-DD') })
+    },
+    [topInfo]
+  )
 
-  const timeChange = useCallback((e: any) => {
-    console.log(123, e)
-  }, [])
+  // 审批的sta
+  const [auditSta, setAuDitSta] = useState('')
 
   // 新增的底部按钮点击
-  const btnClickFu = useCallback((val: number) => {
-    const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
-    console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
+  const btnClickFu = useCallback(
+    async (val: '草稿' | '创建' | '保存' | '审批') => {
+      if (!topInfo.name) return MessageFu.warning('计划名称不能为空')
+
+      if (val === '审批') {
+        // console.log('审批信息富文本', rtf2)
+        if (!auditSta) {
+          if (sollrDom.current) sollrDom.current.scrollTop = 0
+          return MessageFu.warning('请选择审批结果')
+        }
+        const rtf2 = ZAuditRef.current?.resData()
+
+        const res = await B1_APIsaveAudit({
+          orderId: topInfo.id,
+          rtfOpinion: rtf2,
+          status: auditSta === '同意' ? 1 : 2
+        })
+
+        if (res.code === 0) {
+          MessageFu.success('审批成功')
+          // 跳详情页
+          history.push(`/collect_edit/4/${topInfo.id}`)
+        }
+      } else {
+        const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
+        // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
 
-    const rtf2 = ZAuditRef.current?.resData()
-    console.log('审批信息富文本', rtf2)
+        // 上传附件
+        const filesRes = filesRef.current.filesIdRes()
 
-    // if (1 + 1 === 2) return
+        const obj = {
+          ...topInfo,
+          fileIds: filesRes.join(','),
+          rtf: JSON.stringify(rtf1.val || ''),
 
-    if (val === 2) {
-      // 存草稿 当前页保存 不跳转
-      MessageFu.success('草稿保存成功')
-    } else {
-      // 跳到详情页
-      history.push(`/collect_edit/4/111`)
-    }
-  }, [])
+          collectIds: clueArr.map(v => v.id).join(',')
+        }
+        // console.log(123, obj)
 
-  // 点击删除
-  const delTableFu = useCallback(async (id: number) => {}, [])
+        // if (1 + 1 === 2) return
 
-  const tableLastBtn = useMemo(() => {
-    return [
-      {
-        title: '操作',
-        render: (item: any) => {
-          return (
-            <>
-              <Button size='small' type='text' onClick={() => setOpenInfo(item)}>
-                {['3', '4'].includes(key) ? '查看' : '编辑'}
-              </Button>
-              {['3', '4'].includes(key) ? null : (
-                <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
-              )}
-            </>
-          )
+        if (val === '草稿') {
+          // 存草稿 当前页保存 不跳转
+          const res = await B1_APIsaveDraft(obj)
+          if (res.code === 0) {
+            MessageFu.success('草稿保存成功')
+          }
+        } else {
+          const res = val === '创建' ? await B1_APIsaveCreate(obj) : await B1_APIsaveApply(obj)
+          if (res.code === 0) {
+            MessageFu.success(`${val}成功`)
+            // 跳到详情页
+            history.push(`/collect_edit/4/${topInfo.id}`)
+          }
         }
       }
-    ]
-  }, [delTableFu, key])
+    },
+    [auditSta, clueArr, topInfo]
+  )
 
-  // 审批的sta
-  const [auditSta, setAuDitSta] = useState('')
+  // 查看的按钮创建-提交-撤回
+  const lookBtnFu = useCallback(
+    async (val: '创建' | '提交' | '撤回') => {
+      const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
+      // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
+
+      // 上传附件
+      const filesRes = filesRef.current.filesIdRes()
+      const obj = {
+        ...topInfo,
+        fileIds: filesRes.join(','),
+        rtf: JSON.stringify(rtf1.val || ''),
+        goodsIds: topInfo.goods.map(v => v.id).join(','),
+        goods: topInfo.goods.map(v => ({
+          goodsId: v.id,
+          siteStr: v.siteStr,
+          siteId: v.siteId
+        }))
+      }
+
+      const res =
+        val === '创建'
+          ? await B1_APIsaveCreate(obj)
+          : val === '提交'
+          ? await B1_APIsaveApply(obj)
+          : await B1_APIrevocation(id)
+
+      if (res.code === 0) {
+        if (sollrDom.current) sollrDom.current.scrollTop = 0
+        MessageFu.success(val + '成功')
+        getInfoFu()
+      }
+    },
+    [getInfoFu, id, topInfo]
+  )
 
-  // 查看模式下的按钮 待完善
+  // 查看模式点击删除
+  const delFu = useCallback(async () => {
+    const res = await B1_APIdel(id)
+    if (res.code === 0) {
+      MessageFu.success('删除成功')
+      history.push('/collect')
+    }
+  }, [id])
+
+  // 查看模式点击审批 编辑
+  const lookJumpFu = useCallback(
+    (val: '审批' | '编辑') => {
+      history.push(`/collect_edit/${val === '审批' ? 3 : 2}/${id}`)
+      MessageFu.success(`已跳转至${val}页面`)
+    },
+    [id]
+  )
+
+  // 查看模式下的按钮
   const lookBtn = useMemo(() => {
     return (
       <>
-        <Button type='primary'>创建</Button>
-        <Button type='primary'>提交</Button>
-        <MyPopconfirm
-          txtK='撤回'
-          onConfirm={() => {}}
-          Dom={
-            <Button type='primary' danger>
-              撤回
-            </Button>
-          }
-        />
+        {btnFlagFu2(topInfo)['创建'] ? (
+          <Button type='primary' onClick={() => lookBtnFu('创建')}>
+            创建
+          </Button>
+        ) : null}
+        {btnFlagFu2(topInfo)['提交'] ? (
+          <Button type='primary' onClick={() => lookBtnFu('提交')}>
+            提交
+          </Button>
+        ) : null}
+
+        {btnFlagFu2(topInfo)['撤回'] ? (
+          <MyPopconfirm
+            txtK='撤回'
+            onConfirm={() => lookBtnFu('撤回')}
+            Dom={
+              <Button type='primary' danger>
+                撤回
+              </Button>
+            }
+          />
+        ) : null}
+
+        {btnFlagFu2(topInfo)['审批'] ? (
+          <Button type='primary' onClick={() => lookJumpFu('审批')}>
+            审批
+          </Button>
+        ) : null}
+        {btnFlagFu2(topInfo)['编辑'] ? (
+          <Button type='primary' onClick={() => lookJumpFu('编辑')}>
+            编辑
+          </Button>
+        ) : null}
+
+        {btnFlagFu2(topInfo)['重新提交'] ? (
+          <Button type='primary' onClick={() => lookBtnFu('提交')}>
+            重新提交
+          </Button>
+        ) : null}
+
+        {EXbtnFu()}
+
+        {btnFlagFu2(topInfo)['删除'] ? (
+          <MyPopconfirm
+            txtK='删除'
+            onConfirm={() => delFu()}
+            Dom={
+              <Button type='primary' danger>
+                删除
+              </Button>
+            }
+          />
+        ) : null}
 
-        <Button type='primary'>审批</Button>
-        <Button type='primary'>编辑</Button>
-        <Button type='primary'>重新提交</Button>
-        <Button type='primary'>导出</Button>
-        <MyPopconfirm
-          txtK='删除'
-          onConfirm={() => {}}
-          Dom={
-            <Button type='primary' danger>
-              删除
-            </Button>
-          }
-        />
         <Button onClick={() => history.push('/collect')}>返回</Button>
       </>
     )
-  }, [])
-
-  // 征集线索
-  const [openInfo, setOpenInfo] = useState<any>({ id: 0 })
+  }, [delFu, lookBtnFu, lookJumpFu, topInfo])
 
   return (
     <div className={styles.B1edit}>
@@ -134,8 +300,8 @@ function B1edit() {
       <div className='B1main'>
         {['3'].includes(key) ? (
           <X3auditInfo
-            dirCode='待完善'
-            myUrl='待完善'
+            dirCode='B1collect'
+            myUrl='cms/orderCollect/upload'
             auditSta={auditSta}
             auditStaFu={val => setAuDitSta(val)}
             ref={ZAuditRef}
@@ -144,9 +310,10 @@ function B1edit() {
 
         {/* 表单字段、附件等 */}
         <div className='B1Tit'>
-          {/* 待完善 */}
           申请信息
-          <Button type='dashed'>草稿</Button>
+          {key === '1' ? null : (
+            <Button type='dashed'>{Reflect.get(statusObj, topInfo.status)}</Button>
+          )}
         </div>
         <div className='B1rowAll'>
           <div className='B1row'>
@@ -155,6 +322,8 @@ function B1edit() {
             </div>
             <div className='B1rowrr'>
               <Input
+                value={topInfo.name}
+                onChange={e => setTopInfo({ ...topInfo, name: e.target.value.trim() })}
                 readOnly={['3', '4'].includes(key)}
                 placeholder='请输入内容'
                 maxLength={30}
@@ -171,7 +340,7 @@ function B1edit() {
               <DatePicker
                 disabled={['3', '4'].includes(key)}
                 allowClear={false}
-                value={dayjs()}
+                value={dayjs(topInfo.date)}
                 onChange={timeChange}
               />
             </div>
@@ -181,9 +350,9 @@ function B1edit() {
             <div className='B1row' key={v.name}>
               <div className='B1rowll'>{v.name}:</div>
               <div className='B1rowrr'>
-                这是一段文本
+                {topInfo[v.key as 'name']}
                 {['3', '4'].includes(key) && v.name === '发起人'
-                  ? ' - 查看和审批后面显示创建时间'
+                  ? ' - ' + topInfo.createTime || ''
                   : ''}
               </div>
             </div>
@@ -197,9 +366,9 @@ function B1edit() {
                 isLook={['3', '4'].includes(key)}
                 ref={filesRef}
                 fileCheck={false}
-                dirCode={'xxxxxxx'}
-                myUrl='xxxxxxxxxxxx'
-                lookData={[]}
+                dirCode='B1collect'
+                myUrl='cms/orderCollect/upload'
+                lookData={topInfo.files || []}
                 size={500}
               />
             </div>
@@ -209,6 +378,8 @@ function B1edit() {
             <div className='B1rowll'>原因事由:</div>
             <div className='B1rowrr'>
               <Input
+                value={topInfo.reason}
+                onChange={e => setTopInfo({ ...topInfo, reason: e.target.value })}
                 readOnly={['3', '4'].includes(key)}
                 placeholder='请输入内容'
                 maxLength={30}
@@ -222,10 +393,10 @@ function B1edit() {
             <div className='B1rowrr'>
               <ZRichTexts
                 check={false}
-                dirCode={'xxxxxxxx'}
+                dirCode='B1collect'
+                myUrl='cms/orderCollect/upload'
                 isLook={['3', '4'].includes(key)}
                 ref={ZRichTextRef}
-                myUrl='xxxxxxxxxx'
                 isOne={true}
                 upAudioBtnNone={true}
               />
@@ -239,7 +410,7 @@ function B1edit() {
             <div className='B1Tit2ll'>征集线索</div>
             <div className='B1Tit2rr'>
               {['3', '4'].includes(key) ? null : (
-                <Button type='primary' onClick={() => setOpenInfo({ id: -1 })}>
+                <Button type='primary' onClick={() => setOpenId(-1)}>
                   新增
                 </Button>
               )}
@@ -248,27 +419,18 @@ function B1edit() {
 
           {/* 表格 */}
           <MyTable
-            list={[{ id: 101 }]}
+            list={clueArr}
             columnsTemp={B1TableC}
             lastBtn={tableLastBtn}
             pagingInfo={false}
           />
         </div>
 
-        {/* 相关鉴定 */}
+        {/* 相关鉴定 待完善*/}
         {['3', '4'].includes(key) ? <B1appraisal /> : null}
 
         {/* 申请流程 */}
-        {['3', '4'].includes(key) ? (
-          <B3flowTable
-            tableArr={
-              [
-                //  待完善
-              ]
-            }
-          />
-        ) : null}
-        {/* main-end */}
+        {['3', '4'].includes(key) ? <B3flowTable tableArr={topInfo.audits || []} /> : null}
       </div>
 
       {/* 底部按钮 */}
@@ -277,12 +439,18 @@ function B1edit() {
           lookBtn
         ) : (
           <>
-            <Button type='primary' onClick={() => btnClickFu(1)}>
-              {key === '1' ? '创建' : '保存'}
-            </Button>
+            {key === '3' ? (
+              <Button type='primary' onClick={() => btnClickFu('审批')}>
+                审批
+              </Button>
+            ) : (
+              <Button type='primary' onClick={() => btnClickFu(key === '1' ? '创建' : '保存')}>
+                {key === '1' ? '创建' : '保存'}
+              </Button>
+            )}
 
             {key === '1' ? (
-              <Button type='primary' onClick={() => btnClickFu(2)}>
+              <Button type='primary' onClick={() => btnClickFu('草稿')}>
                 存草稿
               </Button>
             ) : null}
@@ -293,13 +461,20 @@ function B1edit() {
       </div>
 
       {/* 征集线索 */}
-      {openInfo.id ? (
+      {openId ? (
         <B1MoAdd
           look={['3', '4'].includes(key)}
-          sId={id}
-          info={openInfo}
-          closeFu={() => setOpenInfo({})}
-          succFu={() => {}}
+          sId={openId}
+          closeFu={() => setOpenId(0)}
+          succFu={(obj, txt) => {
+            if (txt === '新增') setClueArr([obj, ...clueArr])
+            else {
+              const index = clueArr.findIndex(v => v.id === obj.id)
+              const newArr = [...clueArr]
+              newArr[index] = obj
+              setClueArr(newArr)
+            }
+          }}
         />
       ) : null}
     </div>

+ 3 - 0
src/pages/B_enterTibet/B1collect/index.module.scss

@@ -19,6 +19,9 @@
           }
         }
       }
+      .ant-select-selection-placeholder {
+        color: black;
+      }
     }
     .ant-table-cell {
       padding: 8px !important;

+ 102 - 34
src/pages/B_enterTibet/B1collect/index.tsx

@@ -1,19 +1,26 @@
 import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
 import styles from './index.module.scss'
 import { B3_4inputKeyArr, B3baseFormData, D3InputKeyType } from '../B3_4page'
-import history from '@/utils/history'
+import history, { btnFlagFu } from '@/utils/history'
 import { Button, DatePicker, Input, Select } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
 import dayjs from 'dayjs'
 import MyTable from '@/components/MyTable'
-import { B3tableC } from '@/utils/tableData'
+import { B3tableC, statusObj } from '@/utils/tableData'
+import { useDispatch, useSelector } from 'react-redux'
+import { B1_APIdel, B1_APIgetList } from '@/store/action/B1collect'
+import { MessageFu } from '@/utils/message'
+import { FourTableType } from '../B3_4page/type'
+import { RootState } from '@/store'
+import ExportJsonExcel from 'js-export-excel'
+import { selectObj } from '@/utils/select'
 const { RangePicker } = DatePicker
 
 function B1collect() {
-  // 没有接入后端 待完善
-
+  const dispatch = useDispatch()
   const [formData, setFormData] = useState(B3baseFormData)
   const formDataRef = useRef(B3baseFormData)
+  const formDataOldRef = useRef(B3baseFormData)
 
   useEffect(() => {
     formDataRef.current = formData
@@ -46,8 +53,9 @@ function B1collect() {
 
   // 封装发送请求的函数
   const getListFu = useCallback(() => {
-    console.log('发送请求', formDataRef.current)
-  }, [])
+    formDataOldRef.current = { ...formDataRef.current }
+    dispatch(B1_APIgetList(formDataRef.current))
+  }, [dispatch])
 
   useEffect(() => {
     getListFu()
@@ -86,40 +94,95 @@ function B1collect() {
   // 点击删除
   const delTableFu = useCallback(
     async (id: number) => {
-      getListFu()
+      const res = await B1_APIdel(id)
+      if (res.code === 0) {
+        MessageFu.success('删除成功')
+        getListFu()
+      }
     },
     [getListFu]
   )
-
   // 点击各种操作按钮
-  const btnFu = useCallback((id: number | string, key: string) => {
+  const tableBtnFu = useCallback((id: number, key: string) => {
     history.push(`/collect_edit/${key}/${id}`)
   }, [])
 
   const tableLastBtn = useMemo(() => {
-    //   看状态和账号角色显示按钮 待完善
     return [
       {
         title: '操作',
-        render: (item: any) => {
-          return (
+        render: (item: FourTableType) => {
+          let obj = btnFlagFu(item)
+          return !Object.values(obj).some(Boolean) ? (
+            '-'
+          ) : (
             <>
-              <Button size='small' type='text' onClick={() => btnFu(item.id, '2')}>
-                编辑
-              </Button>
-              <Button size='small' type='text' onClick={() => btnFu(item.id, '3')}>
-                审批
-              </Button>
-              <Button size='small' type='text' onClick={() => btnFu(item.id, '4')}>
-                查看
-              </Button>
-              <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
+              {obj['编辑'] ? (
+                <Button size='small' type='text' onClick={() => tableBtnFu(item.id, '2')}>
+                  编辑
+                </Button>
+              ) : null}
+
+              {obj['审批'] ? (
+                <Button size='small' type='text' onClick={() => tableBtnFu(item.id, '3')}>
+                  审批
+                </Button>
+              ) : null}
+              {obj['查看'] ? (
+                <Button size='small' type='text' onClick={() => tableBtnFu(item.id, '4')}>
+                  查看
+                </Button>
+              ) : null}
+
+              {obj['删除'] ? (
+                <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
+              ) : null}
             </>
           )
         }
       }
     ]
-  }, [btnFu, delTableFu])
+  }, [delTableFu, tableBtnFu])
+
+  // 从仓库拿数据
+  const tableInfo = useSelector((state: RootState) => state.B1collect.tableInfo)
+
+  // 点击导出
+  const deriveFu = useCallback(async () => {
+    const name = '藏品征集' + dayjs(new Date()).format('YYYY-MM-DD HH:mm')
+
+    const res = await B1_APIgetList(
+      {
+        ...formDataOldRef.current,
+        pageNum: 1,
+        pageSize: 99999
+      },
+      true
+    )
+
+    if (res.code === 0) {
+      if (res.data.records.length <= 0) return MessageFu.warning('当前搜索条件没有数据!')
+
+      const option = {
+        fileName: name,
+        datas: [
+          {
+            sheetData: res.data.records.map((v: FourTableType) => ({
+              ...v,
+              status: statusObj[v.status as 1]
+            })),
+            sheetName: name,
+            sheetFilter: ['num', 'name', 'deptName', 'creatorName', 'createTime', 'status'],
+            sheetHeader: ['业务单号', '申请名称', '发起部门', '发送人', '发起日期', '申请状态'],
+            columnWidths: [10, 10, 10, 10, 10, 10]
+          }
+        ]
+      }
+
+      const toExcel = new ExportJsonExcel(option) //new
+      toExcel.saveExcel() //保存
+    }
+  }, [])
 
   return (
     <div className={styles.B1collect}>
@@ -139,8 +202,11 @@ function B1collect() {
           ))}
         </div>
         <div className='B1toprr'>
-          <Button type='primary'>批量导出</Button>&emsp;
-          <Button type='primary' onClick={() => btnFu('null', '1')}>
+          <Button type='primary' onClick={deriveFu}>
+            批量导出
+          </Button>
+          &emsp;
+          <Button type='primary' onClick={() => history.push('/collect_edit/1/null')}>
             新增
           </Button>
         </div>
@@ -160,21 +226,23 @@ function B1collect() {
           <div>
             <span>申请状态:</span>
             <Select
-              placeholder='请选择'
-              style={{ width: 200 }}
+              allowClear={true}
+              placeholder='全部'
+              style={{ width: 198 }}
               value={formData.status}
               onChange={e => setFormData({ ...formData, status: e })}
-              options={[{ value: '', label: '全部' }]}
+              options={selectObj['申请状态'].filter(v => v.label !== '待盘点')}
             />
           </div>
 
           <div>
             <span>选择角色:</span>
             <Select
-              style={{ width: 200 }}
-              placeholder='请选择'
-              options={[]}
-              fieldNames={{ value: 'id', label: 'roleName' }}
+              allowClear={true}
+              style={{ width: 198 }}
+              placeholder='全部'
+              options={selectObj['角色']}
+              // fieldNames={{ value: 'id', label: 'roleName' }}
               value={formData.userType}
               onChange={e => setFormData({ ...formData, userType: e })}
             />
@@ -191,12 +259,12 @@ function B1collect() {
       {/* 表格 */}
       <MyTable
         yHeight={610}
-        list={[{ id: 91 }]}
+        list={tableInfo.list}
         columnsTemp={B3tableC}
         lastBtn={tableLastBtn}
         pageNum={formData.pageNum}
         pageSize={formData.pageSize}
-        total={0}
+        total={tableInfo.total}
         onChange={(pageNum, pageSize) => paginationChange(pageNum, pageSize)}
       />
     </div>

+ 15 - 0
src/pages/B_enterTibet/B1collect/type.d.ts

@@ -0,0 +1,15 @@
+export type B1Xtype = {
+  addr: string
+  createTime: string
+  creatorId: number
+  creatorName: string
+  file: []
+  fileIds: string
+  id: number
+  linkman: string
+  name: string
+  phone: string
+  rtf: string
+  type: string
+  updateTime: string
+}

+ 8 - 0
src/pages/B_enterTibet/B3flowTable/index.tsx

@@ -29,6 +29,14 @@ function B3flowTable({ tableArr }: Props) {
   const tableLastBtn = useMemo(() => {
     return [
       {
+        title: '审批结构',
+        render: (item: B3flowTableType) => {
+          const txt1 = item.status === 1 ? '同意' : item.status === 2 ? '不同意' : '(空)'
+          const txt2 = item.isAuto === 1 ? '(自动)' : ''
+          return txt1 + txt2
+        }
+      },
+      {
         title: '审批意见',
         render: (item: B3flowTableType) => {
           if (textFu(item.rtfOpinion)) {

+ 92 - 0
src/store/action/B1collect.ts

@@ -0,0 +1,92 @@
+import http from '@/utils/http'
+import { AppDispatch } from '..'
+/**
+ * 藏品征集 - 获取分页列表
+ */
+export const B1_APIgetList = (data: any, exportFlag?: boolean): any => {
+  if (exportFlag) return http.post('cms/orderCollect/page', data)
+  else {
+    return async (dispatch: AppDispatch) => {
+      const res = await http.post('cms/orderCollect/page', data)
+      if (res.code === 0) {
+        const obj = {
+          list: res.data.records,
+          total: res.data.total
+        }
+        dispatch({ type: 'B1/getList', payload: obj })
+      }
+    }
+  }
+}
+
+/**
+ * 藏品征集-删除
+ */
+export const B1_APIdel = (id: number) => {
+  return http.get(`cms/orderCollect/remove/${id}`)
+}
+
+/**
+ * 藏品征集-创建订单
+ */
+export const B1_APIcreate = () => {
+  return http.get('cms/orderCollect/create')
+}
+
+/**
+ * 藏品征集-获取详情
+ */
+export const B1_APIgetInfo = (id: number) => {
+  return http.get(`cms/orderCollect/detail/${id}`)
+}
+
+/**
+ * 藏品征集-存草稿
+ */
+export const B1_APIsaveDraft = (data: any) => {
+  return http.post('cms/orderCollect/saveDraft', data)
+}
+
+/**
+ * 藏品征集-创建
+ */
+export const B1_APIsaveCreate = (data: any) => {
+  return http.post('cms/orderCollect/saveCreate', data)
+}
+
+/**
+ * 藏品征集-编辑保存
+ */
+export const B1_APIsaveApply = (data: any) => {
+  return http.post('cms/orderCollect/saveApply', data)
+}
+
+/**
+ * 藏品征集-审批
+ */
+export const B1_APIsaveAudit = (data: any) => {
+  return http.post('cms/orderCollect/audit', data)
+}
+
+/**
+ * 藏品征集-撤回订单
+ */
+export const B1_APIrevocation = (id: number) => {
+  return http.get(`cms/orderCollect/revocation/${id}`)
+}
+
+// --------------------------线索相关-----------------
+
+/**
+ * 藏品征集-线索-新增\编辑
+ */
+export const B1X_APIsave = (data: any) => {
+  return http.post('cms/orderCollect/collect/save', data)
+}
+
+/**
+ * 藏品征集-线索-详情
+ */
+export const B1X_APIgetInfo = (id: number) => {
+  return http.get(`cms/orderCollect/collect/detail/${id}`)
+}

+ 28 - 0
src/store/reducer/B1collect.ts

@@ -0,0 +1,28 @@
+import { FourTableType } from '@/pages/B_enterTibet/B3_4page/type'
+
+// 初始化状态
+const initState = {
+  // 列表数据
+  tableInfo: {
+    list: [] as FourTableType[],
+    total: 0
+  }
+}
+
+// 定义 action 类型
+type Props = {
+  type: 'B1/getList'
+  payload: { list: FourTableType[]; total: number }
+}
+
+// reducer
+export default function userReducer(state = initState, action: Props) {
+  switch (action.type) {
+    // 获取列表数据
+    case 'B1/getList':
+      return { ...state, tableInfo: action.payload }
+
+    default:
+      return state
+  }
+}

+ 2 - 0
src/store/reducer/index.ts

@@ -3,6 +3,7 @@ import { combineReducers } from 'redux'
 
 // 导入 登录 模块的 reducer
 import A0Layout from './layout'
+import B1collect from './B1collect'
 import FourAll from './FourAll'
 import C1ledger from './C1ledger'
 import C2files from './C2files'
@@ -22,6 +23,7 @@ import Z7log from './Z7log'
 // 合并 reducer
 const rootReducer = combineReducers({
   A0Layout,
+  B1collect,
   FourAll,
   C1ledger,
   C2files,

+ 6 - 0
src/utils/select.ts

@@ -62,5 +62,11 @@ export const selectObj = {
     { value: 1, label: '已鉴定' },
     { value: 2, label: '已入馆' },
     { value: 3, label: '已入藏' }
+  ],
+  线索类别: [
+    { value: '民间征集', label: '民间征集' },
+    { value: '学术研究', label: '学术研究' },
+    { value: '市场流通', label: '市场流通' },
+    { value: '其他', label: '其他' }
   ]
 }

+ 5 - 7
src/utils/tableData.ts

@@ -28,12 +28,11 @@ selectObj['入藏状态'].forEach(v => {
   statusCollectObj[v.value] = v.label
 })
 
-// 待完善
 export const B1TableC = [
-  ['txt', '线索名称', 'description'],
-  ['txt', '线索类别', 'description'],
-  ['txt', '创建人', 'description'],
-  ['txt', '创建时间', 'description']
+  ['txt', '线索名称', 'name'],
+  ['txt', '线索类别', 'type'],
+  ['txt', '创建人', 'creatorName'],
+  ['txt', '创建时间', 'createTime']
 ]
 
 export const B3eTableC = [
@@ -52,8 +51,7 @@ export const B3eTableC = [
 export const B3FtableC = [
   ['txt', '节点名称', 'name'],
   ['txt', '提交日期', 'updateTime'],
-  ['txt', '处理人', 'creatorName'],
-  ['txtChange', '审批结果', 'status', { 1: '同意', 2: '不同意' }]
+  ['txt', '处理人', 'creatorName']
 ]
 
 export const D1GtableC = [