import { get } from 'lodash';
/**
 * 输出至视图的格式化基类
 */
export class VOBase {
  constructor(response: object) {
    this.errcode = get(response, 'errcode', 0);
    this.errmsg = get(response, 'errmsg', 'ok');
    this.details = get(response, 'details');
    this.total = get(response, 'total');
    // 查询列表和只返回结果的区分,根据total决定
    if (this.total || this.total === 0) {
      this.data = get(response, 'data');
    } else {
      this.data = response;
    }
  }
  errcode: number;
  errmsg: string;
  details?: string;
  data?: any;
  total?: number;
}
/**处理VO */
export const dealVO = (cla, data) => {
  for (const key in cla) {
    const val = get(data, key);
    if (val || val === 0) cla[key] = val;
  }
};
