/*
 * Author: 黎永顺
 * Description: 编号设置
 * Date: 2022-06-07 09:54:46
 * LastEditTime: 2022-06-15 13:09:28
 */
import { observable, action } from "mobx";
import { WeaForm } from "comsMobx";
import { WeaTableNew } from "comsMobx";
import * as mobx from "mobx";
import * as API from "../apis/numberSet"; // 引入API接口文件

const { TableStore } = WeaTableNew;

export class NumberSetStore {
  @observable searchCondition = []; //高级搜索框form数据
  @observable tableStore = new TableStore(); //列表store
  @observable form = new WeaForm(); //高级搜索渲染的表单
  @observable condition = []; //新增职务信息form数据
  @observable reservedForm = new WeaForm(); //新增预留编号表单

  @action("高级搜索表单渲染")
  getAdvanceSearchCondition() {
    API.getAdvanceSearchCondition().then(({ api_status, conditions }) => {
      if (api_status && !_.isEmpty(conditions)) {
        this.setSearchCondition(conditions);
        this.form.initFormFields(conditions);
      }
    });
  }

  @action("获取表格数据")
  getSearchReservedCodeList(params) {
    const payload = {
      ...this.form.getFormParams(),
      ...params,
    };
    API.getSearchReservedCodeList(payload).then(
      ({ api_status, sessionkey }) => {
        if (api_status && !_.isEmpty(sessionkey)) {
          this.tableStore.getDatas(sessionkey, 1);
        }
      }
    );
  }

  @action("新增预留编号表单查询")
  getReservedCodeFrom(payload) {
    return API.getReservedCodeFrom(payload).then(({ api_status, conditioninfo }) => {
      if (api_status && !_.isEmpty(conditioninfo)) {
        conditioninfo.map((c) =>
          c.items.map((item) => {
            if (item.domkey[0] == "YEAR") {
              item.value = item.value.toString();
            }
          })
        );
        this.setCondition(conditioninfo);
        this.reservedForm.initFormFields(conditioninfo);
      }
    });
  }
  @action
  setCondition(condition) {
    this.condition = condition;
  }

  @action
  setSearchCondition(condition) {
    this.searchCondition = condition;
  }

  @action
  getCodeSetting(params) {
    return API.getCodeSetting(params);
  }

  @action
  saveOrUpdateCodeSetting(params) {
    return API.saveOrUpdateCodeSetting(params);
  }

  @action
  getStartNumForm(params) {
    return API.getStartNumForm(params);
  }

  @action
  saveStartNum(params) {
    return API.saveStartNum(params);
  }

  @action("删除预留编号")
  deleteReservedCodeById(params) {
    return API.deleteReservedCodeById(params);
  }

  @action("保存预留编号")
  saveReservedCode(params) {
    return API.saveReservedCode(params);
  }
}