import React, {Component} from 'react'; //MonacoDiffEditor 对比模式 import { Badge, Select, Radio, Checkbox, Modal, DatePicker, Button, } from 'antd'; import locale from 'antd/lib/date-picker/locale/zh_CN'; import moment from 'moment'; import axios from 'axios'; import './css/TPMsettings.css'; import {handleDateStrings} from "./oldTPMsettings"; import Bottomsubmit from "../../modals/Bottomsubmit"; const $ = window.$; let timeout; let currentValue; const Option = Select.Option; const RadioGroup = Radio.Group; function range(start, end) { const result = []; for (let i = start; i < end; i++) { result.push(i); } return result; } function disabledDateTime() { return { // disabledHours: () => range(0, 24).splice(4, 20), disabledMinutes: () => range(1, 30).concat(range(31, 60)), // disabledSeconds: () => [0, 60], }; } function disabledDate(current) { return current && current < moment().endOf('day').subtract(1, 'days'); } export default class Shixuninformation extends Component { constructor(props) { super(props) this.state = { can_copy: false, use_scope: 0, opening_time: null, opentime: false, oldscope_partment: [], scope_partment: [], loading: false, opening_timetype:false } } componentDidMount() { if (this.props.data) { if (this.props.data.shixun) { this.setState({ can_copy: this.props.data && this.props.data.shixun.can_copy === undefined ? false : this.props.data && this.props.data.shixun.can_copy, use_scope: this.props.data && this.props.data.shixun.use_scope, opening_time: this.props.data && this.props.data.shixun.opening_time, opentime: !this.props.data && this.props.data.shixun.opening_time ? false : true, oldscope_partment: this.props.data && this.props.data.shixun.scope_partment, }) } } let departmentsUrl = `/shixuns/departments.json`; axios.get(departmentsUrl).then((response) => { if (response.status === 200) { if (response.data.message === undefined) { this.setState({ departmentslist: response.data.shools_name }); } } }).catch((error) => { console.log(error) }); } componentDidUpdate(prevProps, prevState) { if (prevProps.data != this.props.data) { if (this.props.data) { if (this.props.data.shixun) { this.setState({ can_copy: this.props.data && this.props.data.shixun.can_copy === undefined ? false : this.props.data && this.props.data.shixun.can_copy, use_scope: this.props.data && this.props.data.shixun.use_scope, opening_time: this.props.data && this.props.data.shixun.opening_time, opentime: !this.props.data && this.props.data.shixun.opening_time ? false : true, oldscope_partment: this.props.data && this.props.data.shixun.scope_partment, }) } } } } onChangeTimePicker = (value, dateString) => { this.setState({ opening_time: dateString === "" ? "" : handleDateStrings(dateString), opening_timetype:false }) } onSubmits = () => { this.setState({ loading: true }) let {can_copy, use_scope, scope_partment, opening_time,oldscope_partment} = this.state; if(this.state.opentime===true){ if(opening_time===null){ this.setState({ opening_timetype:true }) return } } let id = this.props.match.params.shixunId; let url = `/shixuns/${id}/update_permission_setting.json`; axios.post(url, { scope_partment: scope_partment, shixun: { can_copy: can_copy, use_scope: use_scope, opening_time: opening_time } } ).then((response) => { if (response.data.status === -1) { } else { let list=[] scope_partment.map((item,key)=>{ list.push(item) }) oldscope_partment.map((item,key)=>{ list.push(item) }) this.props.showNotification("权限配置保存成功!") this.setState({ loading: false, scope_partment:[], oldscope_partment:list }) this.props.getdatas("3") } }).catch((error) => { this.setState({ loading: false }) }) } CheckboxonChange = (e) => { this.setState({ can_copy: e.target.checked }) } SelectOpenpublic = (e) => { this.setState({ use_scope: e.target.value }); } shixunScopeInput = (e) => { let {scope_partment, oldscope_partment} = this.state; let datalist = scope_partment; if (datalist === undefined) { datalist = [] } let scopetype = false; if(scope_partment.length>0){ scope_partment.map((item, key) => { if (item === e) { debugger scopetype = true } }) } if(oldscope_partment.length>0){ oldscope_partment.map((item, key) => { if (item === e) { debugger scopetype = true } }) } if (scopetype === false) { datalist.push(e) this.setState({ scope_partment: datalist }); } else { this.props.showNotification("请勿指定相同的单位") } } shixunsfetch = (value, callback) => { if (timeout) { clearTimeout(timeout); timeout = null; } currentValue = value; function fake() { let departmentsUrl = `/shixuns/departments.json?q=` + currentValue; axios.get(departmentsUrl).then((response) => { callback(response.data.shools_name); }).catch((error) => { console.log(error) }); } timeout = setTimeout(fake, 300); } shixunHandleSearch = (value) => { this.shixunsfetch(value, departmentslist => this.setState({departmentslist})); } deleteScopeInput = (key) => { let {scope_partment} = this.state; let datalist = scope_partment; datalist.splice(key, 1); this.setState({ scope_partment: datalist }); } setopentime = (e) => { this.setState({ opentime: e.target.checked }) } render() { let options; if (this.state.departmentslist != undefined) { options = this.state.departmentslist.map((d, k) => { return ( ) }) } const dateFormat = 'YYYY-MM-DD HH:mm'; return (
复制:
{this.props.data && this.props.data.shixun.use_scope === 0 && this.props.data && this.props.data.shixun.status === 2 ? "" :
公开程度: 对所有单位公开 (实训发布后,所有用户可见) 对指定单位公开 (实训发布后,仅对下方指定单位的用户可见)
(请通过搜索并选中单位名称进行添加)
{ this.state.oldscope_partment.map((item, key) => { return (
  • ) }) } { this.state.scope_partment === undefined ? "" : this.state.scope_partment.map((item, key) => { return (
  • this.deleteScopeInput(key)}>
  • ) }) }
    请选择需要公开的单位
    }
    开启时间:
    {this.state.opentime === false ? "" :
    }
    请选择开启时间
    {this.props.identity < 5 ? : ""}
    ); } }