index.vue 11 KB

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