import React, { Component } from "react"; import { HOST } from '../../config'; import swal from 'sweetalert'; import { Redirect } from 'react-router-dom'; import Pagination from "react-js-pagination"; import $ from 'jquery'; import { PulseLoader } from 'react-spinners'; import Modalupload from '../Modal/ModalUpload'; import ModalEditImg from '../Modal/ModalEditImg'; import axios from 'axios'; import { Avatar, Tooltip, Image } from 'antd'; import {UserOutlined} from '@ant-design/icons'; import momment from 'moment'; import Select from "react-select"; import Store from '../../store'; class ImportImage extends Component { constructor(props) { super(props); this.state = { listImgImport: [], crrImg: [], activePage: 1, offset: 0, showFirst: 0, showLast: 0, totalLength: 0, loading: true, count: 0, modalShow: false, dataEdit: null, modalUploadShow: false, dataSearch: "", optionSelect: [{value: 1, label:"Facebook"}, {value: 2, label: "Tải lên"}], valueSelected: {value: 2, label:"Tải lên"}, dataRole: Store.getState().role.role, } Store.subscribe(() => { this.setState({ dataRole: Store.getState().role.role, }, () => { }); }); this.itemsPerPage = 5; } componentDidMount() { this.getListImg(1); } getListImg = async (page) => { this.setState({ loading: true }); try { const result = await axios({ method: 'POST', url: `${HOST}/api/face_images/search`, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', // 'Authorization': token }, data: { index: page, item_per_page: this.itemsPerPage, search_data: this.state.dataSearch, import_type: this.state.valueSelected.value }, }) if (result.data.status === 10000) { this.setState({ listImgImport: result.data.data, totalLength: result.data.count, }, () => { this.FilterItem(this.state.activePage) }) } } catch (error) { this.setState({ }) console.log(error); } this.setState({ loading: false }); } modalClose = () => { this.setState({ modalShow: false, }); this.getListImg(this.state.activePage); } modalUploadClose = () => { this.setState({ modalUploadShow: false, }); this.getListImg(this.state.activePage); } FilterItem = (activePage) => { const offset = (activePage - 1) * this.itemsPerPage; this.setState({ offset: offset }) } onClickEdit = (value) => { this.setState({ modalShow: true, dataEdit: value }) } handlePageChange = (pageNumber) => { this.setState({ activePage: pageNumber }, () => { this.getListImg(pageNumber); }) } onDelete = async (img) => { let data = await fetch(`${HOST}/api/face_images/delete`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', // 'Authorization': token }, body: JSON.stringify({ 'image_obj_id_list': [img._id] }) }).then((response) => { return response.json() }); if (data.status === 10000) { var { activePage } = this.state if (this.state.listImgImport.length === 1) { activePage = activePage - 1 } this.setState({ activePage: activePage }) swal("Thành công", "Xoá ảnh thành công", "success") this.getListImg(this.state.activePage); } else { swal("Thất bại", "Xoá ảnh thất bại", "error"); } } handleOnKeyDown = e => { if (e.key === 'Enter') { this.getListImg(1) } } reset = () => { this.setState({ activePage: 1, dataSearch: "", valueSelected: {value: 2, label:"Tải lên"}, }, () => { this.getListImg(1); }) } changeHandleFilter = (e) => { this.setState({ valueSelected: e, activePage: 1 }, () => { this.getListImg(1); }); } render() { // if (this.state.isLogin == false) { // return ( // // ) // } let bulletedListImg = this.state.listImgImport.map((value, index) => { var listImg listImg = return ( {(index + this.state.offset + 1)} {listImg} {value.origin_name} {value.import_type === 1 ? "Facebook" : "Tải lên"} {momment(value.created_time).format("DD-MM-YYYY")} {this.state.dataRole?.indexOf('import:edit') === -1 && this.state.dataRole?.indexOf('import:delete') === -1 ? "" : {this.state.dataRole?.indexOf('import:edit') !== -1 ? : ""} {this.state.dataRole?.indexOf('import:delete') !== -1 ? : ""} } ) }); return (

Kho ảnh

this.handleOnKeyDown(e)} onChange={(e) => { this.setState({ dataSearch: e.target.value }) }} value={this.state.dataSearch} id="inputSearch" className="form-control m-input" placeholder="Tên ảnh..." data-col-index={0} />
{process.env.REACT_APP_SOURCE_IMG === "1" ?