index.vue 11 KB

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