import { Spin } from "antd";
import { WeaSwitch } from "comsMobx";
import { WeaAlertPage, WeaFormItem, WeaHelpfulTip, WeaLocaleProvider, WeaSearchGroup } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;
// 获取condition的domKey值
export const getConditionDomkeys = (condition) => {
let domkeyList = [];
_.forEach(condition, item => {
const tmpV = _.reduce(item.items, (pre, cur) => {
return [...pre, cur["domkey"][0]];
}, []);
domkeyList = domkeyList.concat(tmpV);
});
return domkeyList;
};
// 渲染form表单: 一般对form的渲染都统一使用该方法
export const getSearchs = (form, condition, col, isCenter, onChange = () => void (0), title) => {
const { isFormInit } = form;
const formParams = form.getFormParams();
let group = [];
isFormInit && condition && condition.map(c => {
let items = [];
c.items.map(fields => {
items.push({
com: (
{
fields.helpfulTitle &&
}
),
colSpan: 1,
hide: fields.hide
});
});
group.push(
);
});
return group;
};
// 页面加载中效果处理
export const renderLoading = (loading) => (
);
// 无权限处理
export const renderNoright = () => (
{getLabel(2012, "对不起,您暂时没有权限!")}
);
// 暂无数据处理
export const renderNoData = () => (
暂无数据
);
//分页计算
export function calcPageNo(total, pageNo = 1, pageSize = 10, selectDelDataLen = 1) {
const totalPage = Math.ceil((total - selectDelDataLen) / pageSize); // 总页数
pageNo = pageNo > totalPage ? totalPage : pageNo;
pageNo = pageNo < 1 ? 1 : pageNo;
return pageNo;
}
//金额格式化
export const format_with_regex = (number) => {
return !(number + "").includes(".")
? // 就是说1-3位后面一定要匹配3位
(number + "").replace(/\d{1,3}(?=(\d{3})+$)/g, (match) => {
return match + ",";
})
: (number + "").replace(/\d{1,3}(?=(\d{3})+(\.))/g, (match) => {
return match + ",";
});
};
/**
* 打印指定dom内容
* @param printParams
*/
export const printDom = (printParams) => {
const { hideDomId } = printParams;
let hideDom = document.getElementById(hideDomId);
if (hideDom) {
hideDom.style.display = "none";
}
window.print();
if (hideDom) {
hideDom.style.display = "";
}
};
export const getDomkes = (conditions) => {
return _.reduce(conditions, (pre, cur) => ([...pre, ..._.map(cur.items, o => o.domkey[0])]), []);
};
export const padding0 = (num, length) => {
for (let len = ("" + num).length; len < length; len++) {
num = "0" + num;
}
return "0." + num;
};
export const toDecimal_n = (x, num) => {
if (isNaN(parseFloat(x))) return false;
let f = Math.round(x * 100) / 100;
let s = f.toString();
let rs = s.indexOf(".");
if (rs < 0) {
rs = s.length;
s += ".";
}
while (s.length <= rs + num) {
s += "0";
}
return s;
};