index.vue 11 KB

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