index.vue 18 KB

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