index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <div class="my-container">
  3. <div class="bill-left">
  4. <div class="bill-tab">
  5. <div class="tab-title">导航</div>
  6. <side-tree :propConfig="treeConfig" @onChange="onChangeTree" ref="sideTree" />
  7. </div>
  8. </div>
  9. <div class="bill-main">
  10. <module-view :propConfig="config" ref="moduleView" @pagination="getDataList" @search="getDataList"
  11. @resert="onRefresh" @clickHandle="clickHandle" @detail="openEdit" @onRefresh="onRefresh">
  12. </module-view>
  13. </div>
  14. <!-- 新增/编辑弹窗 -->
  15. <el-dialog :title="popTitle+'机构分类'" :visible.sync="dialogFormVisible" width="30%" :destroy-on-close="true">
  16. <by-form :propConfig="addConfig" ref="addFormId">
  17. <template v-slot:status class="clearfix">
  18. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="0">正常</el-radio>
  19. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="1">禁用</el-radio>
  20. </template>
  21. </by-form>
  22. <div slot="footer" class="dialog-footer">
  23. <el-button @click="dialogFormVisible = false">取 消</el-button>
  24. <el-button type="primary" @click="confirm">确 定</el-button>
  25. </div>
  26. </el-dialog>
  27. </div>
  28. </template>
  29. <script lang="ts">
  30. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  31. import api from "@/api/currency";
  32. import Assembly from "@/components/Assembly/material.vue";
  33. @Component
  34. export default class OrganClassify extends Vue {
  35. timeNum = 0;
  36. timer : any = null
  37. popTitle : any = ''
  38. radio : any = 0
  39. dialogFormVisible : boolean = false
  40. parentId : any = 0
  41. parentIds : any = '';
  42. treeConfig = {
  43. attr: {
  44. retConfig: {
  45. id: 'id',
  46. },
  47. defaultExpandAll: true,
  48. label: 'name',
  49. // resType: 'data'
  50. },
  51. // request: {
  52. // url: '/maindata/maindataOrganizationCategory/treeList',
  53. // method: 'GET'
  54. // }
  55. }
  56. config : any = {
  57. attr:{
  58. calculateH:true
  59. },
  60. search: {
  61. attr: {
  62. size: 'mini'
  63. },
  64. columns: [
  65. [{
  66. span: 6,
  67. label: '名称',
  68. prop: 'name',
  69. component: 'by-input',
  70. labelWidth: '70px',
  71. compConfig: {
  72. attr: {
  73. placeholder: '请输入名称',
  74. clearable: true
  75. },
  76. },
  77. },
  78. {
  79. span: 6,
  80. label: '状态',
  81. prop: 'status',
  82. labelWidth: '70px',
  83. component: 'by-select',
  84. compConfig: {
  85. attr: {
  86. placeholder: '请选择状态',
  87. clearable: true,
  88. size: 'small',
  89. data: [{
  90. value: 0,
  91. label: '正常'
  92. }, {
  93. value: 1,
  94. label: '禁用'
  95. }]
  96. }
  97. }
  98. },
  99. ]
  100. ]
  101. },
  102. tool: {
  103. tools: {
  104. add: true,
  105. search: true,
  106. refresh: true
  107. }
  108. },
  109. table: {
  110. attr: {
  111. size: 'mini',
  112. align: 'left',
  113. },
  114. columns: [{
  115. title: '名称',
  116. field: 'name',
  117. isDetail: true,
  118. width: 500,
  119. },
  120. {
  121. width: 300,
  122. title: '备注',
  123. field: 'remark',
  124. },
  125. {
  126. width: 80,
  127. title: '状态',
  128. field: 'status',
  129. component: Assembly,
  130. },
  131. {
  132. width: 120,
  133. title: '操作',
  134. action: true,
  135. plugins: [{
  136. icon: 'el-icon-edit',
  137. name: '编辑',
  138. audit: '',
  139. event: {
  140. click: (item : any) => (this as any).openEdit(item)
  141. }
  142. }, {
  143. name: '删除',
  144. event: {
  145. click: (item : any) => (this as any).doDelete(item)
  146. }
  147. }]
  148. }]
  149. },
  150. }
  151. addConfig = {
  152. attr: {
  153. size: 'small',
  154. rules: {
  155. // parentName: [{
  156. // required: true, message: '请输入父级', trigger: 'blur'
  157. // }],
  158. name: [{
  159. required: true, message: '请输入名称', trigger: 'blur'
  160. }],
  161. }
  162. },
  163. columns: [
  164. [
  165. {
  166. span: 23,
  167. label: '父级',
  168. labelWidth: '70px',
  169. prop: 'parentName',
  170. component: 'select-tree',
  171. compConfig: {
  172. attr: {
  173. label: 'name',
  174. clearable: true,
  175. retConfig: {
  176. parentId: 'id',
  177. parentName: 'name',
  178. },
  179. defaultExpandAll: true
  180. },
  181. request: {
  182. url: '/maindata/maindataOrganizationCategory/treeUseList'
  183. }
  184. }
  185. },
  186. {
  187. span: 23,
  188. labelWidth: '70px',
  189. label: '名称',
  190. prop: 'name',
  191. component: 'by-input',
  192. },
  193. {
  194. span: 23,
  195. labelWidth: '70px',
  196. label: '状态',
  197. slot: true,
  198. prop: 'status',
  199. },
  200. ],
  201. [
  202. {
  203. span: 23,
  204. labelWidth: '70px',
  205. label: '备注',
  206. prop: 'remark',
  207. component: 'by-input',
  208. compConfig: {
  209. attr: {
  210. size: 'mini',
  211. placeholder: '请输入备注',
  212. type: 'textarea'
  213. },
  214. }
  215. },
  216. ]
  217. ]
  218. }
  219. mounted() {
  220. this.timer = setInterval(() => {
  221. this.getDataList()
  222. }, 300)
  223. this.getTreeList();
  224. }
  225. getTreeList(){
  226. api.treeList('maindataOrganizationCategory').then((res : any) => {
  227. console.log(res);
  228. var data:any = [{
  229. id: 0,
  230. name: '机构分类',
  231. children: res.data
  232. }];
  233. (this as any).$refs.sideTree.setData(data);
  234. })
  235. }
  236. //点击树获取数据
  237. onChangeTree(e : any) {
  238. let data : any = {};
  239. e.isContain ? data.ids = e.id : data.parentId = e.id;
  240. this.parentIds = (this as any).$lodash.cloneDeep(e.id);
  241. this.parentId = e.id[0];
  242. let loading = this.$loading({ target: '.main-container' });
  243. api.childrenTreeList(data, 'maindataOrganizationCategory').then((res : any) => {
  244. if (res.code === 200) {
  245. (this.$refs.moduleView as any).setTableValue(res.data.records);
  246. let page = {
  247. pageNo: res.data.current, //当前页
  248. pageSize: res.data.size, //每页条数
  249. total: res.data.total //总条数
  250. };
  251. (this.$refs.moduleView as any).setPage(page);
  252. loading.close();
  253. } else loading.close();
  254. }).catch(() => loading.close());
  255. }
  256. // 确认新增/编辑
  257. confirm() {
  258. (this as any).$refs.addFormId.validate().then(() => {
  259. let query = (this as any).$refs.addFormId.getValue();
  260. console.log(query);
  261. query.status = this.radio;
  262. this.dialogFormVisible = false;
  263. if (this.popTitle === '新增') {
  264. if(!query.parentId){
  265. query.parentId=0
  266. }
  267. api.saveList(query, 'maindataOrganizationCategory').then((res : any) => {
  268. if (res.code === 200) {
  269. this.$message.success(this.popTitle + '成功!');
  270. // (this as any).$refs.sideTree.request();
  271. this.getTreeList();
  272. this.getDataList();
  273. } else this.$message.error(res.msg);
  274. }).catch(() => {});
  275. } else if (this.popTitle === '编辑') {
  276. if(!query.parentId){
  277. query.parentId=0
  278. }
  279. if(query.parentId==query.id){
  280. this.$message.error('不能设置自己是自己的上级节点')
  281. return false
  282. }
  283. api.updateList(query, 'maindataOrganizationCategory').then((res : any) => {
  284. if (res.code === 200) {
  285. // this.$message.success(this.popTitle + '成功!');
  286. this.getTreeList();
  287. // (this as any).$refs.sideTree.request();
  288. this.getTreeList();
  289. this.getDataList();
  290. } else this.$message.error(res.msg);
  291. }).catch(() => {});
  292. }
  293. }).catch(() => {});
  294. }
  295. // 获取列表数据
  296. getDataList() {
  297. if (!this.$refs.moduleView) {
  298. if (this.timeNum > 5) {
  299. clearInterval(this.timer)
  300. }
  301. this.timeNum++;
  302. return
  303. }
  304. clearInterval(this.timer)
  305. let query = (this.$refs.moduleView as any).getQuery();
  306. if (this.parentIds) query.parentIds = this.parentIds;
  307. this.getPageList(query)
  308. }
  309. getPageList(query : any) {
  310. let loading = this.$loading({ target: '.main-container' });
  311. api.pageList(query, 'maindataOrganizationCategory').then((res : any) => {
  312. loading.close();
  313. if (res.code === 200) {
  314. (this.$refs.moduleView as any).setTableValue(res.data.records);
  315. let page = {
  316. pageNo: res.data.current, //当前页
  317. pageSize: res.data.size, //每页条数
  318. total: res.data.total //总条数
  319. };
  320. (this.$refs.moduleView as any).setPage(page);
  321. } else this.$message.error(res.msg);
  322. }).catch(() => loading.close());
  323. }
  324. // 工具栏方法
  325. clickHandle(e : any) {
  326. if (e === 'onAdd') this.onAdd();
  327. }
  328. // 打开新增
  329. onAdd() {
  330. this.popTitle = '新增'
  331. this.dialogFormVisible = true;
  332. this.radio = 0
  333. this.getTreeList();
  334. setTimeout(() => {
  335. if(this.parentId!=0){
  336. var data = {
  337. parentName: '',
  338. parentId: 0
  339. }
  340. api.single({ id: this.parentId }, 'maindataOrganizationCategory').then((res : any) => {
  341. if (res.code === 200) {
  342. data.parentName = res.data.name;
  343. data.parentId = res.data.id;
  344. this.dialogFormVisible = true;
  345. setTimeout(() => { (this as any).$refs.addFormId.setValue(data) }, 0);
  346. }
  347. }).catch(() => {});
  348. }else{
  349. (this as any).$refs.addFormId.setValue();
  350. (this as any).$refs.addFormId.$refs['parentName--comp'][0].request();
  351. }
  352. }, 0)
  353. }
  354. // 打开编辑
  355. openEdit(e : any) {
  356. this.popTitle = '编辑'
  357. let loading = this.$loading({ target: '.main-container' });
  358. this.getTreeList();
  359. api.single({ id: e.id }, 'maindataOrganizationCategory').then((res : any) => {
  360. if (res.code === 200) {
  361. let data = res.data;
  362. this.radio = res.data.status;
  363. if(data.parentId!=0){
  364. api.single({ id: data.parentId }, 'maindataOrganizationCategory').then((res : any) => {
  365. loading.close();
  366. if (res.code === 200) {
  367. data.parentName = res.data.name;
  368. this.dialogFormVisible = true;
  369. this.$nextTick(() => (this as any).$refs.addFormId.setValue(data));
  370. }
  371. }).catch(() => loading.close());
  372. }else{
  373. loading.close();
  374. this.dialogFormVisible = true;
  375. setTimeout(() => { (this as any).$refs.addFormId.setValue(data) }, 0);
  376. }
  377. }
  378. }).catch(() => loading.close());
  379. }
  380. // 操作删除
  381. doDelete(item : any) {
  382. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  383. confirmButtonText: '确定',
  384. cancelButtonText: '取消',
  385. type: 'warning',
  386. center: true
  387. }).then(() => {
  388. api.delCategoryId({ id: item.id }, 'maindataOrganizationCategory').then((res : any) => {
  389. if (res.code === 200) {
  390. // (this as any).$refs.sideTree.request();
  391. this.getTreeList();
  392. this.getDataList();
  393. this.$message.success('删除成功!');
  394. } else this.$message.error(res.msg);
  395. }).catch(() => {});
  396. }).catch(() => {
  397. this.$message.info('已取消删除');
  398. });
  399. }
  400. // 刷新/重置
  401. onRefresh() {
  402. (this as any).$refs.moduleView.clearSearch();
  403. // (this as any).$refs.sideTree.request();
  404. this.getTreeList();
  405. this.parentIds = '';
  406. this.getDataList();
  407. }
  408. }
  409. </script>
  410. <style>
  411. .bill-tab{max-height: 100%;overflow-y: auto !important;}
  412. .el-popover{max-height: 400px;overflow-y: auto;}
  413. </style>
  414. <style lang="scss" scoped>
  415. .my-container {
  416. width: 100%;
  417. box-sizing: border-box;
  418. display: flex;
  419. padding: 16px;
  420. height: 100%;
  421. .bill-left {
  422. position: relative;
  423. border-right: solid #EEE 1px;
  424. padding-right: 16px;
  425. flex-shrink: 0;
  426. .bill-tab {
  427. width: 210px;
  428. height: 100%;
  429. transition: all .5s;
  430. overflow: auto;
  431. }
  432. .tab-title {
  433. font-size: 16px;
  434. padding-bottom: 16px;
  435. width: 200px;
  436. }
  437. }
  438. .bill-main {
  439. width: calc(100% - 16px);
  440. box-sizing: border-box;
  441. margin-left: 16px;
  442. position: relative;
  443. height: 100%;
  444. overflow-y: hidden;
  445. }
  446. }
  447. </style>