import React, { Component } from 'react';
import { MessageSocket } from 'tools/MessageSocket.js';
import { Modal, message, Input, Button, Select, Radio, Icon, Table, Col } from 'antd';
import fetchJsonp from 'fetch-jsonp';
import { $http } from '../../containers/config/https';
import './CSS/message.less';
import CommonPagination from 'components/pagination/index';
import RangeDatePicker from 'components/rangePicker/index';
import ColumnAuthoritysModel from '../columnAuthority/ColumnAuthoritysModel'
import moment from 'moment';
import { Util, dayFormat } from 'tools/index';
import ExecuteMessage from './ExecuteMessage.jsx'

let user;
const { Search } = Input;
const { Option } = Select;
const confirm = Modal.confirm;
const { TextArea } = Input;
let messageServer;

class TestMessage extends Component {
    constructor(props) {
        messageServer = window.sessionStorage.messageServer ? JSON.parse(window.sessionStorage.messageServer) : {}
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        super(props);
        var date = new Date()
        this.state = {
          admDateFrom: moment(date).subtract(1, 'months').format('YYYY-MM-DD'),
          admDateTo: moment(date).format('YYYY-MM-DD'),
          keywords: '',
          visible: false,
          size: 'small',
          messageList: [],
          messageDetail: {},
          newMsg: [],
          readFinish: true,
          readMessageIndex: -1,
          RecordColums: [],
          dataSource: [],
          columns: [],
          search: 'search',
          page: 1,
          pageSize: 10,
          total: 0,
          patientInfo: {},
          messageImportanceArr: [],
          messageEventArr: [],
          messageEventCode:"",
          messageStatusArr: [],
          activeKey: '',
          ENObj: {},
          CNObj: {},
          languageObj: {},
          totalWidth: '',
          messageInfo:"",
          toUser:""
        };
      }

      componentDidMount() {    
        this.getBaseData()
      }

      sendMessage = () => {
        let data = {
            params: [{
                message:this.state.messageInfo,
                toUser:this.state.toUser,
                eventCode:this.state.messageEventCode,
                otherInfo:"1111",
            }],
          }
          $http.post('urlDeault', this, {
            code: "04180011",
            data: data,
            success: (res) => {
              if (+res.errorCode === 0) {
                message.success("发送成功")
              }
            }
          })
      }


      getBaseData = () => {
        let data = {
          params: [{
    
          }],
        }
        $http.post('urlDeault', this, {
          code: "04180008",
          data: data,
          success: (res) => {
            if (+res.errorCode === 0) {
              this.setState({
                messageImportanceArr: res.result.MessageImportanceArr,
                messageEventArr: res.result.MessageEventArr,
                messageStatusArr: res.result.MessageStatusArr,
              })
            }
          }
        })
      }

        changeInfo = (e) =>{
        this.setState({
            messageInfo:e.target.value,
        })
        }

        changeUser = (e) =>{
            this.setState({
                toUser:e.target.value,
            })
        }

        //消息类型
        cardTypeChange = (value) => {
            this.setState({
            messageEventCode: value,
            })
        }



      render() {

        let MessageEventArr = [];
        this.state.messageEventArr.map((item) => {
        MessageEventArr.push(
            <Option key={item.code} value={item.code} >
            {item.descripts}
            </Option>
        )
        })

        return  (
            <div>
            发送内容：<Input style={{width:'200px'}}   onChange={this.changeInfo} />
            用户ID：<Input style={{width:'200px'}}   onChange={this.changeUser} />

            消息事件：
            <Select value={this.state.messageEventCode}
            onChange={this.cardTypeChange}
            style={{ width: '120px' }}>
            {MessageEventArr}
            </Select>

            <Button style={{ height: '32px', margin: '5px' }} type="primary" onClick={this.sendMessage.bind(this)}>发送</Button>

              <div>
                <p>发送多条消息是因为他有多个角色></p>
                <p>用户ID  工号 名称</p>
                <p>1	xys	xys</p>
                <p>2	xys002	李宇峰</p>
                <p>3	SZ001	门诊医生</p>
                <p>4	SZ002	门诊收费</p>
                <p>5 SZ003	门诊挂号</p>
                <p>6	SZ004	门诊发药</p>
                <p>7	SZ005	药库</p>
                <p>8	000007	住院医师</p>
                <p>9	000008	住院收费员</p>
                <p>10	000009	住院护士</p>
                <p>11	000003	门诊护士</p>
                <p>12	000004	药品管理员</p>
                <p>13	000005	寒城涧</p>
                <p>14	218	外科住院护士</p>
                <p>16	sz068	物资仓库管员</p>
                <p>17	000010	治疗医生</p>
                <p>18	hlh	凌</p>
                <p>19	000011	康复治疗</p>
                <p>20	000012	理疗室</p>
                <p>21	10086	卡密</p>
              </div>
            </div>
        )
    }

}
export default TestMessage;