index.vue 12 KB

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