index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import {toast} from 'nc-lightapp-front';
  2. export default class SearchAction {
  3. constructor(comp) {
  4. this.comp = comp;
  5. this.dispatch = this.comp.props.dispatch;
  6. }
  7. closeModal = () => {
  8. const {props} = this.comp;
  9. const {dispatch} = props;
  10. dispatch({
  11. type: 'main/update',
  12. payload: {
  13. assignAppVisible: false
  14. }
  15. });
  16. this.comp.setState({
  17. workflow: [],
  18. leftData: [],
  19. rightData: [],
  20. allAssignInfo: {},
  21. selectedWork: ''
  22. })
  23. };
  24. getContent = async () => {
  25. const {props} = this.comp;
  26. const {dispatch, main} = props;
  27. const {assignContent} = main;
  28. const workflow = assignContent.content.map(item => {
  29. if(!item.assginUsers) {
  30. item.users = item.uservos.map(user => {
  31. return {
  32. key: user.userpk,
  33. title: user.username
  34. }
  35. });
  36. } else {
  37. item.users = item.assginUsers.map(user => {
  38. return {
  39. key: user.pk,
  40. title: user.name
  41. }
  42. });
  43. }
  44. item.selectUsers = [];
  45. if(!item.assginUsers){
  46. item.oldUsers = item.uservos
  47. item.uservos = [];
  48. }else{
  49. item.oldUsers = item.assginUsers;
  50. item.assginUsers = [];
  51. }
  52. return {
  53. key: item.desc,
  54. value: item.activitydefid,
  55. label: item.desc
  56. }
  57. });
  58. let leftData = assignContent.content[0].users, rightData = [];
  59. this.comp.setState({
  60. allAssignInfo: assignContent,
  61. leftData,
  62. rightData,
  63. workflow,
  64. selectedWork: workflow[0].value
  65. })
  66. };
  67. onWorkflowChange = async (value) => {
  68. const {state} = this.comp;
  69. const {allAssignInfo} = state;
  70. let leftData = [], rightData = [];
  71. const curInfo = allAssignInfo.content.find(item => item.activitydefid === value);
  72. if (curInfo) {
  73. leftData = curInfo.users;
  74. rightData = curInfo.selectUsers;
  75. }
  76. this.comp.setState({
  77. leftData,
  78. rightData,
  79. selectedWork: value
  80. });
  81. };
  82. appChange = (targetKeys, direction, moveKeys) => {
  83. const {state} = this.comp;
  84. const {allAssignInfo, selectedWork} = state;
  85. const curInfo = allAssignInfo.content.find(item => item.activitydefid === selectedWork);
  86. if (curInfo) {
  87. curInfo.selectUsers = targetKeys;
  88. curInfo.assginUsers = curInfo.oldUsers.filter(item => targetKeys.includes(item.pk || item.userpk));
  89. }
  90. if (allAssignInfo.flow_type === 'approveflow') {
  91. curInfo.uservos = curInfo.assginUsers;
  92. allAssignInfo.content[0] = curInfo;
  93. }
  94. this.comp.setState({
  95. allAssignInfo,
  96. rightData: targetKeys
  97. });
  98. };
  99. onSure = () => {
  100. const {action, state, props} = this.comp;
  101. const {allAssignInfo} = state;
  102. const {main} = props;
  103. const {language} = main;
  104. let isAssigned = true;
  105. allAssignInfo.content.forEach(item => {
  106. if (!item.selectUsers || !item.selectUsers.length) {
  107. isAssigned = false
  108. }
  109. });
  110. if (!isAssigned) {
  111. toast({color: 'danger', content: language['hrzzpc-000139']});
  112. return;
  113. }
  114. action.formAct.assignApp(allAssignInfo, () => {
  115. this.closeModal()
  116. });
  117. }
  118. }