import React from "react";
import $ from "jquery/src/ajax";
import "react-quill/dist/quill.bubble.css";
import moment from "moment";
import "../authentication/techDemand.less";
import {
  Form,
  Button,
  message,
} from "antd";
import {
  beforeUploadFile,
} from "@/tools.js";
import Editors from "@/richTextEditors";

//主体
const Setting = Form.create()(
  React.createClass({

    getInitialState() {
      return {
        content: "",
      };
    },
    // 初始化数据
    loadData() {
      //发送请求
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/getSysConfig",
        data: {
          id: 100
        },
        success: function (data) {
          if (data.error.length == 0) {
            this.setState({
              content: data.data.content
            });
          } else {
            message.warning(data.error[0].message)
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },

    // 编辑声明
    edit() {
      this.setState({
        loading: true,
      });
      $.ajax({
        method: "post",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/updateSysConfig",
        data: {
          id: 100,
          content: this.state.content,
        },
        success: function (data) {
          this.setState({
            loading: false,
          });
          if (data.error && data.error.length) {
            message.warning(data.error[0].message);
          }else{
            message.success("修改成功！")
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },

    componentWillMount() {
      this.loadData();
    },

    render() {
      return (
        <div className="user-content">
          <div className="content-title">
            <span>本站声明设置</span>
            <div style={{ width: 800, marginTop: 20 }}>
              <Editors
                textContent={this.state.content}
                uploadUrl={"/api/admin/news/uploadFile"}
                globalConfig={globalConfig.uploadPath}
                placeholder=""
                handleRichText={(value) => {
                  this.setState({ content: value });
                }}
              />
              <Button
                type="primary"
                onClick={this.edit}
                style={{ margin: "50px 0 20px 360px" }}
              >
                保存更改
              </Button>
              <div style={{ color: "red" }}>提示：本站声明，显示在新闻底部，一旦修改，将整站全部修改！！！</div>
            </div>
          </div>
        </div>
      );
    },
  })
);

export default Setting;
