index.vue 12 KB

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