index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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 ProductClassification 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/maindataMaterialCategory/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('maindataMaterialCategory').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. if (!query.parentId) query.parentId = 0;
  243. query.status = this.radio;
  244. this.dialogFormVisible = false;
  245. if (this.popTitle === '新增') {
  246. api.saveList(query, 'maindataMaterialCategory').then((res : any) => {
  247. if (res.code === 200) {
  248. this.$message({
  249. type: 'success',
  250. message: this.popTitle + '成功!'
  251. });
  252. this.getTreeList();
  253. this.getDataList();
  254. } else this.failHandle(res)
  255. })
  256. } else if (this.popTitle === '编辑') {
  257. api.updateList(query, 'maindataMaterialCategory').then((res : any) => {
  258. if (res.code === 200) {
  259. this.$message({
  260. type: 'success',
  261. message: this.popTitle + '成功!'
  262. });
  263. this.getTreeList();
  264. this.getDataList();
  265. } else this.failHandle(res)
  266. })
  267. }
  268. })
  269. }
  270. // 获取列表数据
  271. getDataList() {
  272. if (!this.$refs.moduleView) {
  273. if (this.timeNum > 5) {
  274. clearInterval(this.timer)
  275. }
  276. this.timeNum++;
  277. return
  278. }
  279. clearInterval(this.timer)
  280. let query = (this.$refs.moduleView as any).getQuery();
  281. query.parentId = this.parentId;
  282. let newData : any = {}
  283. for (let key in query) {
  284. if (query[key].toString()) {
  285. newData[key] = query[key]
  286. }
  287. }
  288. console.log('表单字段 ==> ', newData);
  289. api.pageList(newData, 'maindataMaterialCategory').then((res : any) => {
  290. if (res.code === 200) {
  291. (this.$refs.moduleView as any).setTableValue(res.data.records);
  292. let page = {
  293. pageNo: res.data.current, //当前页
  294. pageSize: res.data.size, //每页条数
  295. total: res.data.total //总条数
  296. };
  297. (this.$refs.moduleView as any).setPage(page)
  298. } else this.failHandle(res)
  299. })
  300. }
  301. // 工具栏方法
  302. clickHandle(e : any) {
  303. if (e === 'onRefresh') (this.$refs.moduleView as any).resert();
  304. if (e === 'onAdd') this.onAdd();
  305. if (e === 'onDelete') this.onDelete();
  306. if (e === 'onExport') this.onExport();
  307. }
  308. // 打开新增
  309. onAdd() {
  310. this.popTitle = '新增'
  311. this.dialogFormVisible = true;
  312. this.radio = 0
  313. setTimeout(() => {
  314. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue({});
  315. }, 0)
  316. }
  317. // 打开编辑
  318. openEdit(e : any) {
  319. console.log('打开编辑 ==> ', e);
  320. this.popTitle = '编辑'
  321. this.dialogFormVisible = true;
  322. this.radio = e.status
  323. api.single({ id: e.parentId }, 'maindataMaterialCategory').then((res : any) => {
  324. if (res.code === 200) {
  325. e.parentName = res.data.name
  326. setTimeout(() => {
  327. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue(e);
  328. }, 0)
  329. }
  330. })
  331. }
  332. // 工具栏删除
  333. onDelete() {
  334. let selectData = (this.$refs.moduleView as any).getSelectData()
  335. let ids = '';
  336. if (selectData.length > 0) {
  337. selectData.map((v : any) => {
  338. ids += v.id + ','
  339. })
  340. } else return this.$message({ type: 'warning', message: '请选择删除数据' })
  341. ids = ids.slice(0, ids.length - 1);
  342. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  343. confirmButtonText: '确定',
  344. cancelButtonText: '取消',
  345. type: 'warning',
  346. center: true
  347. }).then(() => {
  348. api.deleteList({ ids: ids }, 'maindataMaterialCategory').then((res : any) => {
  349. if (res.code === 200) {
  350. this.getTreeList();
  351. this.getDataList();
  352. this.$message({
  353. type: 'success',
  354. message: '删除成功!'
  355. });
  356. } else this.failHandle(res)
  357. })
  358. }).catch(() => {
  359. this.$message({
  360. type: 'info',
  361. message: '已取消删除'
  362. });
  363. });
  364. }
  365. // 操作删除
  366. doDelete2(item : any) {
  367. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  368. confirmButtonText: '确定',
  369. cancelButtonText: '取消',
  370. type: 'warning',
  371. center: true
  372. }).then(() => {
  373. api.childrenTreeList({ id: item.id }, 'maindataMaterialCategory').then((v : any) => {
  374. if (v.code === 200) {
  375. if (v.data.length > 0) return this.$message({ type: 'error', message: '此数据有子节点,不能进行删除!' })
  376. api.deleteList({ ids: item.id }, 'maindataMaterialCategory').then((res : any) => {
  377. if (res.code === 200) {
  378. this.getTreeList();
  379. this.getDataList();
  380. this.$message({
  381. type: 'success',
  382. message: '删除成功!'
  383. });
  384. } else this.failHandle(res)
  385. })
  386. } else this.$message({ type: 'error', message: '删除失败!请稍后再试' })
  387. })
  388. }).catch(() => {
  389. this.$message({
  390. type: 'info',
  391. message: '已取消删除'
  392. });
  393. });
  394. }
  395. // 导航切换
  396. handleNodeClick(e : any) {
  397. this.parentId = e.id
  398. api.childrenTreeList({ id: e.id }, 'maindataMaterialCategory').then((res : any) => {
  399. if (res.code === 200) {
  400. (this.$refs.moduleView as any).setTableValue(res.data);
  401. let page = {
  402. pageNo: res.data.current, //当前页
  403. pageSize: res.data.size, //每页条数
  404. total: res.data.total //总条数
  405. };
  406. (this.$refs.moduleView as any).setPage(page)
  407. }
  408. })
  409. }
  410. //导出
  411. onExport() {
  412. let urlArr = '/maindata/maindataMaterial';
  413. let query = (this.$refs.moduleView as any).getQuery();
  414. (this as any).$download(urlArr + '/export', {
  415. ...query
  416. }, urlArr[urlArr.length - 1] + `_${new Date().getTime()}.xlsx`)
  417. }
  418. // 运行错误
  419. failHandle(err : any) {
  420. let msg = err.msg ? err.msg : '运行错误!';
  421. this.$message.error(msg)
  422. }
  423. }
  424. </script>
  425. <style lang="scss" scoped>
  426. .my-container {
  427. width: 100%;
  428. box-sizing: border-box;
  429. display: flex;
  430. padding: 16px;
  431. .search-btn {
  432. width: 100%;
  433. display: flex;
  434. justify-content: flex-end;
  435. margin-bottom: 20px;
  436. }
  437. .bill-left {
  438. position: relative;
  439. border-right: solid #EEE 1px;
  440. padding-right: 16px;
  441. flex-shrink: 0;
  442. // box-sizing: border-box;
  443. .bill-tab {
  444. width: 150px;
  445. height: 100%;
  446. transition: all .5s;
  447. overflow: hidden;
  448. }
  449. .title {
  450. font-size: 16px;
  451. padding-bottom: 16px;
  452. width: 200px;
  453. }
  454. .bill-nav {
  455. font-size: 14px;
  456. height: 30px;
  457. line-height: 30px;
  458. width: 200px;
  459. box-sizing: border-box;
  460. padding: 0 8px;
  461. cursor: pointer;
  462. margin-bottom: 2px;
  463. border-radius: 5px;
  464. }
  465. .onBill {
  466. background-color: #bde3f7;
  467. }
  468. .bill-nav:hover {
  469. background-color: #bde3f7;
  470. }
  471. .close {
  472. height: 22px;
  473. width: 22px;
  474. border-radius: 50%;
  475. border: solid #EEE 1px;
  476. position: absolute;
  477. top: 30px;
  478. right: -11px;
  479. background-color: #FFF;
  480. display: flex;
  481. justify-content: center;
  482. align-items: center;
  483. cursor: pointer;
  484. }
  485. }
  486. .bill-main {
  487. width: calc(100% - 16px);
  488. box-sizing: border-box;
  489. margin-left: 16px;
  490. position: relative;
  491. .bill-box {
  492. width: 100%;
  493. position: absolute;
  494. left: 0;
  495. top: 0;
  496. opacity: 0;
  497. z-index: -1;
  498. transition: all .5s;
  499. .bill-tool,
  500. .table-tool {
  501. width: 100%;
  502. padding-bottom: 16px;
  503. }
  504. .form {
  505. margin-bottom: 8px;
  506. }
  507. }
  508. .on-show {
  509. opacity: 1;
  510. z-index: 1;
  511. }
  512. }
  513. }
  514. </style>