import { observable, action } from 'mobx';
import * as API from '../apis/NC';
import {checkNonstandard} from '../util/IntegrationUtil';

export default class NCStore{
  @observable hasRight=false;
  @observable rightLoading= true;
  @observable menuList = [];
  @observable mainTitle = [];
  @observable routeUrl = '';
  @observable nonStandLoading = true;
  @observable hasNonStandard = true;

  @action getMenuList = (params) => {
    this.nonStandLoading = true;
    let num = "";
    if(params.groupid == '1') {
      num = "067";
    }else if(params.groupid == '2') {
      num = "068";
    }else if(params.groupid == '3') {
      num = "069";
    }else if(params.groupid == '4') {
      num = "070";
    }
    checkNonstandard({num}, (result) => {
      this.hasNonStandard = result.isOpen;
      this.nonStandLoading = false;
      if(result.isOpen) {
        API.getMenuList(params).then(result => {
          if(result.flag == 'success'){
            this.menuList = result.menuList;
            this.mainTitle = result.mainTitle;
            if(this.menuList&&this.menuList.length) {
                this.routeUrl = this.menuList[0].routeUrl+'?from=productEntrance&typename='+params.groupid;
            }
            this.hasRight=true;
          }else{
            this.hasRight = false;
          }
          this.rightLoading = false;
        })
      }
    })
  }

  @action changeUrl = (url) => this.routeUrl = url
}