index.vue 16 KB

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