index.vue 10 KB

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