index.vue 20 KB

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