index.vue 16 KB

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