index.vue 20 KB

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