index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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 Supplier 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: 'contacts',
  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. {
  113. title: '负责人',
  114. field: 'contacts',
  115. width: 300,
  116. },
  117. {
  118. width: 80,
  119. title: '状态',
  120. field: 'status',
  121. component: Assembly,
  122. }, {
  123. width: 500,
  124. title: '备注',
  125. field: 'remark',
  126. }, {
  127. width: 120,
  128. title: '操作',
  129. action: true,
  130. plugins: [{
  131. icon: 'el-icon-edit',
  132. name: '编辑',
  133. audit: '',
  134. event: {
  135. click: (item : any) => {
  136. (this as any).openEdit(item)
  137. }
  138. }
  139. }, {
  140. name: '删除',
  141. event: {
  142. click: (item : any) => (this as any).doDelete2(item)
  143. }
  144. }]
  145. }]
  146. },
  147. }
  148. addConfig = {
  149. attr: {
  150. size: 'small',
  151. rules: {
  152. name: [{
  153. required: true, message: '请输入名称', trigger: 'blur'
  154. }],
  155. contacts: [{
  156. required: true, message: '请输入负责人', trigger: 'blur'
  157. }]
  158. }
  159. },
  160. columns: [
  161. [
  162. {
  163. span: 23,
  164. labelWidth: '70px',
  165. label: '名称',
  166. prop: 'name',
  167. component: 'by-input',
  168. },
  169. {
  170. span: 23,
  171. labelWidth: '70px',
  172. label: '负责人',
  173. prop: 'contacts',
  174. component: 'by-input',
  175. },
  176. {
  177. span: 23,
  178. labelWidth: '70px',
  179. label: '状态',
  180. slot: true,
  181. prop: 'status',
  182. },
  183. ],
  184. [
  185. {
  186. span: 23,
  187. labelWidth: '70px',
  188. label: '备注',
  189. prop: 'remark',
  190. component: 'by-input',
  191. compConfig: {
  192. attr: {
  193. size: 'mini',
  194. placeholder: '请输入备注',
  195. type:'textarea'
  196. },
  197. }
  198. },
  199. ]
  200. ]
  201. }
  202. mounted() {
  203. this.timer = setInterval(() => {
  204. this.getDataList()
  205. }, 300)
  206. }
  207. // 确认新增/编辑
  208. confirm() {
  209. (this as any).$refs.addFormId.validate().then(() => {
  210. let query = (this as any).$refs.addFormId.getValue();
  211. console.log(query);
  212. query.status = this.radio;
  213. this.dialogFormVisible = false;
  214. if (this.popTitle === '新增') {
  215. api.saveList(query, 'maindataMaterialSupplier').then((res : any) => {
  216. if (res.code === 200) {
  217. this.$message.success(this.popTitle + '成功!');
  218. this.getDataList();
  219. } else this.$message.error(res.msg);
  220. })
  221. } else if (this.popTitle === '编辑') {
  222. api.updateList(query, 'maindataMaterialSupplier').then((res : any) => {
  223. if (res.code === 200) {
  224. this.$message({
  225. type: 'success',
  226. message: this.popTitle + '成功!'
  227. });
  228. this.getDataList();
  229. } else this.$message.error(res.msg);
  230. })
  231. }
  232. })
  233. }
  234. // 获取列表数据
  235. getDataList() {
  236. if (!this.$refs.moduleView) {
  237. if (this.timeNum > 5) {
  238. clearInterval(this.timer)
  239. }
  240. this.timeNum++;
  241. return
  242. }
  243. clearInterval(this.timer)
  244. let query = (this.$refs.moduleView as any).getQuery();
  245. api.pageList(query, 'maindataMaterialSupplier').then((res : any) => {
  246. if (res.code === 200) {
  247. (this.$refs.moduleView as any).setTableValue(res.data.records);
  248. let page = {
  249. pageNo: res.data.current, //当前页
  250. pageSize: res.data.size, //每页条数
  251. total: res.data.total //总条数
  252. };
  253. (this.$refs.moduleView as any).setPage(page)
  254. } else this.$message.error(res.msg);
  255. })
  256. }
  257. // 工具栏方法
  258. clickHandle(e : any) {
  259. if (e === 'onAdd') this.onAdd();
  260. if (e === 'onDelete') this.onDelete();
  261. if (e === 'onExport') this.onExport();
  262. }
  263. // 打开新增
  264. onAdd() {
  265. this.popTitle = '新增'
  266. this.dialogFormVisible = true;
  267. this.radio = 0
  268. setTimeout(() => {
  269. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue('');
  270. }, 0)
  271. }
  272. // 打开编辑
  273. openEdit(e : any) {
  274. this.popTitle = '编辑'
  275. this.dialogFormVisible = true;
  276. this.radio = e.status
  277. setTimeout(() => {
  278. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue(e);
  279. }, 0)
  280. }
  281. // 工具栏删除
  282. onDelete() {
  283. let selectData = (this.$refs.moduleView as any).getSelectData()
  284. let ids = '';
  285. if (selectData.length > 0) {
  286. selectData.map((v : any) => {
  287. ids += v.id + ','
  288. })
  289. } else return this.$message({ type: 'warning', message: '请选择删除数据' })
  290. ids = ids.slice(0, ids.length - 1);
  291. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  292. confirmButtonText: '确定',
  293. cancelButtonText: '取消',
  294. type: 'warning',
  295. center: true
  296. }).then(() => {
  297. api.deleteList({ ids: ids }, 'maindataMaterialSupplier').then((res : any) => {
  298. if (res.code === 200) {
  299. this.getDataList();
  300. this.$message({
  301. type: 'success',
  302. message: '删除成功!'
  303. });
  304. } else this.$message.error(res.msg);
  305. })
  306. }).catch(() => {
  307. this.$message({
  308. type: 'info',
  309. message: '已取消删除'
  310. });
  311. });
  312. }
  313. // 操作删除
  314. doDelete2(item : any) {
  315. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  316. confirmButtonText: '确定',
  317. cancelButtonText: '取消',
  318. type: 'warning',
  319. center: true
  320. }).then(() => {
  321. api.deleteList({ ids: item.id }, 'maindataMaterialSupplier').then((res : any) => {
  322. if (res.code === 200) {
  323. this.getDataList();
  324. this.$message({
  325. type: 'success',
  326. message: '删除成功!'
  327. });
  328. } else this.$message.error(res.msg);
  329. })
  330. }).catch(() => {
  331. this.$message.info('已取消删除');
  332. });
  333. }
  334. // 刷新
  335. onRefresh(){
  336. this.loading = this.$loading({ target: '.main-container' });
  337. (this as any).$refs.moduleView.clearSearch();
  338. api.pageList({}, 'maindataMaterialSupplier').then((res : any) => {
  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. this.loading.close();
  348. } else this.$message.error(res.msg);
  349. })
  350. }
  351. //导出
  352. onExport() {
  353. let urlArr = '/maindata/maindataMaterial';
  354. let query = (this.$refs.moduleView as any).getQuery();
  355. (this as any).$download(urlArr + '/export', {
  356. ...query
  357. }, urlArr[urlArr.length - 1] + `_${new Date().getTime()}.xlsx`)
  358. }
  359. }
  360. </script>
  361. <style lang="scss" scoped>
  362. .my-container {
  363. width: 100%;
  364. box-sizing: border-box;
  365. display: flex;
  366. padding: 16px;
  367. .search-btn {
  368. width: 100%;
  369. display: flex;
  370. justify-content: flex-end;
  371. margin-bottom: 20px;
  372. }
  373. .bill-left {
  374. position: relative;
  375. border-right: solid #EEE 1px;
  376. padding-right: 16px;
  377. flex-shrink: 0;
  378. // box-sizing: border-box;
  379. .bill-tab {
  380. width: 150px;
  381. height: 100%;
  382. transition: all .5s;
  383. overflow: hidden;
  384. }
  385. .title {
  386. font-size: 16px;
  387. padding-bottom: 16px;
  388. width: 200px;
  389. }
  390. .bill-nav {
  391. font-size: 14px;
  392. height: 30px;
  393. line-height: 30px;
  394. width: 200px;
  395. box-sizing: border-box;
  396. padding: 0 8px;
  397. cursor: pointer;
  398. margin-bottom: 2px;
  399. border-radius: 5px;
  400. }
  401. .onBill {
  402. background-color: #bde3f7;
  403. }
  404. .bill-nav:hover {
  405. background-color: #bde3f7;
  406. }
  407. .close {
  408. height: 22px;
  409. width: 22px;
  410. border-radius: 50%;
  411. border: solid #EEE 1px;
  412. position: absolute;
  413. top: 30px;
  414. right: -11px;
  415. background-color: #FFF;
  416. display: flex;
  417. justify-content: center;
  418. align-items: center;
  419. cursor: pointer;
  420. }
  421. }
  422. .bill-main {
  423. width: calc(100% - 16px);
  424. box-sizing: border-box;
  425. margin-left: 16px;
  426. position: relative;
  427. .bill-box {
  428. width: 100%;
  429. position: absolute;
  430. left: 0;
  431. top: 0;
  432. opacity: 0;
  433. z-index: -1;
  434. transition: all .5s;
  435. .bill-tool,
  436. .table-tool {
  437. width: 100%;
  438. padding-bottom: 16px;
  439. }
  440. .form {
  441. margin-bottom: 8px;
  442. }
  443. }
  444. .on-show {
  445. opacity: 1;
  446. z-index: 1;
  447. }
  448. }
  449. }
  450. </style>