PerReviewsSelectorOnly.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <el-dialog
  3. :visible.sync="innerVisible"
  4. @close="handleClose"
  5. @open="initData"
  6. @closed="dataReset"
  7. append-to-body
  8. :close-on-click-modal="false"
  9. center
  10. title="审批节点配置"
  11. width="600px"
  12. >
  13. <el-form v-if="currentNode" label-width="200">
  14. <el-form-item label="启用">
  15. <el-switch
  16. v-model="currentNode.enable"
  17. disabled
  18. />
  19. </el-form-item>
  20. <el-form-item label="">
  21. <div class="handler-list">
  22. <el-tag
  23. v-for="(item,index) in currentNode.children"
  24. :key="`hl_${index}`"
  25. :type="childIndex === index ? '' : 'info'"
  26. closable
  27. @close="removeChild(index)"
  28. @click="childSelect(index)"
  29. >
  30. {{assigneeMap[item.assigneeType] || '未知'}}
  31. </el-tag>
  32. <el-button
  33. v-show="currentNode.enable"
  34. icon="el-icon-plus"
  35. size="mini"
  36. style="margin-bottom: 10px;"
  37. @click="addChild"
  38. />
  39. </div>
  40. </el-form-item>
  41. <el-form-item label="审批人">
  42. <el-radio-group
  43. v-model="currentNode.children[childIndex].assigneeType"
  44. :disabled="!currentNode.enable"
  45. @change="onAssigneeTypeChange"
  46. >
  47. <el-radio-button label="leader">组织管理员</el-radio-button>
  48. <el-radio-button label="user">指定人员</el-radio-button>
  49. <el-radio-button label="self">被考核人</el-radio-button>
  50. <el-radio-button label="post">岗位</el-radio-button>
  51. <el-radio-button label="deptLeader">部门负责人</el-radio-button>
  52. </el-radio-group>
  53. </el-form-item>
  54. <el-form-item label="">
  55. <template v-if="currentNode.children[childIndex].assigneeType === 'leader'">
  56. <el-select
  57. v-model="currentNode.children[childIndex].leaderLevel"
  58. placeholder="请选择管理员"
  59. :disabled="!currentNode.enable"
  60. filterable
  61. style="width: 300px;"
  62. key="leader"
  63. @change="onOrgManagerChange"
  64. >
  65. <el-option
  66. v-for="item in levelOptions"
  67. :key="`leader_${item.value}`"
  68. :label="item.label"
  69. :value="item.value"
  70. style="width: 300px;"
  71. />
  72. </el-select>
  73. </template>
  74. <template v-if="currentNode.children[childIndex].assigneeType === 'user'">
  75. <el-select
  76. v-model="userSelected"
  77. placeholder="请选择指定人员"
  78. multiple
  79. :disabled="!currentNode.enable"
  80. filterable
  81. style="width: 300px;"
  82. key="user"
  83. @change="onUserChange"
  84. >
  85. <el-option
  86. v-for="item in employees"
  87. :key="`user_${item.id}`"
  88. :label="item.name"
  89. :value="item.id"
  90. style="width: 300px;"
  91. />
  92. </el-select>
  93. </template>
  94. <template v-if="currentNode.children[childIndex].assigneeType === 'post'">
  95. <el-select
  96. v-model="postSelected"
  97. placeholder="请选择岗位"
  98. multiple
  99. :disabled="!currentNode.enable"
  100. filterable
  101. style="width: 300px;"
  102. key="post"
  103. @change="onPostChange"
  104. >
  105. <el-option
  106. v-for="item in postList"
  107. :key="`post_${item.id}`"
  108. :label="item.name"
  109. :value="item.id"
  110. style="width: 300px;"
  111. />
  112. </el-select>
  113. </template>
  114. <template v-if="currentNode.children[childIndex].assigneeType === 'deptLeader'">
  115. <el-select
  116. v-model="deptSelected"
  117. placeholder="请选择部门"
  118. multiple
  119. :disabled="!currentNode.enable"
  120. filterable
  121. style="width: 300px;"
  122. key="deptLeader"
  123. @change="onDeptChange"
  124. >
  125. <el-option
  126. v-for="item in deptList"
  127. :key="`deptLeader_${item.id}`"
  128. :label="item.name"
  129. :value="item.id"
  130. style="width: 300px;"
  131. />
  132. </el-select>
  133. </template>
  134. </el-form-item>
  135. <el-form-item label="多人时">
  136. <el-radio-group
  137. v-model="currentNode.children[childIndex].multipleType"
  138. :disabled="!currentNode.enable"
  139. >
  140. <el-radio-button label="or">任一人确认(或签)</el-radio-button>
  141. <el-radio-button label="parallel">按顺序确认(会签)</el-radio-button>
  142. <el-radio-button label="sequence">同时确认(会签)</el-radio-button>
  143. </el-radio-group>
  144. </el-form-item>
  145. <el-form-item label="允许">
  146. <el-checkbox-group
  147. v-model="currentNode.children[childIndex].allows"
  148. :disabled="!currentNode.enable"
  149. >
  150. <el-checkbox-button label="transfer">转交</el-checkbox-button>
  151. </el-checkbox-group>
  152. </el-form-item>
  153. </el-form>
  154. <template #footer>
  155. <el-row type="flex" justify="end">
  156. <el-col align="end">
  157. <el-button
  158. type="primary"
  159. @click="onConfirm"
  160. >
  161. 确认
  162. </el-button>
  163. </el-col>
  164. </el-row>
  165. </template>
  166. </el-dialog>
  167. </template>
  168. <script>
  169. import Template from "../../examine/components/Template.vue";
  170. export default {
  171. name: "PerReviewsSelectorOnly",
  172. components: {Template},
  173. props: {
  174. showVisible: {
  175. type: Boolean,
  176. default: false
  177. },
  178. },
  179. data(){
  180. return {
  181. userInfo: this.$userInfo(),
  182. currentNode: null,
  183. childIndex: null,
  184. innerVisible: this.showVisible,
  185. loading:false,
  186. employees:[],
  187. postList:[],
  188. deptList:[],
  189. userSelected:[],
  190. postSelected:[],
  191. deptSelected:[],
  192. assigneeMap:{
  193. leader:'组织管理员',
  194. user:'指定人员',
  195. self:'被考核人',
  196. post:'岗位',
  197. deptLeader:'部门负责人',
  198. },
  199. levelOptions: [
  200. {
  201. value: 1,
  202. label: '直接管理员'
  203. },
  204. {
  205. value: 2,
  206. label: '二级管理员'
  207. },
  208. {
  209. value: 3,
  210. label: '三级管理员'
  211. },
  212. {
  213. value: 4,
  214. label: '四级管理员'
  215. },
  216. {
  217. value: 5,
  218. label: '五级管理员'
  219. },
  220. {
  221. value: 6,
  222. label: '六级管理员'
  223. }
  224. ]
  225. }
  226. },
  227. computed:{
  228. employeeMap(){
  229. const map = {};
  230. this.employees.forEach(e => {
  231. if (!map[e.id]) map[e.id] = e.name;
  232. });
  233. return map;
  234. },
  235. postMap(){
  236. const map = {};
  237. this.postList.forEach(e => {
  238. if (!map[e.id]) map[e.id] = e.name;
  239. });
  240. return map;
  241. },
  242. deptMap(){
  243. const map = {};
  244. this.deptList.forEach(e => {
  245. if (!map[e.id]) map[e.id] = e.name;
  246. });
  247. return map;
  248. },
  249. },
  250. watch:{
  251. showVisible(val){
  252. this.innerVisible = val;
  253. },
  254. },
  255. methods: {
  256. defaultNode(){
  257. const node = JSON.parse("{\"id\":\"RS_1907236768800382982\",\"type\":\"reviews\",\"enable\":true,\"assigneeType\":\"leader\",\"leaderLevel\":1,\"assigneeIds\":[],\"multipleType\":\"or\",\"allows\":[\"transfer\"],\"weight\":0,\"children\":[{\"id\":\"R_1907236768800382983\",\"type\":\"review\",\"enable\":true,\"assigneeType\":\"leader\",\"leaderLevel\":1,\"assigneeIds\":[],\"multipleType\":\"or\",\"allows\":[\"transfer\"],\"weight\":0,\"children\":[]}]}");
  258. node.id = "RS_" + this.generalId();
  259. node.children.forEach((_,i) => {
  260. node.children[i].id = "R_" + this.generalId();
  261. });
  262. return node;
  263. },
  264. matchErrMsg(err){
  265. return err.toString().replace(/[(Error: )]/g,'');
  266. },
  267. handleClose(){
  268. this.$emit('update:showVisible',false);
  269. },
  270. dataReset(){
  271. this.currentNode = null;
  272. this.childIndex = null;
  273. this.userSelected = [];
  274. this.postSelected = [];
  275. this.deptSelected = [];
  276. },
  277. initData(){
  278. if (this.loading) return;
  279. this.dataReset();
  280. this.loading = true;
  281. let result = true;
  282. Promise.all([
  283. this.$axiosUser('get', '/api/pro/employee/index', {page:0,page_size:10,status:1}, 'v2'),
  284. this.$axiosUser('get','/org/post'),
  285. this.$axiosUser('get', `/org/departments/${this.userInfo.site_id}`)
  286. ])
  287. .then(([employeeRes,postRes,deptRes]) => {
  288. if (employeeRes.data.code !== 1) throw new Error(employeeRes.data.msg);
  289. if (postRes.data.code !== 1) throw new Error(postRes.data.message);
  290. if (deptRes.data.code !== 1) throw new Error(deptRes.data.message);
  291. this.employees = employeeRes.data.data.list
  292. .filter(e => e.account_id && e.account_id > 0)
  293. .map(e => {
  294. return {
  295. id:e.id,
  296. name:e.name,
  297. }
  298. });
  299. this.postList = postRes.data.data.map(item => {
  300. return {
  301. id: item.id,
  302. name: item.name,
  303. }
  304. });
  305. this.deptList = deptRes.data.data.list.map(item => {
  306. return {
  307. id: item.id,
  308. name: item.name,
  309. }
  310. });
  311. this.currentNode = this.defaultNode();
  312. this.childIndex = this.currentNode.children && this.currentNode.children.length > 0 ? 0 : null;
  313. if (this.childIndex !== null && !!this.currentNode.children[this.childIndex]){
  314. switch (this.currentNode.children[this.childIndex].assigneeType){
  315. case 'user':
  316. this.userSelected = [...this.currentNode.children[this.childIndex].assigneeIds];
  317. break;
  318. case 'post':
  319. this.postSelected = [...this.currentNode.children[this.childIndex].assigneeIds];
  320. break;
  321. case 'deptLeader':
  322. this.deptSelected = [...this.currentNode.children[this.childIndex].assigneeIds];
  323. break;
  324. }
  325. }
  326. })
  327. .catch(err => {
  328. this.$message.error(this.matchErrMsg(err));
  329. result = false;
  330. })
  331. .finally(() => {
  332. this.loading = false;
  333. if (!result) this.handleClose();
  334. })
  335. },
  336. generalId(){
  337. return Date.now() + Math.floor(Math.random() * 10000);
  338. },
  339. addChild(){
  340. let id = "R_" + this.generalId();
  341. this.currentNode.children.push({
  342. id:id,
  343. type:'review',
  344. enable:true,
  345. assigneeType:'leader',
  346. leaderLevel:1,
  347. assigneeIds:[],
  348. multipleType:'or',
  349. allows:['transfer'],
  350. weight:0,
  351. children:[],
  352. });
  353. },
  354. removeChild(index){
  355. if (this.currentNode.children.length <= 1 || !this.currentNode.children[index]) return;
  356. let selectChildId = this.currentNode.children[index].id;
  357. this.childIndex = 0;
  358. this.currentNode.children = this.currentNode.children.filter((_,i) => i !== index);
  359. if (selectChildId){
  360. this.currentNode.children.forEach((child,i) => {
  361. if (child.id === selectChildId) this.childIndex = i;
  362. })
  363. }
  364. },
  365. onAssigneeTypeChange(v){
  366. this.currentNode.children[this.childIndex].assigneeIds = [];
  367. this.currentNode.children[this.childIndex].leaderLevel = 1;
  368. this.userSelected = [];
  369. this.postSelected = [];
  370. this.deptSelected = [];
  371. },
  372. onOrgManagerChange(v){
  373. this.currentNode.children[this.childIndex].assigneeIds = [];
  374. this.currentNode.children[this.childIndex].leaderLevel = v;
  375. this.userSelected = [];
  376. this.postSelected = [];
  377. this.deptSelected = [];
  378. },
  379. onUserChange(v){
  380. this.currentNode.children[this.childIndex].assigneeIds = [...v];
  381. this.currentNode.children[this.childIndex].leaderLevel = 1;
  382. this.userSelected = v;
  383. this.postSelected = [];
  384. this.deptSelected = [];
  385. },
  386. onPostChange(v){
  387. this.currentNode.children[this.childIndex].assigneeIds = [...v];
  388. this.currentNode.children[this.childIndex].leaderLevel = 1;
  389. this.userSelected = [];
  390. this.postSelected = v;
  391. this.deptSelected = [];
  392. },
  393. onDeptChange(v){
  394. this.currentNode.children[this.childIndex].assigneeIds = [...v];
  395. this.currentNode.children[this.childIndex].leaderLevel = 1;
  396. this.userSelected = [];
  397. this.postSelected = [];
  398. this.deptSelected = v;
  399. },
  400. childSelect(index){
  401. if (!this.currentNode.children[index]) return;
  402. this.childIndex = index;
  403. this.userSelected = this.currentNode.children[this.childIndex].assigneeType === 'user' ? this.currentNode.children[this.childIndex].assigneeIds : [];
  404. this.postSelected = this.currentNode.children[this.childIndex].assigneeType === 'post' ? this.currentNode.children[this.childIndex].assigneeIds : [];
  405. this.deptSelected = this.currentNode.children[this.childIndex].assigneeType === 'deptLeader' ? this.currentNode.children[this.childIndex].assigneeIds : [];
  406. },
  407. onConfirm(){
  408. this.$emit('confirm',this.currentNode);
  409. this.handleClose();
  410. },
  411. }
  412. }
  413. </script>
  414. <style scoped lang="scss">
  415. .handler-list {
  416. width: 500px;
  417. margin: 0 auto 16px auto;
  418. border-radius: 6px;
  419. border: 1px solid #d7dae2;
  420. padding: 10px 0 0 10px;
  421. box-sizing: border-box;
  422. display: flex;
  423. flex-wrap: wrap;
  424. .el-tag {
  425. margin: 0 10px 10px 0;
  426. cursor: pointer;
  427. }
  428. }
  429. </style>