
import { observable, action } from 'mobx';
import * as API from '../apis/index';
import loadjs from 'loadjs';

class ApiDocCheck {
  @observable data = '';
  @observable testRes = '';
  @observable treeData = [];
  @observable defaultKey = '';

  @action
  getmarkapi = (params) => {
    // loadjs('../tree,json','res')
    // loadjs.ready('res', function() {
    //   const testRes = {"code":0,"data":"## API标题 ##\n\n### 概述\n\n>\n\n### 请求方式\n\n>GET\n\n### 请求地址\n\n>/api/doc/console/category/info/remind/message\n\n### 请求参数说明\n\n参数名 | 类型 | 描述 \n-|-|-\n__random__|String|\nbodymsg|String|\nid|String|\n### 返回值类型\n\n>json\n\n### 返回示例\n\n```json\n{\"fieldListOptions\":[{\"disabled\":false,\"key\":\"$DOC_SecCategory\",\"selected\":false,\"showname\":\"文档目录-$DOC_SecCategory\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Department\",\"selected\":false,\"showname\":\"创建人部门-$DOC_Department\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Content\",\"selected\":false,\"showname\":\"文档内容-$DOC_Content\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_CreatedByFull\",\"selected\":false,\"showname\":\"创建人名称-$DOC_CreatedByFull\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_CreatedDate\",\"selected\":false,\"showname\":\"创建日期-$DOC_CreatedDate\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_ModifiedDate\",\"selected\":false,\"showname\":\"最后的修改日期-$DOC_ModifiedDate\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Status\",\"selected\":false,\"showname\":\"文档的状态(草稿,打开,正常,归档)-$DOC_Status\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Subject\",\"selected\":false,\"showname\":\"文档标题-$DOC_Subject\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Publish\",\"selected\":false,\"showname\":\"发布状态(正常,新闻,标题新闻)-$DOC_Publish\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_ApproveDate\",\"selected\":false,\"showname\":\"审批日期-$DOC_ApproveDate\",\"visible\":true}],\"bodymsg\":\"您有新的待阅文档《$DOC_Subject》，请查阅\",\"api_status\":true}\n```\n\n### 注意事项\n\n\n\n","msgShowType":"none","status":true}
    //   if (res.data) {
    //     this.data = res.data;
    //     this.testRes = testRes.data;
    //     this.defaultKey = res.data.currentModule
    //   }
    // });
    // API.getapijson(params).then(res => {
    //   const testRes = {"code":0,"data":"## API标题 ##\n\n### 概述\n\n>\n\n### 请求方式\n\n>GET\n\n### 请求地址\n\n>/api/doc/console/category/info/remind/message\n\n### 请求参数说明\n\n参数名 | 类型 | 描述 \n-|-|-\n__random__|String|\nbodymsg|String|\nid|String|\n### 返回值类型\n\n>json\n\n### 返回示例\n\n```json\n{\"fieldListOptions\":[{\"disabled\":false,\"key\":\"$DOC_SecCategory\",\"selected\":false,\"showname\":\"文档目录-$DOC_SecCategory\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Department\",\"selected\":false,\"showname\":\"创建人部门-$DOC_Department\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Content\",\"selected\":false,\"showname\":\"文档内容-$DOC_Content\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_CreatedByFull\",\"selected\":false,\"showname\":\"创建人名称-$DOC_CreatedByFull\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_CreatedDate\",\"selected\":false,\"showname\":\"创建日期-$DOC_CreatedDate\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_ModifiedDate\",\"selected\":false,\"showname\":\"最后的修改日期-$DOC_ModifiedDate\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Status\",\"selected\":false,\"showname\":\"文档的状态(草稿,打开,正常,归档)-$DOC_Status\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Subject\",\"selected\":false,\"showname\":\"文档标题-$DOC_Subject\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_Publish\",\"selected\":false,\"showname\":\"发布状态(正常,新闻,标题新闻)-$DOC_Publish\",\"visible\":true},{\"disabled\":false,\"key\":\"$DOC_ApproveDate\",\"selected\":false,\"showname\":\"审批日期-$DOC_ApproveDate\",\"visible\":true}],\"bodymsg\":\"您有新的待阅文档《$DOC_Subject》，请查阅\",\"api_status\":true}\n```\n\n### 注意事项\n\n\n\n","msgShowType":"none","status":true}
    //   if (res.data) {
    //     this.data = res.data;
    //     this.testRes = testRes.data;
    //     this.defaultKey = res.data.currentModule
    //   }
    // });
      const testRes = { code: 0, data: '## API标题 ##\n\n### 概述\n\n>\n\n### 请求方式\n\n>GET\n\n### 请求地址\n\n>/api/doc/console/category/info/remind/message\n\n### 请求参数说明\n\n参数名 | 类型 | 描述 \n-|-|-\n__random__|String|\nbodymsg|String|\nid|String|\n### 返回值类型\n\n>json\n\n### 返回示例\n\n```json\n{"fieldListOptions":[{"disabled":false,"key":"$DOC_SecCategory","selected":false,"showname":"文档目录-$DOC_SecCategory","visible":true},{"disabled":false,"key":"$DOC_Department","selected":false,"showname":"创建人部门-$DOC_Department","visible":true},{"disabled":false,"key":"$DOC_Content","selected":false,"showname":"文档内容-$DOC_Content","visible":true},{"disabled":false,"key":"$DOC_CreatedByFull","selected":false,"showname":"创建人名称-$DOC_CreatedByFull","visible":true},{"disabled":false,"key":"$DOC_CreatedDate","selected":false,"showname":"创建日期-$DOC_CreatedDate","visible":true},{"disabled":false,"key":"$DOC_ModifiedDate","selected":false,"showname":"最后的修改日期-$DOC_ModifiedDate","visible":true},{"disabled":false,"key":"$DOC_Status","selected":false,"showname":"文档的状态(草稿,打开,正常,归档)-$DOC_Status","visible":true},{"disabled":false,"key":"$DOC_Subject","selected":false,"showname":"文档标题-$DOC_Subject","visible":true},{"disabled":false,"key":"$DOC_Publish","selected":false,"showname":"发布状态(正常,新闻,标题新闻)-$DOC_Publish","visible":true},{"disabled":false,"key":"$DOC_ApproveDate","selected":false,"showname":"审批日期-$DOC_ApproveDate","visible":true}],"bodymsg":"您有新的待阅文档《$DOC_Subject》，请查阅","api_status":true}\n```\n\n### 注意事项\n\n\n\n', msgShowType: 'none', status: true };
    loadjs.isDefined(params.id) ? loadjs.ready(params.id, () => {
      if (window[`data${params.id}`]) {
        this.testRes = testRes.data;
        this.data = window[`data${params.id}`];
      }
    }) : loadjs(`../context/${params.id}.js`, params.id, () => {
      if (window[`data${params.id}`]) {
        this.testRes = testRes.data;
        this.data = window[`data${params.id}`];
      }
    });


    // loadjs.ready('context', function() {
    //   if (window['data' + params.id]) {
    //     // this.defaultKey = window.tree.currentModule
    //     // this.treeData = window.tree
    //     this.testRes = testRes.data;
    //     this.data = window['data' + params.id];
    //   }
    // }.bind(this));
  }

  @action
  getTreeData = (params) => {
    // API.getTreeData(params).then(action(res => {
    //   if (res.datas) {
    //     this.defaultKey = res.currentModule
    //     this.treeData = res.datas
    //   }
    // }));
    // $.getJSON('../tree.js', (res) => {
    //   if (res.data) {
    //     this.defaultKey = res.currentModule
    //     this.treeData = res.datas
    //   }
    // })
    loadjs('../tree.js', 'res');
    // loadjs('../context.js','context')

    loadjs.ready('res', () => {
      if (window.tree) {
        this.treeData = window.tree;
        this.defaultKey = window.tree[0].domid;
        // alert(window.tree[0].domid)
      }
    });
  }
}

export default ApiDocCheck;
