index.vue 18 KB

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