helper.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import * as config from '../config'
  2. const selectContractNo = {}
  3. const detailData = {}
  4. const erpWarehouse = {}
  5. const rolesList = []
  6. const now = Date.now || function() {
  7. return new Date().getTime();
  8. };
  9. const isArray = Array.isArray || function(obj) {
  10. return obj instanceof Array;
  11. };
  12. const getListByUserId = function() {
  13. let baseUrlNew = config.def().baseUrlNew
  14. var userInfo = uni.getStorageSync("userInfo")
  15. console.log("------", userInfo)
  16. if (userInfo) {
  17. uni.request({
  18. url: baseUrlNew + '/roleMenu/query/getListByUserId',
  19. data: {
  20. userId: userInfo.id ? userInfo.id : userInfo.data.id
  21. },
  22. method: 'GET',
  23. success: (res) => {
  24. if (res.statusCode === 200) {
  25. uni.setStorageSync("jurisdiction", res.data.data)
  26. let list = getUserAllRoles(res.data.data);
  27. uni.setStorageSync("rolesList", list)
  28. }
  29. }
  30. })
  31. }
  32. }
  33. const getUserAllRoles = (item) => {
  34. console.log(item)
  35. for (let i = 0; i < item.length; i++) {
  36. rolesList.push(item[i].name)
  37. // console.log('用户权限',rolesList)
  38. if (item[i].children && item[i].children.length > 0) {
  39. getUserAllRoles(item[i].children)
  40. }
  41. }
  42. return rolesList;
  43. }
  44. const setAudit = (item) => {
  45. let _list = uni.getStorageSync("copyTaskInfo")
  46. let _isShowbtn = true
  47. if (_list.length == 0) {
  48. _isShowbtn = false
  49. }
  50. for (let i = 0; i < _list.length; i++) {
  51. if (_list[i].businessId == item.id) {
  52. _list.splice(i, 1)
  53. uni.setStorageSync("copyTaskInfo", _list)
  54. }
  55. }
  56. if (_list.length > 0) {
  57. uni.navigateTo({
  58. url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn,
  59. })
  60. }
  61. console.log(item)
  62. }
  63. //获取当天日期
  64. const getNowFormatDate = () => {
  65. var date = new Date();
  66. var seperator1 = "-";
  67. var year = date.getFullYear();
  68. var month = date.getMonth() + 1;
  69. var strDate = date.getDate();
  70. if (month >= 1 && month <= 9) {
  71. month = "0" + month;
  72. }
  73. if (strDate >= 0 && strDate <= 9) {
  74. strDate = "0" + strDate;
  75. }
  76. var currentdate = year + seperator1 + month + seperator1 + strDate;
  77. return currentdate;
  78. }
  79. const convertCurrency = (money) => {
  80. //汉字的数字
  81. var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
  82. //基本单位
  83. var cnIntRadice = new Array('', '拾', '佰', '仟');
  84. //对应整数部分扩展单位
  85. var cnIntUnits = new Array('', '万', '亿', '兆');
  86. //对应小数部分单位
  87. var cnDecUnits = new Array('角', '分', '毫', '厘');
  88. //整数金额时后面跟的字符
  89. var cnInteger = '整';
  90. //整型完以后的单位
  91. var cnIntLast = '元';
  92. //最大处理的数字
  93. var maxNum = 999999999999999.9999;
  94. //金额整数部分
  95. var integerNum;
  96. //金额小数部分
  97. var decimalNum;
  98. //输出的中文金额字符串
  99. var chineseStr = '';
  100. //分离金额后用的数组,预定义
  101. var parts;
  102. if (money == '') {
  103. return '';
  104. }
  105. money = parseFloat(money);
  106. if (money >= maxNum) {
  107. //超出最大处理数字
  108. return '';
  109. }
  110. if (money == 0) {
  111. chineseStr = cnNums[0] + cnIntLast + cnInteger;
  112. return chineseStr;
  113. }
  114. //转换为字符串
  115. money = money.toString();
  116. if (money.indexOf('.') == -1) {
  117. integerNum = money;
  118. decimalNum = '';
  119. } else {
  120. parts = money.split('.');
  121. integerNum = parts[0];
  122. decimalNum = parts[1].substr(0, 4);
  123. }
  124. //获取整型部分转换
  125. if (parseInt(integerNum, 10) > 0) {
  126. var zeroCount = 0;
  127. var IntLen = integerNum.length;
  128. for (var i = 0; i < IntLen; i++) {
  129. var n = integerNum.substr(i, 1);
  130. var p = IntLen - i - 1;
  131. var q = p / 4;
  132. var m = p % 4;
  133. if (n == '0') {
  134. zeroCount++;
  135. } else {
  136. if (zeroCount > 0) {
  137. chineseStr += cnNums[0];
  138. }
  139. //归零
  140. zeroCount = 0;
  141. chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
  142. }
  143. if (m == 0 && zeroCount < 4) {
  144. chineseStr += cnIntUnits[q];
  145. }
  146. }
  147. chineseStr += cnIntLast;
  148. }
  149. //小数部分
  150. if (decimalNum != '') {
  151. var decLen = decimalNum.length;
  152. for (var i = 0; i < decLen; i++) {
  153. var n = decimalNum.substr(i, 1);
  154. if (n != '0') {
  155. chineseStr += cnNums[Number(n)] + cnDecUnits[i];
  156. }
  157. }
  158. }
  159. if (chineseStr == '') {
  160. chineseStr += cnNums[0] + cnIntLast + cnInteger;
  161. } else if (decimalNum == '') {
  162. chineseStr += cnInteger;
  163. }
  164. return chineseStr;
  165. }
  166. export default {
  167. detailData,
  168. selectContractNo,
  169. now,
  170. isArray,
  171. erpWarehouse,
  172. getListByUserId,
  173. setAudit,
  174. getNowFormatDate,
  175. convertCurrency
  176. }