import React, { useState, useRef, useEffect } from "react"; import { ResultFlowResult } from "@/components" import { Select, Input, Button, Table, message, Pagination, Popover, Modal, Col, Row, Form, Tabs } from 'antd' import { pageSizeOptions } from '@/config/character.config.js' import { SearchOutlined, DeleteOutlined, PlayCircleOutlined, EditOutlined, PlusCircleOutlined, InfoCircleOutlined } from '@ant-design/icons'; import ajax from '@/services' import "./index.scss"; import { useSessionStorageState } from "ahooks" function Road(props) { const [form] = Form.useForm() const [ajaxLoading, setAjaxLoading] = useState(false) const [deviceDetail, setDeviceDetail] = useState({}) const [editModalVisible, setEditModalVisible] = useState(false) const [editStatus, setEditStatus] = useState(false) const [storeData, setStoreData] = useState([]) //所属商户 const [deviceTypeData, setDeviceTypeData] = useState([{ label: '全部', value: -1 }]) //设备类型 const [brandData, setBrandData] = useState([{ label: '全部', value: -1 }]) // 品牌list const [resultData, setResultData] = useState({ data: [], total_records: 0, export_url: '', process_url: "" }) const parameter = { device_name: '', device_code: '', pole_position_code: '', type_id: -1, //设备类型 road_name: '', operator: "0", //所属商户 operate_status: -1, //运营状态 device_status: -1, //设备状态 pn: 1, length: Number(pageSizeOptions[0]), // 每页条数 } const [formData, setFormData] = useState(parameter) const [lastFormData, setLastFormData] = useState(formData) const lastFormDataRef = useRef(formData) const getOperatorData = () => { ajax.getOperator().then((e) => { setStoreData([ ...storeData, ...e.data ]) }) } const getDeviceType = () => { ajax.getDeviceTypeList().then((e) => { setDeviceTypeData([ ...deviceTypeData, ...e.data ]) }) } const getBrandData = () => { ajax.getAllBrandNameList().then((e) => { setBrandData([ ...brandData, ...e.data ]) }) } const handleDelToServer = (id) => { return new Promise((resolved, rejected) => { ajax.nvrDel(id).then((e) => { if (e.status == 20000) { resolved(e.message) } }).catch((err) => { rejected(err) }) }) } const getDeviceDetail = (id) => { return new Promise((resolved, rejected) => { ajax.getDeviceDimensionDetail({id: id}).then((e) => { if (e.status == 20000) { resolved(e.data) } }).catch((err) => { rejected(err) }) }) } const handleEdit = (item) => { getDeviceDetail(item.id).then((data) => { setEditStatus(true) form.setFieldsValue({ ...data }) setDeviceDetail(data) setEditModalVisible(true) }) } const editModalCancel = () => { setEditModalVisible(false) form.resetFields() } //列表 const handleColumns = (tab) => { let result = [...tableColumns]; switch (tab) { case '1': result.splice(9, 1) break; } return result; } //列表 const tableColumns = [ { title: '设备名称', dataIndex: 'name' }, { title: '设备编号', dataIndex: 'code' }, { title: '设备类型', dataIndex: 'type_name', }, { title: '所属路段', dataIndex: 'road_name', }, { title: '对应杆位号', dataIndex: 'pole_position_code', }, { title: '区域', dataIndex: 'region_name', }, { title: '设备厂商', dataIndex: 'operqator', }, { title: '运营状态', dataIndex: 'operate_status', }, { title: '设备状态', dataIndex: 'device_status', render: (text, record, index) => { return (
{text}
) } }, { title: '更新时间', dataIndex: 'update_time', }, { title: '操作', width: 135, // render: (text, record, index) => { // return <> //
//
// // }, render: (text, record) => { return <>
handleEdit(record)}>查看设备
}>
}, } ] // 获取列表数据 const getData = (data = formData) => { setAjaxLoading(true) ajax.getDeviceDimensionList(data).then(res => { setAjaxLoading(false) if (res.status === 20000) { let resDataArr = res.data.list.map((item) => { item.key = item.id return item }) setResultData({ ...resultData, data: resDataArr, total_records: res.data.total }) } else { setResultData({ data: [], total_records: 0, export_url: '', process_url: "" }) message.error(res.message) } }, err => { console.log(err) }) } //切换分页 const changePn = (pn, length) => { if (lastFormData.length === length) { setFormData(Object.assign({}, formData, { pn: pn, length: length})) setLastFormData(Object.assign({}, lastFormData, { pn: pn, length: length })) lastFormDataRef.current = Object.assign({}, lastFormData, { pn: pn , length: length}) getData(Object.assign({}, formData, { pn: pn, length: length })) } } //切换每页条数 const changeLength = (pn, length) => { setFormData(Object.assign({}, formData, { pn: 1, length: length })) setLastFormData(Object.assign({}, lastFormData, { pn: 1, length: length })) lastFormDataRef.current = Object.assign({}, lastFormData, { pn: 1, length: length }) getData(Object.assign({}, formData, { pn: 1, length: length })) } //检索数据 const getSearchData = (data = formData) => { getData(data) } //重置表单 const formReset = () => { setFormData({ ...parameter }) getData({...parameter}) } const handleExport = () => { ajax.deviceDimensionExport(formData).then(e => { if (e.status == 20000) { window.open(e.data.url) } }) } const brandEdit = (params) => { return new Promise((resolved, rejected) => { ajax.brandEdit(params).then((e) => { if (e.status == 20000) { resolved(e.message) } }).catch(err => { rejected(err) }) }) } const brandAdd = (params) => { return new Promise((resolved, rejected) => { ajax.brandAdd(params).then((e) => { if (e.status == 20000) { resolved(e.message) } }).catch(err => { rejected(err) }) }) } const [sessionTabList, setSessionTabList] = useSessionStorageState('equipmentStatus', { value: { } }) useEffect(() => { if (sessionTabList && Object.values(sessionTabList).length > 0) { setFormData({ device_name: sessionTabList?.device_name, device_code: sessionTabList?.device_code, pole_position_code: sessionTabList?.pole_position_code, type_id: -1, road_name: sessionTabList?.road_name, operator: "0", device_status: -1, operate_status: -1 }) } }, []) useEffect(() => { setSessionTabList({ ...formData }) }, [formData]) useEffect(() => { getData() getOperatorData() getDeviceType() getBrandData() }, []) return ( <>
setFormData({...formData, device_name: e.target.value})} />
setFormData({...formData, device_code: e.target.value})} />
setFormData({...formData, pole_position_code: e.target.value})} />
setFormData({...formData, road_name: e.target.value})} />
{ if (v == 2) { setFormData({...formData, operate_status: v, device_status: -1}) } else { setFormData({...formData, operate_status: v}) } }} />
{ formData.operate_status != 2 ? (