index.vue 17 KB

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