index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * Created by xieli on 2018/7/12 0012.
  3. */
  4. import http from "api/http.js";
  5. const mixins = {
  6. filters: {
  7. // 显示时间为 2021.07.22
  8. formatTime(time){
  9. if(time==='0001-01-01 00:00:00'||time==='0000-00-00 00:00:00'){
  10. return '--'
  11. }else{
  12. return time?time.replace(/-/g,'.'):''
  13. }
  14. },
  15. // 格式化金额 三位一个逗号
  16. formatPriceHasPoint(e){
  17. let str=e.toString()
  18. let num1='',num2=''
  19. if(str.indexOf(".")!=-1){
  20. num1=str.substring(0,str.indexOf("."))
  21. num2=str.substring(str.length,str.indexOf("."))
  22. if(Number(num2)<=0){
  23. num2=''
  24. }
  25. }else{
  26. num1=str
  27. }
  28. return num1.replace(/(?!^)(?=(\d{3})+$)/g, ',')+num2
  29. }
  30. },
  31. methods: {
  32. formatterColumn(row,column,cellvalue){
  33. return cellvalue ? http.dateFormatter(cellvalue) : '';
  34. },
  35. notHasTimeFormatter(row,column,cellvalue){
  36. return cellvalue ? http.dateFormatter(cellvalue,false) : '';
  37. },
  38. mixinsDateFormatter(date,type){
  39. if(!date) return "";
  40. return type === false ? http.dateFormatter(date, false) : http.dateFormatter(date);
  41. },
  42. numberFormatter(str,type=1){ // 0 文字在左侧 1 文字在右侧
  43. switch (str) {
  44. case '万':
  45. return (row,column,cellvalue) =>{
  46. return type ? `${this.division(cellvalue,10000)}${str}`:`${str}${this.division(cellvalue,10000)}`;
  47. };
  48. default:
  49. return (row,column,cellvalue) =>{
  50. return `${cellvalue}${str}`;
  51. };
  52. }
  53. },
  54. formatterTime(time){
  55. return http.dateFormatter(time);
  56. },
  57. /**
  58. * y 被除数
  59. * n 除数
  60. */
  61. division(y,n){ //除法
  62. if( y === '' || y===null || y===undefined){
  63. y = 0;
  64. }
  65. let a = String(y);
  66. let power = String(a).split('.')[1] ? String(a).split('.')[1].length : 0;
  67. let intY = y * Math.pow(10,power);
  68. let intN = n * Math.pow(10,power);
  69. return intY/intN;
  70. },
  71. prompt(msg) { //提示
  72. this.$message({
  73. message: msg,
  74. duration: 1000,
  75. });
  76. },
  77. notice(msg) {
  78. this.$message({
  79. message: msg,
  80. type: 'error',
  81. duration: 1000,
  82. });
  83. },
  84. success(msg) {
  85. this.$message({
  86. message: msg,
  87. type: 'success',
  88. duration: 1000,
  89. });
  90. },
  91. _handleFocus(){
  92. this.$nextTick(()=>{
  93. var a= document.getElementsByClassName('el-icon-arrow-right');
  94. a[1].removeAttribute('disabled');
  95. a[1].classList.remove('is-disabled');
  96. })
  97. },
  98. _sendCode(params,func){
  99. return new Promise( (resolve,reject)=>{
  100. this.$prompt('请输入验证码', '提示', {
  101. confirmButtonText: '确定',
  102. cancelButtonText: '取消',
  103. inputValidator:(e)=>{
  104. if( e=='' || e==null ){
  105. return '验证码不能为空';
  106. }else{
  107. return true;
  108. }
  109. },
  110. beforeClose:(action,instance,done) => {
  111. if( action==='confirm' ){
  112. let newParams = Object.assign({},params,{VerifyCode:instance.inputValue});
  113. func(newParams).then(res=>{
  114. if( res.Ret==200 ){
  115. done();
  116. resolve(res);
  117. }
  118. })
  119. }else{
  120. done();
  121. }
  122. }
  123. }).then(({ value }) => {
  124. }).catch(() => {
  125. // this.$message({
  126. // type: 'info',
  127. // message: '取消输入'
  128. // });
  129. });
  130. })
  131. }
  132. }
  133. }
  134. export { mixins }