| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- /**
- * 小数位数
- */
- var numberOfDecimalPlacesAmount = 0;
- /**
- * 小数位数
- * @param num
- */
- var setNumberOfDecimalPlacesAmount = function (num) {
- numberOfDecimalPlacesAmount = num;
- return "ok";
- }
- /**
- * 截取字符串
- * @param str
- * @param start
- * @param end
- */
- var subStr = function (str, start, end) {
- return str.substring(start, end)
- }
- /**
- * 转成字符串
- * @param number
- */
- var toLocaleString = function (number) {
- number = number.toFixed(numberOfDecimalPlacesAmount);
- var arr = number.split('.')
- return parseInt(arr[0]).toLocaleString() + '.' + arr[1]
- }
- /**
- * 格式化日期
- * @param time
- */
- var format = function (time) {
- if (!time || time == '') {
- return ''
- }
- var date = getDate(time);
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- return year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
- }
- var formatDateTime = function (time) {
- if (!time || time == '') {
- return ''
- }
- var date = getDate(time);
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var minute = date.getMinutes()
- // var second = date.getSeconds()
- return year + '-' + month + '-' + day + ' ' + hour + ':' + minute
- }
- var formatDate = function (time) {
- if (!time || time == '') {
- return ''
- }
- var date = getDate(time);
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- return year + '-' + month + '-' + day
- }
- /**
- * json
- * @param str
- */
- var parse = function (str) {
- if (str == '') return str;
- return JSON.parse(str);
- }
- /**
- * 截取日期
- * @param str
- * @param start
- * @param end
- */
- var dateFormat = function (str, start, end) {
- if (!str) return ''
- return str.substring(start, end);
- }
- /**
- * 获取类型
- * @param item
- */
- var getType = function (item) {
- if (item.BOMID && item.BOMID != 0) {
- return "blue"
- } else if (item.CustomFlag == 1) {
- return ""
- } else {
- return ""
- }
- }
- /**
- * 价格和金额
- * @param num
- */
- var jsCalcFix2 = function (num) {
- return parseFloat(num + "").toFixed(numberOfDecimalPlacesAmount)
- }
- /**
- * 判断str中是否含有val
- * @param str
- * @param val
- */
- var defineIndexOf = function (str, val) {
- if (str != null) {
- return str.indexOf(val);
- }
- }
- var addressFullIsUndefined = function (addressFull) {
- if (addressFull && (addressFull.indexOf('undefined') != -1)) {
- return addressFull.replace("undefined", "") ? addressFull.replace("undefined", "") : ''
- } else {
- return addressFull ? addressFull : ''
- }
- }
- //地址出现undefined null NaN(目前只能替换一个 每种)
- function addressToIndexOf(str) {
- // console.log('地址出现undefined',typeof str)
- if (typeof str == 'string') {
- if (str != null && str != '') {
- return str = str.replace('undefined', '').replace('null', '').replace('NaN', '') ? str.replace('undefined', '').replace('null', '').replace('NaN', '') : ''
- }
- }
- }
- /**
- * @desc : 设置值
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function setItemValue(item, colName) {
- var value = ''
- if (typeof colName == 'object') {
- var count = colName.length;
- for (i = 0; i < count; i++) {
- value += colName[i].title + (item[colName[i].name] ? item[colName[i].name] : '')
- + (item[colName[i].name] ? ' | ' : '');
- }
- if (value) {
- value = value.substring(0, value.length - 3);
- }
- } else {
- value = item[colName]!=null ? item[colName] : '';
- }
- return value;
- }
- /**
- * @desc : 设置底部值
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function setFooterItemValue(item, colName) {
- var value = ''
- if (typeof colName == 'object') {
- var count = colName.length;
- for (i = 0; i < count; i++) {
- // 如果前缀有值就显示
- if (colName[i].prefix) {
- //控制参数为0 等于自定义参数
- if (colName[i].different && item[colName[i].name] == 0) {
- value += colName[i].different
- } else {
- value += colName[i].prefix + ' ' + (item[colName[i].name] ? item[colName[i].name] : '') + ' ' + colName[i].title;
- }
- } else {
- value += (item[colName[i].name] ? item[colName[i].name] : '') + colName[i].title;
- }
- }
- } else {
- value = item[colName] ? item[colName]: '';
- }
- return value.indexOf('NaN') < 0 ? value : '';
- }
- /**
- * @desc : 设置查询提示值
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function setSearchPlaceholder(lang, cols) {
- var text = '';
- if (typeof cols == 'object') {
- for (i = 0; i < cols.length; i++) {
- text += lang[cols[i]] + '/';
- }
- text = text.substring(0, text.length - 1);
- } else {
- text = lang[cols];
- }
- return lang['search'] + ' ' + text;
- }
- /**
- * @desc : 设置提示信息
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function setPlaceholder(lang, name, searchFlag = false) {
- var text;
- if (lang[name]) {
- text = lang[name];
- } else {
- text = name;
- }
- if (searchFlag) {
- text = lang['searchWords'] + text;
- } else {
- text = lang['inputWords'] + text;
- }
- return text;
- }
- /**
- * @desc : 前台实现千分位
- * @date : 2024/2/18 16:49
- * @author : 周兴
- */
- function toThousandCents(num) {
- if (num == undefined) {
- return 0;
- }
- var num = num + '';
- var d = '';
- if (num.slice(0, 1) == '-') {
- d = num.slice(0, 1);
- num = num.slice(1);
- }
- var len = num.length;
- var index = num.indexOf('.');
- if (index == -1) {
- num = num + '.00';
- } else if ((index + 2) == len) {
- num = num + '0';
- }
- var index = num.indexOf('.'); // 字符出现的位置
- var num2 = num.slice(-3);
- num = num.slice(0, index)
- var result = '';
- while (num.length > 3) {
- result = ',' + num.slice(-3) + result;
- num = num.slice(0, num.length - 3);
- }
- if (num) {
- result = num + result;
- }
- return d + (result + num2)
- }
- /**
- * @desc : 向上取整
- * @date : 2024/2/18 16:49
- * @author : 周兴
- */
- function ceiling(val) {
- var value = parseInt(val);
- if (val > value) {
- value = value + 1
- }
- return value
- }
- /**
- * 暴露接口调用
- */
- module.exports = {
- ceiling: ceiling,
- toThousandCents: toThousandCents,
- setItemValue: setItemValue,
- setFooterItemValue: setFooterItemValue,
- setSearchPlaceholder: setSearchPlaceholder,
- setPlaceholder: setPlaceholder,
- addressToIndexOf: addressToIndexOf,
- addressFullIsUndefined: addressFullIsUndefined,
- setNumberOfDecimalPlacesAmount: setNumberOfDecimalPlacesAmount,
- toLocaleString: toLocaleString,
- subStr: subStr,
- format: format,
- parse: parse,
- dateFormat: dateFormat,
- getType: getType,
- jsCalcFix2: jsCalcFix2,
- defineIndexOf: defineIndexOf,
- formatDateTime: formatDateTime,
- formatDate:formatDate
- }
|