tools.blade.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <script type="text/javascript">
  2. //向服务器查询 查询后jump
  3. function form_jump(url, form_data, jump) {
  4. var index = layer.msg('请求服务器中...', {icon: 16, time: 0, shade: 0.5});
  5. jQuery.comm.sendmessage(url, form_data,
  6. data => {
  7. layer.close(index);
  8. // var datax = eval("(" + data + ")");
  9. if (data.code == 200) {
  10. tip_ok();
  11. if (jump != undefined) {
  12. setTimeout(function () {
  13. window.location.href = jump;
  14. }, 1500);
  15. }
  16. } else {
  17. tip_error(data.message);
  18. }
  19. },
  20. //ajax error
  21. data => {
  22. layer.close(index);
  23. tip_error(data.responseText);
  24. });
  25. }
  26. //向服务器查询 查询后执行func
  27. function form_func(url, form_data, func) {
  28. var index = layer.msg('请求服务器中...', {icon: 16, time: 0, shade: 0.5});
  29. jQuery.comm.sendmessage(url, form_data,
  30. data => {
  31. layer.close(index);
  32. // var datax = eval("(" + data + ")");
  33. if (data.code == 200) {
  34. tip_ok();
  35. if (undefined != func)
  36. func(data.data);
  37. } else {
  38. console.log(data)
  39. if (data.code == 422){
  40. tip_errors(data.msg)
  41. } else{
  42. tip_error(data.msg);
  43. }
  44. }
  45. },
  46. //ajax error
  47. data => {
  48. layer.close(index);
  49. // var msg = Object.values(data.responseJSON.errors).join('\n\t');
  50. var msg = Object.values(data.responseJSON.errors)[0][0];
  51. tip_error(msg);
  52. });
  53. }
  54. //成功提示,1.5秒后消失
  55. function tip_ok(msg) {
  56. if (undefined == msg)
  57. msg = "操作成功!";
  58. swal({
  59. type: 'success',
  60. title: msg,
  61. showConfirmButton: false,
  62. timer: 1000
  63. });
  64. }
  65. //失败提示,带错误消息,点击ok关闭
  66. function tip_error(msg) {
  67. if (undefined == msg)
  68. msg = '操作失败!';
  69. swal({
  70. type: 'error',
  71. title: msg,
  72. timer:1500,
  73. showConfirmButton: true,
  74. })
  75. }
  76. //失败提示,带错误消息,点击ok关闭
  77. function tip_errors(msg) {
  78. console.log(typeof msg);
  79. let content='';
  80. for(let i in msg){
  81. content += msg[i][0] +' '
  82. }
  83. console.log(content);
  84. swal({
  85. type: 'error',
  86. title: '操作失败!',
  87. text:content,
  88. showConfirmButton: false,
  89. })
  90. }
  91. //确认提示,如果自定义title时,注意cancel_func需要传null
  92. function confirm_opt(confirm_func, cancel_func, msg) {
  93. msg = (msg == undefined) ? '确认操作吗?' : msg;
  94. swal({
  95. title: msg,
  96. type: 'warning',
  97. showCancelButton: true,
  98. focusConfirm: false,
  99. confirmButtonColor: '#3085d6',
  100. cancelButtonColor: '#999',
  101. confirmButtonText: '确定!',
  102. cancelButtonText: '取消'
  103. }).then(function (res) {
  104. if (res.value) {
  105. confirm_func();
  106. } else {
  107. if (cancel_func != undefined)
  108. cancel_func();
  109. }
  110. })
  111. }
  112. //将数字(整数)转为汉字,从零到一亿亿,需要小数的可自行截取小数点后面的数字直接替换对应arr1的读法就行了
  113. function convertToChinaNum(num) {
  114.     var arr1 = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
  115.     var arr2 = new Array('', '十', '百', '千', '万', '十', '百', '千', '亿', '十', '百', '千','万', '十', '百', '千','亿');//可继续追加更高位转换值
  116.     if(!num || isNaN(num)){
  117.         return "零";
  118.     }
  119.     var str1 = num.toString().split("")
  120. var str1 = num.toString().split(".")[0];
  121. var str2 = num.toString().split(".")[1];
  122.     var result = "";
  123.     for (var i = 0; i < str1.length; i++) {
  124.         var des_i = str1.length - 1 - i;//倒序排列设值
  125.         result = arr2[i] + result;
  126.         var arr1_index = str1[des_i];
  127.         result = arr1[arr1_index] + result;
  128.     }
  129.     //将【零千、零百】换成【零】 【十零】换成【十】
  130.     result = result.replace(/零(千|百|十)/g, '零').replace(/十零/g, '十');
  131.     //合并中间多个零为一个零
  132.     result = result.replace(/零+/g, '零');
  133.     //将【零亿】换成【亿】【零万】换成【万】
  134.     result = result.replace(/零亿/g, '亿').replace(/零万/g, '万');
  135.     //将【亿万】换成【亿】
  136.     result = result.replace(/亿万/g, '亿');
  137.     //移除末尾的零
  138.     result = result.replace(/零+$/, '')
  139.     //将【零一十】换成【零十】
  140.     //result = result.replace(/零一十/g, '零十');//貌似正规读法是零一十
  141.     //将【一十】换成【十】
  142.     result = result.replace(/^一十/g, '十');
  143.     return result;
  144. }
  145. function convertCurrency(money) {
  146. //汉字的数字
  147. // var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
  148. var cnNums = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
  149. //基本单位
  150. var cnIntRadice = new Array('', '十', '百', '千');
  151. //对应整数部分扩展单位
  152. var cnIntUnits = new Array('', '万', '亿', '兆');
  153. //对应小数部分单位
  154. var cnDecUnits = new Array('角', '分', '毫', '厘');
  155. //整数金额时后面跟的字符
  156. var cnInteger = '整';
  157. //整型完以后的单位
  158. var cnIntLast = '元';
  159. //最大处理的数字
  160. var maxNum = 999999999999999.9999;
  161. //金额整数部分
  162. var integerNum;
  163. //金额小数部分
  164. var decimalNum;
  165. //输出的中文金额字符串
  166. var chineseStr = '';
  167. //分离金额后用的数组,预定义
  168. var parts;
  169. if (money == '') { return ''; }
  170. money = parseFloat(money);
  171. if (money >= maxNum) {
  172. //超出最大处理数字
  173. return '超出范围';
  174. }
  175. if (money == 0) {
  176. chineseStr = cnNums[0];
  177. return chineseStr;
  178. }
  179. //转换为字符串
  180. money = money.toString();
  181. if (money.indexOf('.') == -1) {
  182. integerNum = money;
  183. decimalNum = '';
  184. } else {
  185. parts = money.split('.');
  186. integerNum = parts[0];
  187. decimalNum = parts[1].substr(0, 2);
  188. }
  189. //获取整型部分转换
  190. if (parseInt(integerNum, 10) > 0) {
  191. var zeroCount = 0;
  192. var IntLen = integerNum.length;
  193. for (var i = 0; i < IntLen; i++) {
  194. var n = integerNum.substr(i, 1);
  195. var p = IntLen - i - 1;
  196. var q = p / 4;
  197. var m = p % 4;
  198. if (n == '0') {
  199. zeroCount++;
  200. } else {
  201. if (zeroCount > 0) {
  202. chineseStr += cnNums[0];
  203. }
  204. //归零
  205. zeroCount = 0;
  206. chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
  207. }
  208. if (m == 0 && zeroCount < 4) {
  209. chineseStr += cnIntUnits[q];
  210. }
  211. }
  212. // chineseStr += cnIntLast;
  213. } else {
  214. chineseStr += cnNums[0];
  215. }
  216. //小数部分
  217. if (decimalNum != '') {
  218. chineseStr += '点';
  219. var decLen = decimalNum.length;
  220. for (var i = 0; i < decLen; i++) {
  221. var n = decimalNum.substr(i, 1);
  222. if (n != '0') {
  223. chineseStr += cnNums[Number(n)];
  224. }
  225. }
  226. }
  227. if (chineseStr == '') {
  228. chineseStr += cnNums[0];
  229. } else if (decimalNum == '') {
  230. // chineseStr;
  231. }
  232. return chineseStr;
  233. }
  234. </script>
  235. <script src="/admin/js/accounting.min.js"></script>