import { observable, action, toJS } from 'mobx';
import * as API from './../apis/elseSetting.js';
import { authorized } from '../apis/common.js';
import { WeaForm } from 'comsMobx'
import { message } from 'antd';
//gai
export class ElseSettingStore {
	@observable containerInitFinished = {};
	init = () => {
		this.getFormdata();
		authorized('accountcenter/othersettings').then(data => {
			if (data.status === '1') {
				this.containerInitFinished = {
					init: true,
					authorized: data.hasRightOtherSettings || data.hasRightNetworkSegmentStrategy || data.hasDBSettings
				}
			}
		}, error => {
			this.containerInitFinished = {
				init: true,
				authorized: false
			}
		})
	}
	@observable Form = new WeaForm();
	@observable FormField = [];
	@action getFormdata = () => {
		this.Form = new WeaForm();
		API.getelseSettingForm().then(data => {
			if (data && data.formField) {
				this.FormField = toJS(data.formField);
				this.Form.initFormFields(this.FormField);
			}
		})
	}
	@action save = () => {
		const param = this.Form.getFormParams();
		API.save(param).then(data => {
			if (data && data.status == '1') {
				message.success('保存成功');
			}
		});
	}

}