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