wxmlUtil.wxs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /**
  2. * 小数位数
  3. */
  4. var numberOfDecimalPlacesAmount = 0;
  5. /**
  6. * 小数位数
  7. * @param num
  8. */
  9. var setNumberOfDecimalPlacesAmount = function (num) {
  10. numberOfDecimalPlacesAmount = num;
  11. return "ok";
  12. }
  13. /**
  14. * 截取字符串
  15. * @param str
  16. * @param start
  17. * @param end
  18. */
  19. var subStr = function (str, start, end) {
  20. return str.substring(start, end)
  21. }
  22. /**
  23. * 转成字符串
  24. * @param number
  25. */
  26. var toLocaleString = function (number) {
  27. number = number.toFixed(numberOfDecimalPlacesAmount);
  28. var arr = number.split('.')
  29. return parseInt(arr[0]).toLocaleString() + '.' + arr[1]
  30. }
  31. /**
  32. * 格式化日期
  33. * @param time
  34. */
  35. var format = function (time) {
  36. if (!time || time == '') {
  37. return ''
  38. }
  39. var date = getDate(time);
  40. var year = date.getFullYear()
  41. var month = date.getMonth() + 1
  42. var day = date.getDate()
  43. return year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  44. }
  45. var formatDateTime = function (time) {
  46. if (!time || time == '') {
  47. return ''
  48. }
  49. var date = getDate(time);
  50. var year = date.getFullYear()
  51. var month = date.getMonth() + 1
  52. var day = date.getDate()
  53. var hour = date.getHours()
  54. var minute = date.getMinutes()
  55. // var second = date.getSeconds()
  56. return year + '-' + month + '-' + day + ' ' + hour + ':' + minute
  57. }
  58. var formatDate = function (time) {
  59. if (!time || time == '') {
  60. return ''
  61. }
  62. var date = getDate(time);
  63. var year = date.getFullYear()
  64. var month = date.getMonth() + 1
  65. var day = date.getDate()
  66. return year + '-' + month + '-' + day
  67. }
  68. /**
  69. * json
  70. * @param str
  71. */
  72. var parse = function (str) {
  73. if (str == '') return str;
  74. return JSON.parse(str);
  75. }
  76. /**
  77. * 截取日期
  78. * @param str
  79. * @param start
  80. * @param end
  81. */
  82. var dateFormat = function (str, start, end) {
  83. if (!str) return ''
  84. return str.substring(start, end);
  85. }
  86. /**
  87. * 获取类型
  88. * @param item
  89. */
  90. var getType = function (item) {
  91. if (item.BOMID && item.BOMID != 0) {
  92. return "blue"
  93. } else if (item.CustomFlag == 1) {
  94. return ""
  95. } else {
  96. return ""
  97. }
  98. }
  99. /**
  100. * 价格和金额
  101. * @param num
  102. */
  103. var jsCalcFix2 = function (num) {
  104. return parseFloat(num + "").toFixed(numberOfDecimalPlacesAmount)
  105. }
  106. /**
  107. * 判断str中是否含有val
  108. * @param str
  109. * @param val
  110. */
  111. var defineIndexOf = function (str, val) {
  112. if (str != null) {
  113. return str.indexOf(val);
  114. }
  115. }
  116. var addressFullIsUndefined = function (addressFull) {
  117. if (addressFull && (addressFull.indexOf('undefined') != -1)) {
  118. return addressFull.replace("undefined", "") ? addressFull.replace("undefined", "") : ''
  119. } else {
  120. return addressFull ? addressFull : ''
  121. }
  122. }
  123. //地址出现undefined null NaN(目前只能替换一个 每种)
  124. function addressToIndexOf(str) {
  125. // console.log('地址出现undefined',typeof str)
  126. if (typeof str == 'string') {
  127. if (str != null && str != '') {
  128. return str = str.replace('undefined', '').replace('null', '').replace('NaN', '') ? str.replace('undefined', '').replace('null', '').replace('NaN', '') : ''
  129. }
  130. }
  131. }
  132. /**
  133. * @desc : 设置值
  134. * @author : 周兴
  135. * @date : 2024/1/26 11:46
  136. */
  137. function setItemValue(item, colName) {
  138. var value = ''
  139. if (typeof colName == 'object') {
  140. var count = colName.length;
  141. for (i = 0; i < count; i++) {
  142. value += colName[i].title + (item[colName[i].name] ? item[colName[i].name] : '')
  143. + (item[colName[i].name] ? ' | ' : '');
  144. }
  145. if (value) {
  146. value = value.substring(0, value.length - 3);
  147. }
  148. } else {
  149. value = item[colName]!=null ? item[colName] : '';
  150. }
  151. return value;
  152. }
  153. /**
  154. * @desc : 设置底部值
  155. * @author : 周兴
  156. * @date : 2024/1/26 11:46
  157. */
  158. function setFooterItemValue(item, colName) {
  159. var value = ''
  160. if (typeof colName == 'object') {
  161. var count = colName.length;
  162. for (i = 0; i < count; i++) {
  163. // 如果前缀有值就显示
  164. if (colName[i].prefix) {
  165. //控制参数为0 等于自定义参数
  166. if (colName[i].different && item[colName[i].name] == 0) {
  167. value += colName[i].different
  168. } else {
  169. value += colName[i].prefix + ' ' + (item[colName[i].name] ? item[colName[i].name] : '') + ' ' + colName[i].title;
  170. }
  171. } else {
  172. value += (item[colName[i].name] ? item[colName[i].name] : '') + colName[i].title;
  173. }
  174. }
  175. } else {
  176. value = item[colName] ? item[colName]: '';
  177. }
  178. return value.indexOf('NaN') < 0 ? value : '';
  179. }
  180. /**
  181. * @desc : 设置查询提示值
  182. * @author : 周兴
  183. * @date : 2024/1/26 11:46
  184. */
  185. function setSearchPlaceholder(lang, cols) {
  186. var text = '';
  187. if (typeof cols == 'object') {
  188. for (i = 0; i < cols.length; i++) {
  189. text += lang[cols[i]] + '/';
  190. }
  191. text = text.substring(0, text.length - 1);
  192. } else {
  193. text = lang[cols];
  194. }
  195. return lang['search'] + ' ' + text;
  196. }
  197. /**
  198. * @desc : 设置提示信息
  199. * @author : 周兴
  200. * @date : 2024/1/26 11:46
  201. */
  202. function setPlaceholder(lang, name, searchFlag = false) {
  203. var text;
  204. if (lang[name]) {
  205. text = lang[name];
  206. } else {
  207. text = name;
  208. }
  209. if (searchFlag) {
  210. text = lang['searchWords'] + text;
  211. } else {
  212. text = lang['inputWords'] + text;
  213. }
  214. return text;
  215. }
  216. /**
  217. * @desc : 前台实现千分位
  218. * @date : 2024/2/18 16:49
  219. * @author : 周兴
  220. */
  221. function toThousandCents(num) {
  222. if (num == undefined) {
  223. return 0;
  224. }
  225. var num = num + '';
  226. var d = '';
  227. if (num.slice(0, 1) == '-') {
  228. d = num.slice(0, 1);
  229. num = num.slice(1);
  230. }
  231. var len = num.length;
  232. var index = num.indexOf('.');
  233. if (index == -1) {
  234. num = num + '.00';
  235. } else if ((index + 2) == len) {
  236. num = num + '0';
  237. }
  238. var index = num.indexOf('.'); // 字符出现的位置
  239. var num2 = num.slice(-3);
  240. num = num.slice(0, index)
  241. var result = '';
  242. while (num.length > 3) {
  243. result = ',' + num.slice(-3) + result;
  244. num = num.slice(0, num.length - 3);
  245. }
  246. if (num) {
  247. result = num + result;
  248. }
  249. return d + (result + num2)
  250. }
  251. /**
  252. * @desc : 向上取整
  253. * @date : 2024/2/18 16:49
  254. * @author : 周兴
  255. */
  256. function ceiling(val) {
  257. var value = parseInt(val);
  258. if (val > value) {
  259. value = value + 1
  260. }
  261. return value
  262. }
  263. /**
  264. * 暴露接口调用
  265. */
  266. module.exports = {
  267. ceiling: ceiling,
  268. toThousandCents: toThousandCents,
  269. setItemValue: setItemValue,
  270. setFooterItemValue: setFooterItemValue,
  271. setSearchPlaceholder: setSearchPlaceholder,
  272. setPlaceholder: setPlaceholder,
  273. addressToIndexOf: addressToIndexOf,
  274. addressFullIsUndefined: addressFullIsUndefined,
  275. setNumberOfDecimalPlacesAmount: setNumberOfDecimalPlacesAmount,
  276. toLocaleString: toLocaleString,
  277. subStr: subStr,
  278. format: format,
  279. parse: parse,
  280. dateFormat: dateFormat,
  281. getType: getType,
  282. jsCalcFix2: jsCalcFix2,
  283. defineIndexOf: defineIndexOf,
  284. formatDateTime: formatDateTime,
  285. formatDate:formatDate
  286. }