index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <div class="my-container">
  3. <div class="bill-left">
  4. <div class="bill-tab">
  5. <div class="title">导航</div>
  6. <el-tree :data="data" :props="props" @node-click="handleNodeClick"></el-tree>
  7. </div>
  8. </div>
  9. <div class="bill-main">
  10. <module-view :propConfig="config" ref="moduleView" @pagination="getDataList" @search="getDataList"
  11. @resert="getDataList" @clickHandle="clickHandle" @detail="openEdit">
  12. </module-view>
  13. </div>
  14. <!-- 新增/编辑弹窗 -->
  15. <el-dialog :title="popTitle+'虚拟分类'" :visible.sync="dialogFormVisible" width="30%">
  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. data : any = []
  37. parentId:any=''
  38. props = {
  39. label: 'name',
  40. children: 'children'
  41. }
  42. // 右边
  43. baseURL : any = process.env.VUE_APP_BASE_API
  44. timeNum = 0;
  45. timer : any = null
  46. popTitle : any = ''
  47. radio : any = 0
  48. dialogFormVisible : boolean = false
  49. config : any = {
  50. search: {
  51. attr: {
  52. size: 'mini'
  53. },
  54. columns: [
  55. [{
  56. span: 6,
  57. label: '名称',
  58. prop: 'name',
  59. component: 'by-input',
  60. labelWidth: '70px',
  61. compConfig: {
  62. attr: {
  63. placeholder: '请输入名称',
  64. clearable: true
  65. },
  66. },
  67. },
  68. {
  69. span: 6,
  70. label: '简称',
  71. prop: 'shortName',
  72. component: 'by-input',
  73. labelWidth: '70px',
  74. compConfig: {
  75. attr: {
  76. placeholder: '请输入简称',
  77. clearable: true
  78. },
  79. },
  80. },
  81. {
  82. span: 6,
  83. label: '状态',
  84. prop: 'status',
  85. component: 'by-select',
  86. labelWidth: '70px',
  87. compConfig: {
  88. attr: {
  89. placeholder: '请选择数据',
  90. clearable: true,
  91. data: [{
  92. value: 0,
  93. label: '正常'
  94. }, {
  95. value: 1,
  96. label: '禁用'
  97. }]
  98. }
  99. }
  100. },
  101. ]
  102. ]
  103. },
  104. tool: {
  105. tools: {
  106. add: true,
  107. // delete: true,
  108. search: true,
  109. refresh: true
  110. }
  111. },
  112. table: {
  113. attr: {
  114. size: 'mini',
  115. seq: true,
  116. align: 'center',
  117. checkbox: false,
  118. height: 600
  119. },
  120. columns: [{
  121. width: 300,
  122. title: '名称',
  123. field: 'name',
  124. isDetail: true,
  125. }, {
  126. title: '简称',
  127. field: 'shortName'
  128. }, {
  129. width: 80,
  130. title: '状态',
  131. field: 'status',
  132. component: Assembly,
  133. },
  134. {
  135. title: '备注',
  136. field: 'remark',
  137. }, {
  138. width: 120,
  139. title: '操作',
  140. action: true,
  141. plugins: [{
  142. icon: 'el-icon-edit',
  143. name: '编辑',
  144. audit: '',
  145. event: {
  146. click: (item : any) => {
  147. (this as any).openEdit(item)
  148. }
  149. }
  150. }, {
  151. name: '删除',
  152. event: {
  153. click: (item : any) => (this as any).doDelete2(item)
  154. }
  155. }]
  156. }]
  157. },
  158. }
  159. addConfig = {
  160. attr: {
  161. size: 'small',
  162. rules: {
  163. name: [{
  164. required: true, message: '请输入名称', trigger: 'blur'
  165. }],
  166. }
  167. },
  168. columns: [
  169. [
  170. {
  171. span: 23,
  172. label: '父级',
  173. labelWidth: '70px',
  174. prop: 'parentName',
  175. component: 'select-tree',
  176. compConfig: {
  177. attr: {
  178. label: 'name',
  179. clearable: true,
  180. retConfig: {
  181. parentId: 'id',
  182. }
  183. },
  184. request: {
  185. url: '/maindata/maindataMaterialVmcategory/treeList'
  186. }
  187. }
  188. },
  189. {
  190. span: 23,
  191. labelWidth: '70px',
  192. label: '名称',
  193. prop: 'name',
  194. component: 'by-input',
  195. },
  196. {
  197. span: 23,
  198. labelWidth: '70px',
  199. label: '简称',
  200. slot: true,
  201. prop: 'shortName',
  202. component: 'by-input',
  203. },
  204. {
  205. span: 23,
  206. labelWidth: '70px',
  207. label: '状态',
  208. slot: true,
  209. prop: 'status',
  210. },
  211. {
  212. span: 23,
  213. labelWidth: '70px',
  214. label: '备注',
  215. slot: true,
  216. prop: 'remark',
  217. component: 'by-input',
  218. },
  219. ],
  220. ]
  221. }
  222. mounted() {
  223. this.getTreeList()
  224. this.timer = setInterval(() => {
  225. this.getDataList()
  226. }, 500)
  227. }
  228. // 获取树型导航数据
  229. getTreeList() {
  230. api.treeList('maindataMaterialVmcategory').then((res : any) => {
  231. // console.log(res.data[0]);
  232. if (res.code === 200) {
  233. this.data = res.data;
  234. } else this.failHandle(res)
  235. })
  236. }
  237. // 确认新增/编辑
  238. confirm() {
  239. (this as any).$refs.addFormId.validate().then(() => {
  240. let query = (this as any).$refs.addFormId.getValue();
  241. console.log(query);
  242. query.status = this.radio;
  243. this.dialogFormVisible = false;
  244. if (this.popTitle === '新增') {
  245. api.saveList(query, 'maindataMaterialVmcategory').then((res : any) => {
  246. if (res.code === 200) {
  247. this.$message({
  248. type: 'success',
  249. message: this.popTitle + '成功!'
  250. });
  251. this.getTreeList();
  252. this.getDataList();
  253. } else this.failHandle(res)
  254. })
  255. } else if (this.popTitle === '编辑') {
  256. api.updateList(query, 'maindataMaterialVmcategory').then((res : any) => {
  257. if (res.code === 200) {
  258. this.$message({
  259. type: 'success',
  260. message: this.popTitle + '成功!'
  261. });
  262. this.getTreeList();
  263. this.getDataList();
  264. } else this.failHandle(res)
  265. })
  266. }
  267. })
  268. }
  269. // 获取列表数据
  270. getDataList() {
  271. if (!this.$refs.moduleView) {
  272. if (this.timeNum > 5) {
  273. clearInterval(this.timer)
  274. }
  275. this.timeNum++;
  276. return
  277. }
  278. clearInterval(this.timer)
  279. let query = (this.$refs.moduleView as any).getQuery();
  280. query.parentId = this.parentId;
  281. console.log('表单字段 ==> ', query);
  282. api.pageList(query, 'maindataMaterialVmcategory').then((res : any) => {
  283. if (res.code === 200) {
  284. (this.$refs.moduleView as any).setTableValue(res.data.records);
  285. let page = {
  286. pageNo: res.data.current, //当前页
  287. pageSize: res.data.size, //每页条数
  288. total: res.data.total //总条数
  289. };
  290. (this.$refs.moduleView as any).setPage(page)
  291. } else this.failHandle(res)
  292. })
  293. }
  294. // 工具栏方法
  295. clickHandle(e : any) {
  296. if (e === 'onRefresh') (this.$refs.moduleView as any).resert();
  297. if (e === 'onAdd') this.onAdd();
  298. if (e === 'onDelete') this.onDelete();
  299. if (e === 'onExport') this.onExport();
  300. }
  301. // 打开新增
  302. onAdd() {
  303. this.popTitle = '新增'
  304. this.dialogFormVisible = true;
  305. this.radio = 0
  306. setTimeout(() => {
  307. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue({});
  308. }, 0)
  309. }
  310. // 打开编辑
  311. openEdit(e : any) {
  312. this.popTitle = '编辑'
  313. this.dialogFormVisible = true;
  314. this.radio = e.status
  315. api.single({id:e.parentId},'maindataMaterialVmcategory').then((res:any) =>{
  316. if(res.code===200){
  317. e.parentName = res.data.name
  318. setTimeout(() => {
  319. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue(e);
  320. }, 0)
  321. }
  322. })
  323. }
  324. // 工具栏删除
  325. onDelete() {
  326. let selectData = (this.$refs.moduleView as any).getSelectData()
  327. let ids = '';
  328. if (selectData.length > 0) {
  329. selectData.map((v : any) => {
  330. ids += v.id + ','
  331. })
  332. } else return this.$message({ type: 'warning', message: '请选择删除数据' })
  333. ids = ids.slice(0, ids.length - 1);
  334. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  335. confirmButtonText: '确定',
  336. cancelButtonText: '取消',
  337. type: 'warning',
  338. center: true
  339. }).then(() => {
  340. api.deleteList({ ids: ids }, 'maindataMaterialVmcategory').then((res : any) => {
  341. if (res.code === 200) {
  342. this.getTreeList();
  343. this.getDataList();
  344. this.$message({
  345. type: 'success',
  346. message: '删除成功!'
  347. });
  348. } else this.failHandle(res)
  349. })
  350. }).catch(() => {
  351. this.$message({
  352. type: 'info',
  353. message: '已取消删除'
  354. });
  355. });
  356. }
  357. // 操作删除
  358. doDelete2(item : any) {
  359. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  360. confirmButtonText: '确定',
  361. cancelButtonText: '取消',
  362. type: 'warning',
  363. center: true
  364. }).then(() => {
  365. api.childrenTreeList({ id: item.id }, 'maindataMaterialVmcategory').then((v : any) => {
  366. if (v.code === 200) {
  367. if (v.data.length > 0) return this.$message({ type: 'error', message: '此数据有子节点,不能进行删除!' })
  368. api.deleteList({ ids: item.id }, 'maindataMaterialVmcategory').then((res : any) => {
  369. if (res.code === 200) {
  370. this.getTreeList();
  371. this.getDataList();
  372. this.$message({
  373. type: 'success',
  374. message: '删除成功!'
  375. });
  376. } else this.failHandle(res)
  377. })
  378. } else this.$message({ type: 'error', message: '删除失败!请稍后再试' })
  379. })
  380. }).catch(() => {
  381. this.$message({
  382. type: 'info',
  383. message: '已取消删除'
  384. });
  385. });
  386. }
  387. // 导航切换
  388. handleNodeClick(e : any) {
  389. this.parentId=e.id
  390. api.childrenTreeList({ id: e.id }, 'maindataMaterialVmcategory').then((res : any) => {
  391. if (res.code === 200) {
  392. (this.$refs.moduleView as any).setTableValue(res.data);
  393. let page = {
  394. pageNo: res.data.current, //当前页
  395. pageSize: res.data.size, //每页条数
  396. total: res.data.total //总条数
  397. };
  398. (this.$refs.moduleView as any).setPage(page)
  399. }
  400. })
  401. }
  402. //导出
  403. onExport() {
  404. let urlArr = '/maindata/maindataMaterial';
  405. let query = (this.$refs.moduleView as any).getQuery();
  406. (this as any).$download(urlArr + '/export', {
  407. ...query
  408. }, urlArr[urlArr.length - 1] + `_${new Date().getTime()}.xlsx`)
  409. }
  410. // 运行错误
  411. failHandle(err : any) {
  412. let msg = err.msg ? err.msg : '运行错误!';
  413. this.$message.error(msg)
  414. }
  415. }
  416. </script>
  417. <style lang="scss" scoped>
  418. .my-container {
  419. width: 100%;
  420. box-sizing: border-box;
  421. display: flex;
  422. padding: 16px;
  423. .search-btn {
  424. width: 100%;
  425. display: flex;
  426. justify-content: flex-end;
  427. margin-bottom: 20px;
  428. }
  429. .bill-left {
  430. position: relative;
  431. border-right: solid #EEE 1px;
  432. padding-right: 16px;
  433. flex-shrink: 0;
  434. // box-sizing: border-box;
  435. .bill-tab {
  436. width: 150px;
  437. height: 100%;
  438. transition: all .5s;
  439. overflow: hidden;
  440. }
  441. .title {
  442. font-size: 16px;
  443. padding-bottom: 16px;
  444. width: 200px;
  445. }
  446. .bill-nav {
  447. font-size: 14px;
  448. height: 30px;
  449. line-height: 30px;
  450. width: 200px;
  451. box-sizing: border-box;
  452. padding: 0 8px;
  453. cursor: pointer;
  454. margin-bottom: 2px;
  455. border-radius: 5px;
  456. }
  457. .onBill {
  458. background-color: #bde3f7;
  459. }
  460. .bill-nav:hover {
  461. background-color: #bde3f7;
  462. }
  463. .close {
  464. height: 22px;
  465. width: 22px;
  466. border-radius: 50%;
  467. border: solid #EEE 1px;
  468. position: absolute;
  469. top: 30px;
  470. right: -11px;
  471. background-color: #FFF;
  472. display: flex;
  473. justify-content: center;
  474. align-items: center;
  475. cursor: pointer;
  476. }
  477. }
  478. .bill-main {
  479. width: calc(100% - 16px);
  480. box-sizing: border-box;
  481. margin-left: 16px;
  482. position: relative;
  483. .bill-box {
  484. width: 100%;
  485. position: absolute;
  486. left: 0;
  487. top: 0;
  488. opacity: 0;
  489. z-index: -1;
  490. transition: all .5s;
  491. .bill-tool,
  492. .table-tool {
  493. width: 100%;
  494. padding-bottom: 16px;
  495. }
  496. .form {
  497. margin-bottom: 8px;
  498. }
  499. }
  500. .on-show {
  501. opacity: 1;
  502. z-index: 1;
  503. }
  504. }
  505. }
  506. </style>