index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <div>
  3. <basic-container>
  4. <avue-crud
  5. ref="crud"
  6. :option="option"
  7. :data="dataList"
  8. v-model="form"
  9. :page.sync="page"
  10. :search.sync="search"
  11. :table-loading="loading"
  12. @on-load="onLoad"
  13. @search-change="searchChange"
  14. @current-change="currentChange"
  15. @size-change="sizeChange"
  16. @refresh-change="refreshChange"
  17. @saveColumn="saveColumn"
  18. >
  19. <template slot-scope="scope" slot="status">
  20. <span v-if="scope.row.status == 'N'">新建</span>
  21. <span v-if="scope.row.status == 'A'">有效</span>
  22. <span v-if="scope.row.status == 'S'">停用</span>
  23. <span v-if="scope.row.status == 'Z'">暂存</span>
  24. </template>
  25. <template slot="menuLeft">
  26. <el-button
  27. type="primary"
  28. icon="el-icon-plus"
  29. size="small"
  30. @click.stop="addHandle"
  31. >创建单据</el-button>
  32. </template>
  33. <template slot-scope="scope" slot="menu">
  34. <el-button
  35. type="text"
  36. icon="el-icon-edit"
  37. size="small"
  38. @click.stop="editOpen(scope.row)"
  39. >编辑
  40. </el-button>
  41. <el-button
  42. type="text"
  43. icon="el-icon-delete"
  44. size="small"
  45. @click.stop="rowDel(scope.row, scope.index)"
  46. >删除
  47. </el-button>
  48. </template>
  49. </avue-crud>
  50. </basic-container>
  51. <el-dialog
  52. append-to-body
  53. :visible.sync="visible"
  54. width="80%"
  55. :close-on-click-modal="false"
  56. :destroy-on-close="true"
  57. :close-on-press-escape="false"
  58. v-dialog-drag
  59. :title="title"
  60. >
  61. <el-form :inline="true" :model="dataForm" :rules="dataRule" ref="dataForm">
  62. <el-form-item label="审核路径名称" prop="pathName">
  63. <el-input v-model="dataForm.pathName" placeholder="审核路径名称"></el-input>
  64. </el-form-item>
  65. <el-form-item label="状态" prop="status">
  66. <el-select v-model="dataForm.status" placeholder="状态" style="width: 100%">
  67. <el-option
  68. v-for="item in optionsStatue"
  69. :key="item.id"
  70. :label="item.name"
  71. :value="item.id">
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. <el-form-item label="维护人" prop="opUserName">
  76. <el-input v-model="dataForm.opUserName" disabled placeholder="维护人"></el-input>
  77. </el-form-item>
  78. <el-form-item label="维护时间" prop="opDate">
  79. <el-input v-model="dataForm.opDate" disabled placeholder="维护时间"></el-input>
  80. </el-form-item>
  81. <el-form-item label="备注" class="full" prop="remarks">
  82. <el-input v-model="dataForm.remarks" placeholder="备注"></el-input>
  83. </el-form-item>
  84. </el-form>
  85. <avue-crud
  86. ref="dialogCrud"
  87. :option="detailOption"
  88. :data="detailData"
  89. >
  90. <template slot="levelName" slot-scope="{row,index}">
  91. <el-input
  92. v-model="row.levelName"
  93. clearable
  94. placeholder="请输入"
  95. ></el-input>
  96. </template>
  97. <template slot="remarks" slot-scope="{row,index}">
  98. <el-input
  99. v-model="row.remarks"
  100. clearable
  101. placeholder="请输入"
  102. ></el-input>
  103. </template>
  104. <template slot="iffixAuditUser" slot-scope="{row,index}">
  105. <el-select
  106. v-model="row.iffixAuditUser"
  107. >
  108. <el-option
  109. label="是"
  110. value="T"
  111. ></el-option>
  112. <el-option
  113. label="否"
  114. value="F"
  115. ></el-option>
  116. </el-select>
  117. </template>
  118. <template slot="iffinalItem" slot-scope="{row,index}">
  119. <el-select
  120. v-model="row.iffinalItem"
  121. >
  122. <el-option
  123. label="是"
  124. value="T"
  125. ></el-option>
  126. <el-option
  127. label="否"
  128. value="F"
  129. ></el-option>
  130. </el-select>
  131. </template>
  132. <template slot="userMold" slot-scope="{ row, index }">
  133. <el-select
  134. v-model="row.userMold"
  135. filterable
  136. placeholder="请选择规则"
  137. @change="userMoldChange(row)"
  138. >
  139. <el-option
  140. v-for="(item, index) in ruleData"
  141. :key="index"
  142. :value="item.value"
  143. :label="item.label"
  144. ></el-option>
  145. </el-select>
  146. </template>
  147. <template slot="auditMoldId" slot-scope="{ row, index }">
  148. <el-cascader
  149. v-model="row.auditMoldId"
  150. :disabled="!row.userMold || row.userMold == 3"
  151. :options="row.userMold == 1? roleData: row.userMold == 2? deptData: []"
  152. :props="props"
  153. collapse-tags
  154. clearable
  155. filterable
  156. @change="auditChange(row)"
  157. ></el-cascader>
  158. </template>
  159. <template slot="auditUserId" slot-scope="{row,index}">
  160. <el-select
  161. v-model="row.auditUserId"
  162. filterable
  163. collapse-tags
  164. multiple
  165. placeholder="审核人"
  166. >
  167. <el-option v-for="(item,index) in row.userList"
  168. :key="index"
  169. :label="item.realName"
  170. :value="item.id"
  171. ></el-option>
  172. </el-select>
  173. </template>
  174. <template slot="menuLeft">
  175. <el-button
  176. type="primary"
  177. icon="el-icon-plus"
  178. size="small"
  179. @click.stop="addDetail"
  180. >新增</el-button>
  181. </template>
  182. <template slot-scope="{row,index}" slot="menu">
  183. <el-button
  184. type="text"
  185. icon="el-icon-delete"
  186. size="small"
  187. @click="rowDetailDelete(detailData, index)"
  188. >移除</el-button>
  189. </template>
  190. </avue-crud>
  191. <span slot="footer" class="dialog-footer">
  192. <el-button @click="closeDia">取消</el-button>
  193. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  194. </span>
  195. </el-dialog>
  196. </div>
  197. </template>
  198. <script>
  199. import option from "./config/mainList.json";
  200. import detailOption from "./config/detail.json";
  201. import { getList,
  202. modify,
  203. removeList,
  204. detailData ,userList,
  205. getUserApprovalList} from "@/api/approval/processConfig";
  206. import _ from "lodash";
  207. import {getDeptTree} from "@/api/system/dept";
  208. import {getRoleTree} from "@/api/system/role";
  209. export default {
  210. name: "index",
  211. data() {
  212. return {
  213. option: {},
  214. dataList: [],
  215. form: {},
  216. page: {
  217. pageSize: 10,
  218. currentPage: 1,
  219. total: 0,
  220. pageSizes: [10, 50, 100, 200, 300, 400, 500]
  221. },
  222. detailData: [],
  223. auditUserIdDic:[],
  224. loading: false,
  225. search: {},
  226. visible: false,
  227. title: '',
  228. detailOption: {},
  229. optionsStatue: [
  230. {
  231. id: 'A',
  232. name: '有效'
  233. },
  234. {
  235. id: 'S',
  236. name: '停用'
  237. },
  238. ],
  239. dataForm: {
  240. status: 'A',
  241. },
  242. dataRule: {},
  243. tenantId: null, // 租户
  244. // dicData: [],
  245. props: {
  246. multiple: true,
  247. value: 'id',
  248. label: 'title',
  249. emitPath: false,
  250. },
  251. roleData: [],
  252. deptData: [],
  253. ruleData: [
  254. {value: 1, label: '角色'},
  255. {value: 2, label: '部门'},
  256. {value: 3, label: '用户'},
  257. ], //指定规则
  258. }
  259. },
  260. created() {
  261. this.option = option
  262. this.detailOption = detailOption
  263. getUserApprovalList().then(res =>{
  264. this.auditUserIdDic = res.data.data
  265. })
  266. this.tenantId = this.$store.getters.userInfo.tenant_id;
  267. getRoleTree(this.tenantId).then(res => {
  268. this.roleData = res.data.data;
  269. });
  270. getDeptTree(this.tenantId).then(res => {
  271. this.deptData = res.data.data;
  272. });
  273. let i = 0;
  274. this.option.column.forEach(item => {
  275. if (item.search) i++
  276. })
  277. if (i % 3 !== 0){
  278. const num = 3 - Number(i % 3)
  279. this.option.searchMenuSpan = num * 8;
  280. this.option.searchMenuPosition = "right";
  281. }
  282. },
  283. methods: {
  284. onLoad(page, params) {
  285. params = {
  286. ...params,
  287. current: page.currentPage,
  288. size: page.pageSize,
  289. }
  290. this.loading = true
  291. getList(params).then(res => {
  292. this.dataList = res.data.data.records ? res.data.data.records : [];
  293. }).finally(() => {
  294. this.loading = false
  295. })
  296. },
  297. addHandle() {
  298. this.title = '新增';
  299. this.visible = !this.visible
  300. this.dataForm = {}
  301. this.detailData = []
  302. },
  303. // 编辑
  304. editOpen(row) {
  305. detailData({id: row.id}).then(res => {
  306. this.dataForm = res.data.data
  307. this.detailData = res.data.data.auditPathsLevels
  308. this.detailData.map(e => {
  309. let params = {};
  310. if (e.auditMoldId && e.auditMoldId.length > 0) {
  311. if (e.userMold === 1) {
  312. this.$set(params, 'roleId', e.auditMoldId)
  313. } else if (e.userMold === 2) {
  314. this.$set(params, 'deptId', e.auditMoldId)
  315. }
  316. userList(params).then(response => {
  317. this.$set(e, 'userList', response.data.data);
  318. })
  319. } else {
  320. this.$set(e, 'userList', this.auditUserIdDic);
  321. }
  322. if (e.auditMoldId) {
  323. e.auditMoldId = e.auditMoldId.split(',')
  324. }
  325. if (e.auditUserId) {
  326. e.auditUserId = e.auditUserId.split(',')
  327. }
  328. })
  329. })
  330. this.title = '修改';
  331. this.visible = !this.visible
  332. },
  333. rowDel(row, index) {
  334. this.$confirm("确定将选择数据删除?", {
  335. confirmButtonText: "确定",
  336. cancelButtonText: "取消",
  337. type: "warning"
  338. }).then(() => {
  339. removeList(row.id).then(res =>{
  340. if(res.data.success){
  341. this.$message({
  342. type: "success",
  343. message: "操作成功!"
  344. });
  345. this.page.currentPage = 1;
  346. this.onLoad(this.page);
  347. }
  348. })
  349. })
  350. },
  351. //点击搜索按钮触发
  352. searchChange(params, done) {
  353. this.page.currentPage = 1;
  354. this.onLoad(this.page, params);
  355. done();
  356. },
  357. currentChange(val) {
  358. this.page.currentPage = val;
  359. },
  360. sizeChange(val) {
  361. this.page.currentPage = 1;
  362. this.page.pageSize = val;
  363. },
  364. refreshChange() {
  365. this.onLoad(this.page, this.search);
  366. },
  367. async saveColumn() {
  368. // const inSave = await this.saveColumnData(
  369. // this.getColumnName(50),
  370. // this.option
  371. // );
  372. if (inSave) {
  373. this.$message.success("保存成功");
  374. //关闭窗口
  375. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  376. }
  377. },
  378. addDetail() {
  379. this.detailData.push({
  380. userList: this.auditUserIdDic,
  381. levelName: null,
  382. auditUserId: [],
  383. iffixAuditUser: 'T',
  384. iffinalItem: 'T',
  385. remarks: null,
  386. $cellEdit: true
  387. })
  388. },
  389. rowDetailDelete(row, index) {
  390. row.splice(index, 1)
  391. },
  392. closeDia() {
  393. this.visible = false
  394. },
  395. dataFormSubmit() {
  396. if (this.detailData.length === 0) {
  397. this.$message.error('请维护审批级次')
  398. return false
  399. }
  400. for (let x in this.detailData) {
  401. if (this.detailData[x].iffixAuditUser === 'S') {
  402. if (this.detailData[x].auditUserId === null || this.detailData[x].auditUserId === '' || this.dataList[x].auditUserId.length === 0) {
  403. this.$message.error('请维护第' + (Number(x) + 1) + '级的审核人')
  404. return false
  405. }
  406. }
  407. }
  408. let params ={
  409. ...this.dataForm,
  410. auditPathsLevels: JSON.parse(JSON.stringify(this.detailData))
  411. }
  412. for (let item of params.auditPathsLevels){
  413. item.levelId = _.add(item.$index,1)
  414. delete item.id
  415. if (item.auditMoldId) {
  416. item.auditMoldId = item.auditMoldId.join(',');
  417. }
  418. if (item.auditUserId) {
  419. item.auditUserId = item.auditUserId.join(',');
  420. }
  421. }
  422. modify(params).then(res =>{
  423. if(res.data.success){
  424. this.$message.success("操作成功!")
  425. this.visible = false
  426. this.refreshChange()
  427. }
  428. })
  429. },
  430. auditChange(row) {
  431. let params = {};
  432. row.auditUserId = null;
  433. if (row.auditMoldId && row.auditMoldId.length > 0) {
  434. const data = row.auditMoldId.join(',');
  435. if (row.userMold === 1) {
  436. this.$set(params, 'roleId', data)
  437. } else if (row.userMold === 2) {
  438. this.$set(params, 'deptId', data)
  439. }
  440. userList(params).then(res => {
  441. this.$set(row, 'userList', res.data.data);
  442. // 选完角色部门默认全部带上
  443. this.$set(row, 'auditUserId', res.data.data.map(item => item = item.id));
  444. })
  445. } else {
  446. this.$set(row, 'userList', [])
  447. }
  448. },
  449. userMoldChange(row) {
  450. row.auditUserId = null;
  451. row.auditMoldId = null;
  452. this.$set(row, 'userList', row.userMold == 3? this.auditUserIdDic: []);
  453. },
  454. },
  455. }
  456. </script>
  457. <style scoped>
  458. </style>