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