index.vue 15 KB

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