index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
  4. id="out-table" :header-cell-class-name="headerClassName" :before-open="beforeOpen" :search.sync="search"
  5. v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
  6. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  7. @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
  8. @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 299)"
  9. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 299)" @on-load="onLoad">
  10. <template slot="code" slot-scope="scope">
  11. <avue-text-ellipsis :text="scope.row.code" :height="30" use-tooltip placement="top">
  12. <small slot="more">...</small>
  13. </avue-text-ellipsis>
  14. </template>
  15. <template slot="cnName" slot-scope="scope">
  16. <avue-text-ellipsis :text="scope.row.cnName" :height="30" use-tooltip placement="top">
  17. <small slot="more">...</small>
  18. </avue-text-ellipsis>
  19. </template>
  20. <template slot="enName" slot-scope="scope">
  21. <avue-text-ellipsis :text="scope.row.enName" :height="30" use-tooltip placement="top">
  22. <small slot="more">...</small>
  23. </avue-text-ellipsis>
  24. </template>
  25. <template slot="remarks" slot-scope="scope">
  26. <avue-text-ellipsis :text="scope.row.remarks" :height="30" use-tooltip placement="top">
  27. <small slot="more">...</small>
  28. </avue-text-ellipsis>
  29. </template>
  30. <template slot="menuLeft">
  31. <el-button type="danger" size="small" icon="el-icon-delete" plain @click="handleDelete">删 除
  32. </el-button>
  33. <el-button type="warning" size="small" icon="el-icon-printer" @click="excelBox = true">导入
  34. </el-button>
  35. <el-button type="success" size="small" @click="handleExport" icon="el-icon-printer">导出</el-button>
  36. </template>
  37. <template slot-scope="scope" slot="menu">
  38. <el-button v-if="scope.row.status == 1" type="text" icon="el-icon-turn-off" style="color: #85e967" size="small"
  39. @click.stop="statusfun(scope.row.id,0)">
  40. 启用
  41. </el-button>
  42. <el-button v-if="scope.row.status == 0" type="text" icon="el-icon-turn-off" style="color: #e83c3a" size="small"
  43. @click.stop="statusfun(scope.row.id,1)">
  44. 停用
  45. </el-button>
  46. </template>
  47. </avue-crud>
  48. <el-dialog title="导入往来单位" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  49. v-dialog-drag>
  50. <avue-form :option="excelOption" v-model="excelForm" :table-loading="excelLoading" :upload-before="uploadBefore"
  51. :upload-after="onSuccess">
  52. <template slot="excelTemplate">
  53. <el-button type="primary" @click="handleGet">
  54. 点击下载<i class="el-icon-download el-icon--right"></i>
  55. </el-button>
  56. </template>
  57. </avue-form>
  58. <p style="text-align: center;color: #DC0505">
  59. 温馨提示 第一次导入时请先下载模板
  60. </p>
  61. </el-dialog>
  62. </basic-container>
  63. </template>
  64. <script>
  65. import { getBaccelementsList, getBaccelementsDetail, addBaccelements, updateBaccelements, removeBaccelements } from "@/api/iosBasicData/baccelements";
  66. import { mapGetters } from "vuex";
  67. import { getToken } from "@/util/auth";
  68. export default {
  69. data() {
  70. return {
  71. form: {},
  72. query: {},
  73. loading: true,
  74. excelBox: false,
  75. search: {},
  76. excelForm: {},
  77. excelLoading: false,
  78. excelOption: {
  79. submitBtn: false,
  80. emptyBtn: false,
  81. column: [
  82. {
  83. label: "模板下载",
  84. prop: "excelTemplate",
  85. formslot: true,
  86. span: 24
  87. },
  88. {
  89. label: "模板上传",
  90. prop: "excelFile",
  91. type: "upload",
  92. drag: true,
  93. loadText: "模板上传中,请稍等",
  94. span: 24,
  95. propsHttp: {
  96. res: "data"
  97. },
  98. tip: "请上传 .xls,.xlsx 标准格式文件",
  99. action: "/api/blade-los/baccelements/importBAccElements"
  100. }
  101. ]
  102. },
  103. page: {
  104. pageSize: 10,
  105. currentPage: 1,
  106. total: 0,
  107. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  108. },
  109. selectionList: [],
  110. option: {
  111. dialogDrag: true,
  112. },
  113. optionBack: {
  114. dialogDrag: true,
  115. addBtnText: '新建核算要素',
  116. addTitle: '新建核算要素',
  117. editBtnText: '编辑',
  118. editTitle: '编辑核算要素',
  119. viewBtnText: '查看',
  120. viewTitle: '查看核算要素',
  121. height: 'auto',
  122. stripe: true,
  123. calcHeight: 30,
  124. tip: false,
  125. searchShow: true,
  126. searchMenuSpan: 6,
  127. border: true,
  128. index: true,
  129. viewBtn: true,
  130. selection: true,
  131. dialogClickModal: false,
  132. menuWidth:260,
  133. column: [
  134. {
  135. label: "编码",
  136. prop: "code",
  137. width: "180",
  138. search: true,
  139. slot: true,
  140. rules: [{
  141. required: true,
  142. message: "请输入编码",
  143. trigger: "blur"
  144. }]
  145. },
  146. {
  147. label: "中文名称",
  148. prop: "cnName",
  149. width: "180",
  150. search: true,
  151. slot: true,
  152. rules: [{
  153. required: true,
  154. message: "请输入中文名称",
  155. trigger: "blur"
  156. }]
  157. },
  158. {
  159. label: "英文名称",
  160. prop: "enName",
  161. width: "180",
  162. search: true,
  163. slot: true,
  164. rules: [{
  165. required: true,
  166. message: "请输入英文名称",
  167. trigger: "blur"
  168. }]
  169. },
  170. {
  171. label: "状态",
  172. prop: "status",
  173. type: "select",
  174. dicData: [{
  175. label: '启用',
  176. value: 0
  177. }, {
  178. label: '停用',
  179. value: 1
  180. }],
  181. value: 0
  182. },
  183. {
  184. label: "创建人",
  185. prop: "createUserName",
  186. display: false,
  187. },
  188. {
  189. label: "创建部门",
  190. prop: "createDeptName",
  191. display: false,
  192. },
  193. {
  194. label: "创建时间",
  195. prop: "createTime",
  196. width: "160",
  197. display: false,
  198. },
  199. {
  200. label: "修改人",
  201. prop: "updateUserName",
  202. display: false,
  203. },
  204. {
  205. label: "修改时间",
  206. prop: "updateTime",
  207. width: "160",
  208. display: false,
  209. },
  210. {
  211. label: "是否已删除(0 否 1是)",
  212. prop: "isDeleted",
  213. hide: true,
  214. display: false,
  215. },
  216. {
  217. label: "备注",
  218. prop: "remarks",
  219. type: 'textarea',
  220. width: "180",
  221. span: 24,
  222. minRows: 3,
  223. slot: true
  224. },
  225. ]
  226. },
  227. data: []
  228. };
  229. },
  230. computed: {
  231. ...mapGetters(["permission"]),
  232. permissionList() {
  233. return {
  234. // addBtn: this.vaildData(this.permission.baccelements_add, false),
  235. // viewBtn: this.vaildData(this.permission.baccelements_view, false),
  236. // delBtn: this.vaildData(this.permission.baccelements_delete, false),
  237. // editBtn: this.vaildData(this.permission.baccelements_edit, false)
  238. };
  239. },
  240. ids() {
  241. let ids = [];
  242. this.selectionList.forEach(ele => {
  243. ids.push(ele.id);
  244. });
  245. return ids.join(",");
  246. }
  247. },
  248. async created() {
  249. this.option = await this.getColumnData(this.getColumnName(299), this.optionBack);
  250. },
  251. methods: {
  252. // 禁用启用按钮
  253. statusfun(id,status){
  254. this.$confirm("确定将选择数据更改状态?", {
  255. confirmButtonText: "确定",
  256. cancelButtonText: "取消",
  257. type: "warning"
  258. }).then(()=>{
  259. getBaccelementsDetail(id).then(res=>{
  260. let obj = res.data.data;
  261. obj.status = status
  262. updateBaccelements(obj).then(()=>{
  263. this.onLoad(this.page);
  264. this.$message({
  265. type: "success",
  266. message: "操作成功!"
  267. });
  268. })
  269. })
  270. })
  271. },
  272. // 导出
  273. handleExport() {
  274. var condition = ''
  275. for (const key in this.search) {
  276. var value = this.search[key]
  277. if (value) {
  278. condition += `&${key}=${this.search[key]}`
  279. }
  280. }
  281. this.$confirm('是否导出包装?', '提示', {
  282. confirmButtonText: '确定',
  283. cancelButtonText: '取消',
  284. type: 'warning'
  285. }).then(() => {
  286. window.open(
  287. `/api/blade-los/baccelements/exportBAccElements?${this.website.tokenHeader
  288. }=${getToken()}${condition}`
  289. );
  290. }).catch(() => {
  291. this.$message({
  292. type: 'info',
  293. message: '已取消' //
  294. });
  295. })
  296. },
  297. uploadBefore(file, done, loading) {
  298. done();
  299. loading = true;
  300. },
  301. // 上传成功
  302. onSuccess(res, done, loading, column) {
  303. this.excelBox = false;
  304. this.$message.success("导入成功!");
  305. loading = false;
  306. this.onLoad(this.page);
  307. done();
  308. },
  309. // 下载模板
  310. handleGet() {
  311. window.open(
  312. `/api/blade-los/baccelements/exportBAccElements/template?${this.website.tokenHeader
  313. }=${getToken()}`
  314. );
  315. },
  316. rowSave(row, done, loading) {
  317. addBaccelements(row).then(() => {
  318. this.onLoad(this.page);
  319. this.$message({
  320. type: "success",
  321. message: "操作成功!"
  322. });
  323. done();
  324. }, error => {
  325. loading();
  326. window.console.log(error);
  327. });
  328. },
  329. rowUpdate(row, index, done, loading) {
  330. updateBaccelements(row).then(() => {
  331. this.onLoad(this.page);
  332. this.$message({
  333. type: "success",
  334. message: "操作成功!"
  335. });
  336. done();
  337. }, error => {
  338. loading();
  339. console.log(error);
  340. });
  341. },
  342. rowDel(row) {
  343. if (row.status === 1) {
  344. this.$confirm("确定将选择数据删除?", {
  345. confirmButtonText: "确定",
  346. cancelButtonText: "取消",
  347. type: "warning"
  348. })
  349. .then(() => {
  350. return removeBaccelements(row.id);
  351. })
  352. .then(() => {
  353. this.onLoad(this.page);
  354. this.$message({
  355. type: "success",
  356. message: "操作成功!"
  357. });
  358. });
  359. } else {
  360. this.$message({
  361. message: '非禁用状态无法删除',
  362. type: 'warning'
  363. });
  364. }
  365. },
  366. handleDelete() {
  367. if (this.selectionList.length === 0) {
  368. this.$message.warning("请选择至少一条数据");
  369. return;
  370. }
  371. for (const selection of this.selectionList) {
  372. if (selection.status == 0) {
  373. this.$message.warning("选中的数据中有启用数据,启用数据不可删除!");
  374. return;
  375. }
  376. }
  377. this.$confirm("确定将选择数据删除?", {
  378. confirmButtonText: "确定",
  379. cancelButtonText: "取消",
  380. type: "warning"
  381. })
  382. .then(() => {
  383. return removeBaccelements(this.ids);
  384. })
  385. .then(() => {
  386. this.onLoad(this.page);
  387. this.$message({
  388. type: "success",
  389. message: "操作成功!"
  390. });
  391. this.$refs.crud.toggleSelection();
  392. });
  393. },
  394. beforeOpen(done, type) {
  395. if (["edit", "view"].includes(type)) {
  396. getBaccelementsDetail(this.form.id).then(res => {
  397. this.form = res.data.data;
  398. });
  399. }
  400. done();
  401. },
  402. searchReset() {
  403. this.query = {};
  404. this.onLoad(this.page);
  405. },
  406. searchChange(params, done) {
  407. this.query = params;
  408. this.page.currentPage = 1;
  409. this.onLoad(this.page, params);
  410. done();
  411. },
  412. selectionChange(list) {
  413. this.selectionList = list;
  414. },
  415. selectionClear() {
  416. this.selectionList = [];
  417. this.$refs.crud.toggleSelection();
  418. },
  419. currentChange(currentPage) {
  420. this.page.currentPage = currentPage;
  421. },
  422. sizeChange(pageSize) {
  423. this.page.pageSize = pageSize;
  424. },
  425. refreshChange() {
  426. this.onLoad(this.page, this.query);
  427. },
  428. onLoad(page, params = {}) {
  429. this.loading = true;
  430. getBaccelementsList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  431. const data = res.data.data;
  432. this.page.total = data.total;
  433. this.data = data.records;
  434. this.loading = false;
  435. this.selectionClear();
  436. });
  437. },
  438. //自定义列保存
  439. async saveColumnTwo(ref, option, optionBack, code) {
  440. /**
  441. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  442. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  443. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  444. */
  445. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  446. if (inSave) {
  447. this.$message.success("保存成功");
  448. //关闭窗口
  449. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  450. }
  451. },
  452. //自定义列重置
  453. async resetColumnTwo(ref, option, optionBack, code) {
  454. this[option] = this[optionBack];
  455. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  456. if (inSave) {
  457. this.$message.success("重置成功");
  458. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  459. }
  460. },
  461. // 更改表格颜色
  462. headerClassName(tab) {
  463. //颜色间隔
  464. let back = ""
  465. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  466. if (tab.columnIndex % 2 === 0) {
  467. back = "back-one"
  468. } else if (tab.columnIndex % 2 === 1) {
  469. back = "back-two"
  470. }
  471. }
  472. return back;
  473. },
  474. }
  475. };
  476. </script>
  477. <style lang="scss" scoped>
  478. ::v-deep#out-table .back-one {
  479. background: #ecf5ff !important;
  480. }
  481. ::v-deep#out-table .back-two {
  482. background: #ecf5ff !important;
  483. }
  484. /deep/ .el-col-md-8 {
  485. width: 24.33333%;
  486. }
  487. </style>