|
|
@@ -1,13 +1,327 @@
|
|
|
-import React from 'react'
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
-function A1overview() {
|
|
|
+import { antdSelectType, selectObj, tableSelectToTxt } from '@/utils/dataChange'
|
|
|
+import { useDispatch, useSelector } from 'react-redux'
|
|
|
+import { selectTopBase } from '@/pages/Zother/SelectGoods/data'
|
|
|
+import { getKuListByOpenFu } from '@/pages/Zother/data'
|
|
|
+import { ziyuanAcGet, ziyuanAcSet } from '@/utils/storage'
|
|
|
+import { APIdelTable, B1_APIgetList } from '@/store/action/Bresource/B1overview'
|
|
|
+import { RootState } from '@/store'
|
|
|
+import { Button, Cascader, Input, Select } from 'antd'
|
|
|
+import { Z1_APIgetFormZiDuan } from '@/store/action/Zsystem/Z1sysSet'
|
|
|
+import { baseFormType } from '@/pages/Zsystem/Z1sysSet/data'
|
|
|
+import { treeOneIdByResFu } from '@/pages/Zother/Z1formSet/data'
|
|
|
+import { B1searchFile } from './data'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import Z0sonTable from '@/components/Z0sonTable'
|
|
|
+import { openLink } from '@/utils/history'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+function B1overview() {
|
|
|
+ const [kuList, setKuList] = useState<antdSelectType[]>([])
|
|
|
+
|
|
|
+ const [loding, setLoding] = useState(false)
|
|
|
+
|
|
|
+ const dispatch = useDispatch()
|
|
|
+
|
|
|
+ const [formData, setFormData] = useState({ ...selectTopBase })
|
|
|
+ const formDataRef = useRef({ ...selectTopBase })
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ formDataRef.current = { ...formData }
|
|
|
+ }, [formData])
|
|
|
+
|
|
|
+ // 获取表单字段
|
|
|
+ const [formZi, setFormZi] = useState<baseFormType[]>([])
|
|
|
+
|
|
|
+ const getFormZiFu = useCallback(async (id: number) => {
|
|
|
+ const res = await Z1_APIgetFormZiDuan(id)
|
|
|
+ if (res.code === 0) {
|
|
|
+ const list: any[] = res.data || {}
|
|
|
+ setFormZi(list.filter(v => !B1searchFile.includes(v.fieldLabel)))
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getKuListByOpenFu(data => {
|
|
|
+ setLoding(true)
|
|
|
+ if (data && data.length) {
|
|
|
+ setKuList(data)
|
|
|
+ const ziyuanAcTxt = ziyuanAcGet()
|
|
|
+
|
|
|
+ const fId = ziyuanAcTxt || data[0].value
|
|
|
+ const obj = { ...selectTopBase, formDefId: fId }
|
|
|
+ setFormData(obj)
|
|
|
+ getFormZiFu(fId)
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, [dispatch, getFormZiFu])
|
|
|
+
|
|
|
+ // 点击搜索的 时间戳
|
|
|
+ const [timeKey, setTimeKey] = useState(0)
|
|
|
+
|
|
|
+ // 点击搜索
|
|
|
+ const clickSearch = useCallback(() => {
|
|
|
+ setFormData({ ...formData, current: 1 })
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ }, [formData])
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const resetSelectFu = useCallback(
|
|
|
+ (formDefId?: number) => {
|
|
|
+ setFormData({ ...selectTopBase, formDefId: formDefId || formData.formDefId })
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ },
|
|
|
+ [formData.formDefId]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 封装发送请求的函数
|
|
|
+ const getList = useCallback(async () => {
|
|
|
+ const obj = {
|
|
|
+ ...formDataRef.current
|
|
|
+ }
|
|
|
+
|
|
|
+ // 字典和标签需要 取最后一级 转成数字
|
|
|
+ const sonObj = { ...(obj.dictQuery || {}) }
|
|
|
+
|
|
|
+ for (const k in sonObj) {
|
|
|
+ const temp = sonObj[k]
|
|
|
+ if (typeof temp === 'object') sonObj[k] = Number(temp[temp.length - 1])
|
|
|
+ }
|
|
|
+
|
|
|
+ obj.dictQuery = sonObj
|
|
|
+
|
|
|
+ dispatch(B1_APIgetList(obj))
|
|
|
+ }, [dispatch])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (timeKey) getList()
|
|
|
+ }, [getList, timeKey])
|
|
|
+
|
|
|
+ // 页码变化
|
|
|
+ const paginationChange = useCallback(
|
|
|
+ (pageNum: number, pageSize: number) => {
|
|
|
+ setFormData({ ...formData, current: pageNum, size: pageSize })
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ },
|
|
|
+ [formData]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 动态表单的渲染
|
|
|
+ const dongFormChange = useCallback(
|
|
|
+ (key: any, val: any, flag?: boolean) => {
|
|
|
+ const resKey = flag ? 'dictQuery' : 'queryParams'
|
|
|
+
|
|
|
+ const oldFormSon = { ...(formData[resKey] || {}) }
|
|
|
+ oldFormSon[key] = val
|
|
|
+ setFormData({ ...formData, [resKey]: oldFormSon })
|
|
|
+ },
|
|
|
+ [formData]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 关联字典数组
|
|
|
+ const dictArrTemp = useSelector((state: RootState) => state.Z2dict.dictAll)
|
|
|
+ // 关联标签
|
|
|
+ const biaoQianTemp = useSelector((state: RootState) => state.B3resTag.dictAll)
|
|
|
+ // 表格数据
|
|
|
+ const tableInfo = useSelector((state: RootState) => state.B1overview.tableInfo)
|
|
|
+
|
|
|
+ // 点击删除和二维码
|
|
|
+ const tableBtnFu = useCallback(
|
|
|
+ async (val: '删除' | '二维码', id: number) => {
|
|
|
+ if (val === '删除') {
|
|
|
+ const res = await APIdelTable(formData.formDefId, id)
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success('删除成功')
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ } else MessageFu.warning('开发中')
|
|
|
+ },
|
|
|
+ [formData.formDefId, getList]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 表格操作按钮
|
|
|
+ const tabBtnArr = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: '入库状态',
|
|
|
+ width: 100,
|
|
|
+ render: (item: any) => tableSelectToTxt(item.status_storage, selectObj['入库状态'])
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '发布状态',
|
|
|
+ width: 100,
|
|
|
+ render: (item: any) => tableSelectToTxt(item.status_publish, selectObj['发布状态'])
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '推荐状态',
|
|
|
+ width: 100,
|
|
|
+ render: (item: any) => tableSelectToTxt(item.status_hot, selectObj['推荐状态'])
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ width: 'auto',
|
|
|
+ fixed: 'right',
|
|
|
+ render: (item: any) => {
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <Button
|
|
|
+ size='small'
|
|
|
+ type='text'
|
|
|
+ onClick={() => openLink(`/goodsLook/${item.id}/${formData.formDefId}`)}
|
|
|
+ >
|
|
|
+ 查看
|
|
|
+ </Button>
|
|
|
+ {[2, 3].includes(item.status_storage) ? (
|
|
|
+ <Button size='small' type='text' onClick={() => tableBtnFu('二维码', item.id)}>
|
|
|
+ 二维码
|
|
|
+ </Button>
|
|
|
+ ) : (
|
|
|
+ <MyPopconfirm txtK='删除' onConfirm={() => tableBtnFu('删除', item.id)} />
|
|
|
+ )}
|
|
|
+ </>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }, [formData.formDefId, tableBtnFu])
|
|
|
+
|
|
|
return (
|
|
|
- <div className={styles.A1overview}>
|
|
|
- <h1>A1overview</h1>
|
|
|
+ <div className={styles.B1overview}>
|
|
|
+ <div className='pageTitle'>资源总览</div>
|
|
|
+
|
|
|
+ {formData.formDefId ? (
|
|
|
+ <div className='B1main'>
|
|
|
+ <div className='b1top'>
|
|
|
+ <div className='Z0ku'>
|
|
|
+ 资源库:
|
|
|
+ <Select
|
|
|
+ style={{ maxWidth: 200, minWidth: 120 }}
|
|
|
+ value={formData.formDefId}
|
|
|
+ onChange={e => {
|
|
|
+ setFormData({ ...formData, pageNum: 1, formDefId: e })
|
|
|
+ ziyuanAcSet(e)
|
|
|
+ getFormZiFu(e)
|
|
|
+ resetSelectFu(e)
|
|
|
+ }}
|
|
|
+ options={kuList}
|
|
|
+ />
|
|
|
+ <div className='Z0ku1'>
|
|
|
+ <Button type='primary' onClick={() => MessageFu.warning('开发中')}>
|
|
|
+ 数据导入
|
|
|
+ </Button>
|
|
|
+ <Button type='primary' onClick={() => MessageFu.warning('开发中')}>
|
|
|
+ 数据导出
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ <div className='Z0ku1'>
|
|
|
+ <Button type='primary' onClick={clickSearch}>
|
|
|
+ 查  询
|
|
|
+ </Button>
|
|
|
+
|
|
|
+ <Button onClick={() => resetSelectFu()}>重  置</Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className='B1topMain'>
|
|
|
+ <div className='sgLeftRow'>
|
|
|
+ <Input
|
|
|
+ style={{ width: 290 }}
|
|
|
+ value={formData.searchKey}
|
|
|
+ onChange={e => setFormData({ ...formData, searchKey: e.target.value })}
|
|
|
+ placeholder='请输入资源编码、资源名称、责任者'
|
|
|
+ maxLength={30}
|
|
|
+ showCount
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className='sgLeftRow'>
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ style={{ width: 120 }}
|
|
|
+ value={(formData.queryParams || {})['status_storage']}
|
|
|
+ onChange={e => dongFormChange('status_storage', e)}
|
|
|
+ options={selectObj['入库状态']}
|
|
|
+ placeholder='入库状态'
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className='sgLeftRow'>
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ style={{ width: 120 }}
|
|
|
+ value={(formData.queryParams || {})['status_publish']}
|
|
|
+ onChange={e => dongFormChange('status_publish', e)}
|
|
|
+ options={selectObj['发布状态']}
|
|
|
+ placeholder='发布状态'
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {formZi.map(item => (
|
|
|
+ <div key={item.id} className='sgLeftRow'>
|
|
|
+ {item.tag === '文本' ? (
|
|
|
+ <Input
|
|
|
+ value={(formData.queryParams || {})[item.fieldName]}
|
|
|
+ onChange={e => dongFormChange(item.fieldName, e.target.value.trim())}
|
|
|
+ placeholder={item.fieldLabel}
|
|
|
+ maxLength={30}
|
|
|
+ showCount
|
|
|
+ />
|
|
|
+ ) : ['关联标签', '关联字典'].includes(item.tag) ? (
|
|
|
+ <Cascader
|
|
|
+ changeOnSelect
|
|
|
+ value={(formData.dictQuery || {})[item.fieldName]}
|
|
|
+ onChange={e => dongFormChange(item.fieldName, e, true)}
|
|
|
+ fieldNames={{ label: 'name', value: 'id', children: 'children' }}
|
|
|
+ options={treeOneIdByResFu(
|
|
|
+ item.tag === '关联字典' ? dictArrTemp : biaoQianTemp,
|
|
|
+ item.dictId + ''
|
|
|
+ )}
|
|
|
+ placeholder={item.fieldLabel}
|
|
|
+ />
|
|
|
+ ) : item.tag === '下拉' ? (
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ value={(formData.queryParams || {})[item.fieldName]}
|
|
|
+ onChange={e => dongFormChange(item.fieldName, e)}
|
|
|
+ style={{ width: 120 }}
|
|
|
+ options={item.options.split(',').map(v => ({ value: v, label: v }))}
|
|
|
+ placeholder={item.fieldLabel}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className='b1table'>
|
|
|
+ <Z0sonTable
|
|
|
+ kuList={kuList}
|
|
|
+ formZi={formZi}
|
|
|
+ formDefId={formData.formDefId}
|
|
|
+ tableList={tableInfo.list}
|
|
|
+ pageInfo={{ current: formData.current, size: formData.size, total: tableInfo.total }}
|
|
|
+ yHeight={710}
|
|
|
+ onChange={(pageNum, pageSize) => paginationChange(pageNum, pageSize)}
|
|
|
+ tabBtnArrAll={tabBtnArr}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <div hidden={!loding} className='Z0null'>
|
|
|
+ 请先在 系统管理-资源库管理 添加数据 或 开启资源库状态
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-const MemoA1overview = React.memo(A1overview)
|
|
|
+const MemoB1overview = React.memo(B1overview)
|
|
|
|
|
|
-export default MemoA1overview
|
|
|
+export default MemoB1overview
|