index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. function All() {}
  2. All.prototype = {
  3. timer: "",
  4. debounce(fn, delay = 500) {
  5. var _this = this;
  6. return function(arg) {
  7. //获取函数的作用域和变量
  8. let that = this;
  9. let args = arg;
  10. clearTimeout(_this.timer) // 清除定时器
  11. _this.timer = setTimeout(function() {
  12. fn.call(that, args)
  13. }, delay)
  14. }
  15. },
  16. setCookie(val) { //cookie设置[{key:value}]、获取key、清除['key1','key2']
  17. for (var i = 0, len = val.length; i < len; i++) {
  18. for (var key in val[i]) {
  19. document.cookie = key + '=' + encodeURIComponent(val[i][key]) + "; path=/";
  20. }
  21. }
  22. },
  23. getCookie(name) {
  24. var strCookie = document.cookie;
  25. var arrCookie = strCookie.split("; ");
  26. for (var i = 0, len = arrCookie.length; i < len; i++) {
  27. var arr = arrCookie[i].split("=");
  28. if (name == arr[0]) {
  29. return decodeURIComponent(arr[1]);
  30. }
  31. }
  32. },
  33. clearCookie(name) {
  34. var myDate = new Date();
  35. myDate.setTime(-1000); //设置时间
  36. for (var i = 0, len = name.length; i < len; i++) {
  37. document.cookie = "" + name[i] + "=''; path=/; expires=" + myDate.toGMTString();
  38. }
  39. },
  40. arrToStr(arr) {
  41. if (arr) {
  42. return arr.map(item => { return item.name }).toString()
  43. }
  44. },
  45. toggleClass(arr, elem, key = 'id') {
  46. return arr.some(item => { return item[key] == elem[key] });
  47. },
  48. toChecked(arr, elem, key = 'id') {
  49. var isIncludes = this.toggleClass(arr, elem, key);
  50. !isIncludes ? arr.push(elem) : this.removeEle(arr, elem, key);
  51. },
  52. removeEle(arr, elem, key = 'id') {
  53. var includesIndex;
  54. arr.map((item, index) => {
  55. if (item[key] == elem[key]) {
  56. includesIndex = index
  57. }
  58. });
  59. arr.splice(includesIndex, 1);
  60. },
  61. setApproverStr(nodeConfig) {
  62. if (nodeConfig.setType == 1) {
  63. if (nodeConfig.nodeApproveList.length == 1) {
  64. return nodeConfig.nodeApproveList[0].name
  65. } else if (nodeConfig.nodeApproveList.length > 1) {
  66. if (nodeConfig.signType == 1) {
  67. return this.arrToStr(nodeConfig.nodeApproveList)
  68. } else if (nodeConfig.signType == 2) {
  69. return nodeConfig.nodeApproveList.length + "人(" + this.arrToStr(nodeConfig.nodeApproveList) + ")会签"
  70. }
  71. }
  72. } else if (nodeConfig.setType == 2) {
  73. let level = nodeConfig.directorLevel == 1 ? '直接主管' : '第' + nodeConfig.directorLevel + '级主管'
  74. if (nodeConfig.signType == 1) {
  75. return level
  76. } else if (nodeConfig.signType == 2) {
  77. return level + "会签"
  78. }
  79. }else if (nodeConfig.setType == 3) {
  80. if (nodeConfig.nodeApproveList.length > 0) {
  81. return "指定 (" + this.arrToStr(nodeConfig.nodeApproveList) + ") 角色"
  82. }
  83. return ""
  84. } else if (nodeConfig.setType == 4) {
  85. return "指定部门"
  86. } else if (nodeConfig.setType == 5) {
  87. return "发起人自己"
  88. } else if (nodeConfig.setType == 6) {
  89. return "层层审批:直到发起人的第"+ nodeConfig.directorLevel +"级主管"
  90. }
  91. },
  92. dealStr(str, obj) {
  93. let arr = [];
  94. let list = str.split(",");
  95. for (var elem in obj) {
  96. list.map(item => {
  97. if ((item -1) == elem) {
  98. arr.push(obj[elem].value)
  99. }
  100. })
  101. }
  102. return arr.join("或")
  103. },
  104. getLabelStr(index, obj) {
  105. if(!obj) return;
  106. let ret = obj[index -1];
  107. if (ret) {
  108. return ret.value;
  109. }
  110. return '';
  111. },
  112. conditionStr(nodeConfig, index) {
  113. var { conditionList, nodeApproveList } = nodeConfig.conditionNodes[index];
  114. if (conditionList.length == 0) {
  115. return (index == nodeConfig.conditionNodes.length - 1) && nodeConfig.conditionNodes[index].conditionList.length == 0 ? '其他条件进入此流程' : '请设置条件'
  116. } else {
  117. let str = ""
  118. for (var i = 0; i < conditionList.length; i++) {
  119. var { formId, columnType, showType, showName, optType, zdy1, opt1, zdy2, opt2, fixedDownBoxValue } = conditionList[i];
  120. if (formId == 0) {
  121. if (nodeApproveList.length != 0) {
  122. str += '发起人属于:'
  123. str += nodeApproveList.map(item => { return item.name }).join("或") + " 并且 "
  124. }
  125. }
  126. else if (columnType == "String" && showType == "3") {
  127. if (zdy1) {
  128. str += showName + '属于:' + this.dealStr(zdy1, JSON.parse(fixedDownBoxValue)) + " 并且 "
  129. }
  130. }
  131. else if (columnType == "String" && showType == "2") {
  132. if (!fixedDownBoxValue) {
  133. str += nodeConfig.conditionNodes[index].nodeDisplayName + " "
  134. }else {
  135. if (zdy1) {
  136. str += showName + ':' + this.getLabelStr(zdy1, JSON.parse(fixedDownBoxValue)) + " 并且 "
  137. }
  138. }
  139. }
  140. else if (columnType == "Double" && showType == "2") {
  141. if (zdy1) {
  142. str += showName + ':' + this.getLabelStr(zdy1, JSON.parse(fixedDownBoxValue)) + " 并且 "
  143. }
  144. }
  145. else if (columnType == "Double" && showType != "2") {
  146. if (optType != 6 && zdy1) {
  147. var optTypeStr = ["", "<", ">", "≤", "=", "≥"][optType]
  148. str += `${showName} ${optTypeStr} ${zdy1} 并且 `
  149. } else if (optType == 6 && zdy1 && zdy2) {
  150. str += `${zdy1} ${opt1} ${showName} ${opt2} ${zdy2} 并且 `
  151. }
  152. }
  153. else {
  154. str += null
  155. }
  156. }
  157. return str ? str.substring(0, str.length - 4) : '请设置条件'
  158. }
  159. },
  160. copyerStr(nodeConfig) {
  161. if (nodeConfig.nodeApproveList.length != 0) {
  162. return this.arrToStr(nodeConfig.nodeApproveList)
  163. } else {
  164. if (nodeConfig.ccFlag == 1) {
  165. return "发起人自选"
  166. }
  167. }
  168. },
  169. toggleStrClass(item, key) {
  170. let a = item.zdy1 ? item.zdy1.split(",") : []
  171. return a.some(item => { return item == key });
  172. },
  173. }
  174. export default new All();