index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. width: "180",
  228. search: true,
  229. slot: true,
  230. rules: [{
  231. required: true,
  232. message: "请输入编码",
  233. trigger: "blur"
  234. }]
  235. },
  236. {
  237. label: "中文名称",
  238. prop: "cnName",
  239. width: "180",
  240. search: true,
  241. slot: true,
  242. rules: [{
  243. required: true,
  244. message: "请输入中文名称",
  245. trigger: "blur"
  246. }]
  247. },
  248. {
  249. label: "英文名称",
  250. prop: "enName",
  251. width: "180",
  252. search: true,
  253. slot: true,
  254. rules: [{
  255. required: true,
  256. message: "请输入英文名称",
  257. trigger: "blur"
  258. }]
  259. },
  260. {
  261. label: "单一窗口编码",
  262. prop: "codeSw",
  263. width:160,
  264. search: true,
  265. },
  266. {
  267. label: "数量规则",
  268. prop: "quantityRule",
  269. // rules: [{
  270. // required: true,
  271. // message: "请输入数量规则,用于根据单位自动计算数量",
  272. // trigger: "blur"
  273. // }]
  274. },
  275. // {
  276. // label: "quantity_rule=FIXED 时,默认的数量",
  277. // prop: "quantity",
  278. // rules: [{
  279. // required: true,
  280. // message: "请输入quantity_rule=FIXED 时,默认的数量",
  281. // trigger: "blur"
  282. // }]
  283. // },
  284. {
  285. label: "版本",
  286. prop: "version",
  287. display:false,
  288. },
  289. {
  290. label: "状态",
  291. prop: "status",
  292. type: "select",
  293. dicData:[{
  294. label:'启用',
  295. value:0
  296. },{
  297. label:'停用',
  298. value:1
  299. }],
  300. value: 0
  301. },
  302. // {
  303. // label: "是否已删除(0 否 1是)",
  304. // prop: "isDeleted",
  305. // rules: [{
  306. // required: true,
  307. // message: "请输入是否已删除(0 否 1是)",
  308. // trigger: "blur"
  309. // }]
  310. // },
  311. {
  312. label: "备注",
  313. prop: "remarks",
  314. type: 'textarea',
  315. width: "180",
  316. span: 24,
  317. minRows: 3,
  318. slot: true
  319. },
  320. ]
  321. },
  322. data: []
  323. };
  324. },
  325. computed: {
  326. ...mapGetters(["permission"]),
  327. permissionList() {
  328. return {
  329. // addBtn: this.vaildData(this.permission.bunits_add, false),
  330. // viewBtn: this.vaildData(this.permission.bunits_view, false),
  331. // delBtn: this.vaildData(this.permission.bunits_delete, false),
  332. // editBtn: this.vaildData(this.permission.bunits_edit, false)
  333. };
  334. },
  335. ids() {
  336. let ids = [];
  337. this.selectionList.forEach(ele => {
  338. ids.push(ele.id);
  339. });
  340. return ids.join(",");
  341. }
  342. },
  343. async created() {
  344. this.option = await this.getColumnData(this.getColumnName(296), this.optionBack);
  345. },
  346. methods: {
  347. // 导出
  348. handleExport() {
  349. var condition = ''
  350. for (const key in this.search) {
  351. var value = this.search[key]
  352. if (value) {
  353. condition += `&${key}=${this.search[key]}`
  354. }
  355. }
  356. this.$confirm('是否导出计量单位?', '提示', {
  357. confirmButtonText: '确定',
  358. cancelButtonText: '取消',
  359. type: 'warning'
  360. }).then(() => {
  361. window.open(
  362. `/api/blade-los/bunits/exportBUnits?${this.website.tokenHeader
  363. }=${getToken()}${condition}`
  364. );
  365. }).catch(() => {
  366. this.$message({
  367. type: 'info',
  368. message: '已取消' //
  369. });
  370. })
  371. },
  372. uploadBefore(file, done, loading) {
  373. done();
  374. loading = true;
  375. },
  376. // 上传成功
  377. onSuccess(res, done, loading, column) {
  378. this.excelBox = false;
  379. this.$message.success("导入成功!");
  380. loading = false;
  381. this.onLoad(this.page);
  382. done();
  383. },
  384. // 下载模板
  385. handleGet() {
  386. window.open(
  387. `/api/blade-los/bunits/exportBUnits/template?${this.website.tokenHeader
  388. }=${getToken()}`
  389. );
  390. },
  391. rowSave(row, done, loading) {
  392. addBunits(row).then(() => {
  393. this.onLoad(this.page);
  394. this.$message({
  395. type: "success",
  396. message: "操作成功!"
  397. });
  398. done();
  399. }, error => {
  400. loading();
  401. window.console.log(error);
  402. });
  403. },
  404. rowUpdate(row, index, done, loading) {
  405. updateBunits(row).then(() => {
  406. this.onLoad(this.page);
  407. this.$message({
  408. type: "success",
  409. message: "操作成功!"
  410. });
  411. done();
  412. }, error => {
  413. loading();
  414. console.log(error);
  415. });
  416. },
  417. rowDel(row) {
  418. if (row.status === 1) {
  419. this.$confirm("确定将选择数据删除?", {
  420. confirmButtonText: "确定",
  421. cancelButtonText: "取消",
  422. type: "warning"
  423. })
  424. .then(() => {
  425. return removeBunits(row.id);
  426. })
  427. .then(() => {
  428. this.onLoad(this.page);
  429. this.$message({
  430. type: "success",
  431. message: "操作成功!"
  432. });
  433. });
  434. } else {
  435. this.$message({
  436. message: '非禁用状态无法删除',
  437. type: 'warning'
  438. });
  439. }
  440. },
  441. handleDelete() {
  442. if (this.selectionList.length === 0) {
  443. this.$message.warning("请选择至少一条数据");
  444. return;
  445. }
  446. this.$confirm("确定将选择数据删除?", {
  447. confirmButtonText: "确定",
  448. cancelButtonText: "取消",
  449. type: "warning"
  450. })
  451. .then(() => {
  452. return removeBunits(this.ids);
  453. })
  454. .then(() => {
  455. this.onLoad(this.page);
  456. this.$message({
  457. type: "success",
  458. message: "操作成功!"
  459. });
  460. this.$refs.crud.toggleSelection();
  461. });
  462. },
  463. beforeOpen(done, type) {
  464. if (["edit", "view"].includes(type)) {
  465. getBunitsDetail(this.form.id).then(res => {
  466. this.form = res.data.data;
  467. });
  468. }
  469. done();
  470. },
  471. searchReset() {
  472. this.query = {};
  473. this.onLoad(this.page);
  474. },
  475. searchChange(params, done) {
  476. this.query = params;
  477. this.page.currentPage = 1;
  478. this.onLoad(this.page, params);
  479. done();
  480. },
  481. selectionChange(list) {
  482. this.selectionList = list;
  483. // 选择的数据抛出
  484. this.$emit('selectionChange',list)
  485. },
  486. selectionClear() {
  487. this.selectionList = [];
  488. this.$refs.crud.toggleSelection();
  489. },
  490. currentChange(currentPage){
  491. this.page.currentPage = currentPage;
  492. },
  493. sizeChange(pageSize){
  494. this.page.pageSize = pageSize;
  495. },
  496. refreshChange() {
  497. this.onLoad(this.page, this.query);
  498. },
  499. onLoad(page, params = {}) {
  500. this.loading = true;
  501. getBunitsList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  502. const data = res.data.data;
  503. this.page.total = data.total;
  504. this.data = data.records;
  505. this.loading = false;
  506. this.selectionClear();
  507. });
  508. },
  509. //自定义列保存
  510. async saveColumnTwo(ref, option, optionBack, code) {
  511. /**
  512. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  513. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  514. * 一定要执行异步操作,要等接口成功返回,才能执行下一行编码
  515. */
  516. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  517. if (inSave) {
  518. this.$message.success("保存成功");
  519. //关闭窗口
  520. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  521. }
  522. },
  523. //自定义列重置
  524. async resetColumnTwo(ref, option, optionBack, code) {
  525. this[option] = this[optionBack];
  526. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  527. if (inSave) {
  528. this.$message.success("重置成功");
  529. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  530. }
  531. },
  532. // 更改表格颜色
  533. headerClassName(tab){
  534. //颜色间隔
  535. let back = ""
  536. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  537. if (tab.columnIndex % 2 === 0) {
  538. back = "back-one"
  539. } else if (tab.columnIndex % 2 === 1) {
  540. back = "back-two"
  541. }
  542. }
  543. return back;
  544. },
  545. }
  546. };
  547. </script>
  548. <style lang="scss" scoped>
  549. ::v-deep#out-table .back-one {
  550. background: #ecf5ff !important;
  551. }
  552. ::v-deep#out-table .back-two {
  553. background: #ecf5ff !important;
  554. }
  555. /deep/ .el-col-md-8 {
  556. width: 24.33333%;
  557. }
  558. </style>