index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <div class="my-container">
  3. <div class="bill-left">
  4. <div class="bill-tab">
  5. <div class="tab-title">导航</div>
  6. <side-tree :propConfig="treeConfig" @onChange="onChangeTree" ref="sideTree" />
  7. </div>
  8. </div>
  9. <div class="bill-main">
  10. <module-view :propConfig="config" ref="moduleView" @pagination="getDataList" @search="getDataList"
  11. @resert="onRefresh" @clickHandle="clickHandle" @detail="openEdit" @onRefresh="onRefresh">
  12. </module-view>
  13. </div>
  14. <!-- 新增/编辑弹窗 -->
  15. <el-dialog :title="popTitle+'机构商品分类'" :visible.sync="dialogFormVisible" width="30%" :destroy-on-close="true">
  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:select-tree class="clearfix">
  24. </template>
  25. <template v-slot:status class="clearfix">
  26. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="0">正常</el-radio>
  27. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="1">禁用</el-radio>
  28. </template>
  29. </by-form>
  30. <div slot="footer" class="dialog-footer">
  31. <el-button @click="dialogFormVisible = false">取 消</el-button>
  32. <el-button type="primary" @click="confirm">确 定</el-button>
  33. </div>
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script lang="ts">
  38. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  39. import api from "@/api/currency";
  40. import Assembly from "@/components/Assembly/material.vue";
  41. @Component
  42. export default class AgencyGoods extends Vue {
  43. parentId : any = 0
  44. parentIds : any = ''
  45. timeNum = 0;
  46. timer : any = null
  47. popTitle : any = ''
  48. radio : any = 0
  49. dialogFormVisible : boolean = false
  50. treeConfig = {
  51. attr: {
  52. retConfig: {
  53. id: 'id',
  54. name: 'name'
  55. },
  56. defaultExpandAll: true,
  57. label: 'name',
  58. // resType: 'data'
  59. },
  60. // request: {
  61. // url: '/maindata/maindataMaterialOrganizationCategory/treeList',
  62. // method: 'GET'
  63. // }
  64. }
  65. config : any = {
  66. attr:{
  67. calculateH:true
  68. },
  69. search: {
  70. attr: {
  71. size: 'mini'
  72. },
  73. columns: [
  74. [{
  75. span: 6,
  76. label: '名称',
  77. prop: 'name',
  78. component: 'by-input',
  79. labelWidth: '70px',
  80. compConfig: {
  81. attr: {
  82. placeholder: '请输入名称',
  83. clearable: true
  84. },
  85. },
  86. },
  87. {
  88. span: 6,
  89. label: '简称',
  90. prop: 'shortName',
  91. component: 'by-input',
  92. labelWidth: '70px',
  93. compConfig: {
  94. attr: {
  95. placeholder: '请输入简称',
  96. clearable: true
  97. },
  98. },
  99. },
  100. {
  101. span: 6,
  102. label: '状态',
  103. prop: 'status',
  104. component: 'by-select',
  105. labelWidth: '70px',
  106. compConfig: {
  107. attr: {
  108. placeholder: '请选择状态',
  109. clearable: true,
  110. size: 'small',
  111. data: [{
  112. value: 0,
  113. label: '正常'
  114. }, {
  115. value: 1,
  116. label: '禁用'
  117. }]
  118. }
  119. }
  120. },
  121. ]
  122. ]
  123. },
  124. tool: {
  125. tools: {
  126. add: true,
  127. search: true,
  128. refresh: true
  129. }
  130. },
  131. table: {
  132. attr: {
  133. size: 'mini',
  134. align: 'left',
  135. checkbox: false,
  136. },
  137. columns: [{
  138. width: 300,
  139. title: '名称',
  140. field: 'name',
  141. isDetail: true,
  142. }, {
  143. title: '简称',
  144. field: 'shortName'
  145. },
  146. {
  147. title: '备注',
  148. field: 'remark',
  149. },{
  150. width: 80,
  151. title: '状态',
  152. field: 'status',
  153. align: 'center',
  154. component: Assembly,
  155. }, {
  156. width: 120,
  157. title: '操作',
  158. action: true,
  159. plugins: [{
  160. icon: 'el-icon-edit',
  161. name: '编辑',
  162. audit: '',
  163. event: {
  164. click: (item : any) => {
  165. (this as any).openEdit(item)
  166. }
  167. }
  168. }, {
  169. name: '删除',
  170. event: {
  171. click: (item : any) => (this as any).doDelete(item)
  172. }
  173. }]
  174. }]
  175. },
  176. }
  177. addConfig = {
  178. attr: {
  179. size: 'small',
  180. rules: {
  181. name: [{
  182. required: true, message: '请输入名称', trigger: 'blur'
  183. }],
  184. // parentName: [{
  185. // required: true, message: '请选择上级', trigger: 'change'
  186. // }],
  187. }
  188. },
  189. columns: [
  190. [
  191. {
  192. span: 23,
  193. label: '上级',
  194. labelWidth: '70px',
  195. prop: 'parentName',
  196. component: 'select-tree',
  197. slot: true,
  198. compConfig: {
  199. attr: {
  200. label: 'name',
  201. clearable: true,
  202. retConfig: {
  203. parentId: 'id',
  204. parentName: 'name',
  205. },
  206. defaultExpandAll: true
  207. },
  208. request: {
  209. url: '/maindata/maindataMaterialOrganizationCategory/treeUseList'
  210. }
  211. }
  212. },
  213. {
  214. labelWidth: '70px',
  215. span: 23,
  216. label: '名称',
  217. prop: 'name',
  218. component: 'by-input',
  219. },
  220. {
  221. labelWidth: '70px',
  222. span: 23,
  223. label: '简称',
  224. slot: true,
  225. prop: 'shortName',
  226. component: 'by-input',
  227. },
  228. {
  229. labelWidth: '70px',
  230. span: 23,
  231. label: '状态',
  232. slot: true,
  233. prop: 'status',
  234. },
  235. {
  236. labelWidth: '70px',
  237. span: 23,
  238. label: '备注',
  239. slot: true,
  240. prop: 'remark',
  241. component: 'by-input',
  242. compConfig: {
  243. attr: {
  244. size: 'mini',
  245. placeholder: '请输入备注',
  246. type: 'textarea'
  247. },
  248. }
  249. },
  250. ],
  251. ]
  252. }
  253. mounted() {
  254. this.timer = setInterval(() => {
  255. this.getDataList()
  256. }, 300)
  257. this.getTreeList();
  258. }
  259. getTreeList(){
  260. api.treeList('maindataMaterialOrganizationCategory').then((res : any) => {
  261. console.log(res);
  262. var data:any = [{
  263. id: 0,
  264. name: '机构商品分类',
  265. children: res.data
  266. }];
  267. (this as any).$refs.sideTree.setData(data);
  268. })
  269. }
  270. //点击树获取数据
  271. onChangeTree(e : any) {
  272. let data : any = {};
  273. e.isContain ? data.ids = e.id : data.parentId = e.id;
  274. this.parentIds = (this as any).$lodash.cloneDeep(e.id);
  275. this.parentId = e.id[0];
  276. data.pageSize = 20;
  277. data.pageNo = 1;
  278. let loading = this.$loading({ target: '.main-container' });
  279. api.childrenTreeList(data, 'maindataMaterialOrganizationCategory').then((res : any) => {
  280. loading.close();
  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. }
  290. }).catch(() => loading.close());
  291. }
  292. // 确认新增/编辑
  293. confirm() {
  294. (this as any).$refs.addFormId.validate().then(() => {
  295. let query = (this as any).$refs.addFormId.getValue();
  296. query.status = this.radio;
  297. if (this.popTitle === '新增') {
  298. if(!query.parentId){
  299. query.parentId=0
  300. }
  301. api.saveList(query, 'maindataMaterialOrganizationCategory').then((res : any) => {
  302. if (res.code === 200) {
  303. this.$message.success(this.popTitle + '成功!');
  304. // (this as any).$refs.sideTree.request();
  305. this.getTreeList()
  306. this.dialogFormVisible = false;
  307. this.getDataList();
  308. } else this.$message.error(res.msg);
  309. }).catch(() => {});
  310. } else if (this.popTitle === '编辑') {
  311. if(!query.parentId){
  312. query.parentId=0
  313. }
  314. if(query.parentId==query.id){
  315. this.$message.error('不能设置自己是自己的上级节点')
  316. return false
  317. }
  318. api.updateList(query, 'maindataMaterialOrganizationCategory').then((res : any) => {
  319. if (res.code === 200) {
  320. this.$message.success(this.popTitle + '成功!');
  321. // (this as any).$refs.sideTree.request();
  322. this.getTreeList()
  323. this.dialogFormVisible = false;
  324. this.getDataList();
  325. } else this.$message.error(res.msg);
  326. }).catch(() => {});
  327. }
  328. }).catch(() => {});
  329. }
  330. // 获取列表数据
  331. getDataList() {
  332. if (!this.$refs.moduleView) {
  333. if (this.timeNum > 5) {
  334. clearInterval(this.timer)
  335. }
  336. this.timeNum++;
  337. return
  338. }
  339. clearInterval(this.timer)
  340. let query = (this.$refs.moduleView as any).getQuery();
  341. if (this.parentIds) query.parentIds = this.parentIds;
  342. console.log('表单字段 ==> ', query);
  343. this.getPageList(query)
  344. }
  345. getPageList(query : any) {
  346. let loading = this.$loading({ target: '.main-container' });
  347. api.pageList(query, 'maindataMaterialOrganizationCategory').then((res : any) => {
  348. loading.close();
  349. if (res.code === 200) {
  350. (this.$refs.moduleView as any).setTableValue(res.data.records);
  351. let page = {
  352. pageNo: res.data.current, //当前页
  353. pageSize: res.data.size, //每页条数
  354. total: res.data.total //总条数
  355. };
  356. (this.$refs.moduleView as any).setPage(page);
  357. } else this.$message.error(res.msg);
  358. }).catch(() => loading.close());
  359. }
  360. // 工具栏方法
  361. clickHandle(e : any) {
  362. if (e === 'onAdd') this.onAdd();
  363. }
  364. // 打开新增
  365. onAdd() {
  366. this.popTitle = '新增'
  367. this.dialogFormVisible = true;
  368. this.radio = 0
  369. this.getTreeList();
  370. setTimeout(() => {
  371. if(this.parentId!=0){
  372. var data = {
  373. parentName: '',
  374. parentId: 0
  375. }
  376. api.single({ id: this.parentId }, 'maindataMaterialOrganizationCategory').then((res : any) => {
  377. if (res.code === 200) {
  378. data.parentName = res.data.name;
  379. data.parentId = res.data.id;
  380. this.dialogFormVisible = true;
  381. setTimeout(() => { (this as any).$refs.addFormId.setValue(data) }, 0);
  382. }
  383. }).catch(() => {});
  384. }else{
  385. (this as any).$refs.addFormId.setValue();
  386. (this as any).$refs.addFormId.$refs['parentName--comp'][0].request();
  387. }
  388. }, 0)
  389. }
  390. // 打开编辑
  391. openEdit(e : any) {
  392. console.log('打开编辑 ==> ', e);
  393. this.popTitle = '编辑';
  394. let loading = this.$loading({ target: '.main-container' });
  395. this.getTreeList();
  396. api.single({ id: e.id }, 'maindataMaterialOrganizationCategory').then((res : any) => {
  397. if (res.code === 200) {
  398. let data = res.data;
  399. this.radio = data.status;
  400. if(data.parentId!=0){
  401. api.single({ id: data.parentId }, 'maindataMaterialOrganizationCategory').then((v : any) => {
  402. loading.close();
  403. if (v.code === 200) {
  404. data.parentName = v.data.name;
  405. this.dialogFormVisible = true;
  406. setTimeout(() => { (this as any).$refs.addFormId.setValue(data) }, 0);
  407. }
  408. }).catch(() => loading.close());
  409. }else{
  410. loading.close();
  411. this.dialogFormVisible = true;
  412. setTimeout(() => { (this as any).$refs.addFormId.setValue(data) }, 0);
  413. }
  414. }
  415. }).catch(() => loading.close());
  416. }
  417. // 操作删除
  418. doDelete(item : any) {
  419. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  420. confirmButtonText: '确定',
  421. cancelButtonText: '取消',
  422. type: 'warning',
  423. center: true
  424. }).then(() => {
  425. api.delCategoryId({ id: item.id }, 'maindataMaterialOrganizationCategory').then((res : any) => {
  426. if (res.code === 200) {
  427. // (this as any).$refs.sideTree.request();
  428. this.getTreeList()
  429. this.getDataList();
  430. this.$message.success('删除成功');
  431. } else this.$message.error(res.msg);
  432. }).catch(() => {});
  433. }).catch(() => this.$message.info('已取消删除'));
  434. }
  435. // 刷新/重置
  436. onRefresh() {
  437. (this as any).$refs.moduleView.clearSearch();
  438. // (this as any).$refs.sideTree.request();
  439. this.getTreeList()
  440. this.parentIds = '';
  441. this.getDataList();
  442. }
  443. }
  444. </script>
  445. <style>
  446. .bill-tab{max-height: 100%;overflow-y: auto !important;}
  447. .el-popover{max-height: 400px;overflow-y: auto;}
  448. </style>
  449. <style lang="scss" scoped>
  450. .my-container {
  451. width: 100%;
  452. box-sizing: border-box;
  453. display: flex;
  454. padding: 16px;
  455. height: 100%;
  456. .bill-left {
  457. position: relative;
  458. border-right: solid #EEE 1px;
  459. padding-right: 16px;
  460. flex-shrink: 0;
  461. .bill-tab {
  462. width: 210px;
  463. height: 100%;
  464. transition: all .5s;
  465. overflow: auto;
  466. }
  467. .tab-title {
  468. font-size: 16px;
  469. padding-bottom: 16px;
  470. width: 200px;
  471. }
  472. }
  473. .bill-main {
  474. width: calc(100% - 16px);
  475. box-sizing: border-box;
  476. margin-left: 16px;
  477. position: relative;
  478. height: 100%;
  479. overflow-y: hidden;
  480. }
  481. }
  482. </style>