index.vue 11 KB

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