region.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <el-row>
  3. <el-col :span="9">
  4. <div class="box">
  5. <el-scrollbar>
  6. <basic-container>
  7. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick">
  8. <span class="el-tree-node__label" slot-scope="{ node, data }">
  9. <span>
  10. <i class="el-icon-office-building"></i>
  11. {{ (node || {}).label }}
  12. </span>
  13. </span>
  14. </avue-tree>
  15. </basic-container>
  16. </el-scrollbar>
  17. </div>
  18. </el-col>
  19. <el-col :span="15">
  20. <basic-container>
  21. <el-button-group>
  22. <el-button v-if="permission.region_add" type="primary" size="small"
  23. icon="el-icon-circle-plus-outline" @click="addChildren">新增下级</el-button>
  24. <el-button v-if="permission.region_delete" type="primary" size="small" icon="el-icon-delete"
  25. @click="handleDelete">删除</el-button>
  26. <el-button v-if="permission.region_import" type="primary" size="small" icon="el-icon-upload2"
  27. @click="handleImport">从宏图共享数据导入行政区划</el-button>
  28. <!-- <el-button v-if="permission.region_export" type="primary" size="small" icon="el-icon-download"
  29. @click="handleExport">导出</el-button>
  30. <el-button v-if="permission.region_debug" type="primary" size="small" icon="el-icon-video-play"
  31. @click="handleDebug">调试</el-button> -->
  32. </el-button-group>
  33. </basic-container>
  34. <basic-container>
  35. <avue-form ref="form" :option="regionOption" v-model="regionForm" @submit="handleSubmit">
  36. <!-- <template slot="code" slot-scope="{}">
  37. <el-input placeholder="请输入 区划子编号" v-model="regionForm.subCode">
  38. <template slot="prepend">{{regionForm.parentCode}}</template>
  39. </el-input>
  40. </template> -->
  41. </avue-form>
  42. <el-dialog title="行政区划数据导入" append-to-body :visible.sync="excelBox" width="800px">
  43. <avue-form :option="excelOption" v-model="excelForm" @submit="handleImportSubmit">
  44. <!-- <template slot="excelTemplate">
  45. <el-button type="primary" @click="handleTemplate">
  46. 开始导入<i class="el-icon-download el-icon--right"></i>
  47. </el-button>
  48. </template> -->
  49. </avue-form>
  50. </el-dialog>
  51. <el-dialog title="行政区划数据调试" append-to-body :visible.sync="debugBox" width="350px">
  52. <avue-form :option="debugOption" v-model="debugForm" />
  53. </el-dialog>
  54. </basic-container>
  55. </el-col>
  56. </el-row>
  57. </template>
  58. <script>
  59. import { getTree, getDetail, submit, remove, importSubmit } from "@/api/baseinfo/region";
  60. import { exportBlob } from "@/api/common";
  61. import { mapGetters } from "vuex";
  62. import { validatenull } from "@/util/validate";
  63. import { downloadXls } from "@/util/util";
  64. import { dateNow } from "@/util/date";
  65. import { getToken } from "@/util/auth";
  66. import NProgress from 'nprogress';
  67. import 'nprogress/nprogress.css';
  68. export default {
  69. data() {
  70. return {
  71. topCode: '00',
  72. treeCode: '',
  73. treeParentCode: '',
  74. treeData: [],
  75. treeOption: {
  76. nodeKey: 'id',
  77. defaultExpandedKeys: [],
  78. lazy: false,
  79. // treeLoad: function (node, resolve) {
  80. // const parentCode = (node.level === 0) ? "00" : node.data.value;
  81. // getLazyTree(parentCode).then(res => {
  82. // resolve(res.data.data.map(item => {
  83. // return {
  84. // ...item,
  85. // leaf: !item.hasChildren
  86. // }
  87. // }))
  88. // });
  89. // },
  90. addBtn: false,
  91. menu: false,
  92. size: 'small',
  93. props: {
  94. labelText: '标题',
  95. label: 'title',
  96. value: 'value',
  97. children: 'children'
  98. }
  99. },
  100. regionForm: {},
  101. regionOption: {
  102. labelWidth: 100,
  103. column: [
  104. {
  105. label: "父区划编号",
  106. prop: "parentCode",
  107. span: 24,
  108. disabled: true,
  109. rules: [{
  110. required: true,
  111. message: "请输入父区划编号",
  112. trigger: "blur"
  113. }]
  114. },
  115. {
  116. label: "父区划名称",
  117. prop: "parentName",
  118. span: 24,
  119. disabled: true,
  120. },
  121. {
  122. label: "区划编号",
  123. prop: "code",
  124. span: 24,
  125. rules: [{
  126. required: true,
  127. message: "请输入区划编号",
  128. trigger: "blur"
  129. }]
  130. },
  131. {
  132. label: "区划子编号",
  133. prop: "ancestors",
  134. display: false,
  135. },
  136. {
  137. label: "区划名称",
  138. prop: "name",
  139. span: 24,
  140. rules: [{
  141. required: true,
  142. message: "请输入区划名称",
  143. trigger: "blur"
  144. }]
  145. },
  146. // {
  147. // label: "区划等级",
  148. // prop: "regionLevel",
  149. // type: "radio",
  150. // dicUrl: "/api/galaxy-system/dict/dictionary?code=region",
  151. // props: {
  152. // label: "dictValue",
  153. // value: "dictKey"
  154. // },
  155. // dataType: "number",
  156. // span: 24,
  157. // rules: [{
  158. // required: true,
  159. // message: "请选择区划等级",
  160. // trigger: "blur"
  161. // }]
  162. // },
  163. // {
  164. // label: "区划排序",
  165. // prop: "sort",
  166. // type: "number",
  167. // span: 24,
  168. // rules: [{
  169. // required: true,
  170. // message: "请输入区划排序",
  171. // trigger: "blur"
  172. // }]
  173. // },
  174. // {
  175. // label: "区划备注",
  176. // prop: "remark",
  177. // type: "textarea",
  178. // minRows: 6,
  179. // span: 24,
  180. // },
  181. ]
  182. },
  183. excelBox: false,
  184. excelForm: {},
  185. excelOption: {
  186. // submitBtn: false,
  187. emptyBtn: false,
  188. column: [
  189. // {
  190. // label: '模板上传',
  191. // prop: 'excelFile',
  192. // type: 'upload',
  193. // drag: true,
  194. // loadText: '模板上传中,请稍等',
  195. // span: 24,
  196. // propsHttp: {
  197. // res: 'data'
  198. // },
  199. // tip: '请上传 .xls,.xlsx 标准格式文件',
  200. // action: "/api/galaxy-system/region/import-region"
  201. // },
  202. {
  203. label: "导入区划等级",
  204. labelWidth: 160,
  205. prop: "regionLevel",
  206. type: "radio",
  207. dicUrl: "/api/galaxy-system/dict/dictionary?code=region",
  208. props: {
  209. label: "dictValue",
  210. value: "dictKey"
  211. },
  212. dataType: "number",
  213. span: 24,
  214. value: 3,
  215. rules: [{
  216. required: true,
  217. message: "请选择区划等级",
  218. trigger: "blur"
  219. }]
  220. },
  221. {
  222. label: "数据清空",
  223. labelWidth: 160,
  224. prop: "isCovered",
  225. type: "switch",
  226. align: "center",
  227. width: 80,
  228. dicData: [
  229. {
  230. label: "否",
  231. value: 0
  232. },
  233. {
  234. label: "是",
  235. value: 1
  236. }
  237. ],
  238. value: 0,
  239. slot: true,
  240. rules: [
  241. {
  242. required: true,
  243. message: "请选择是否覆盖",
  244. trigger: "blur"
  245. }
  246. ]
  247. },
  248. // {
  249. // label: '操作',
  250. // labelWidth: 160,
  251. // prop: 'excelTemplate',
  252. // formslot: true,
  253. // span: 24,
  254. // }
  255. ]
  256. },
  257. debugBox: false,
  258. debugForm: {},
  259. debugOption: {
  260. labelWidth: 50,
  261. submitBtn: false,
  262. emptyBtn: false,
  263. column: [
  264. {
  265. label: '省份',
  266. prop: 'province',
  267. type: 'select',
  268. props: {
  269. label: 'name',
  270. value: 'code'
  271. },
  272. cascader: ['city'],
  273. dicUrl: '/api/galaxy-system/region/select',
  274. span: 24,
  275. },
  276. {
  277. label: '地市',
  278. prop: 'city',
  279. type: 'select',
  280. props: {
  281. label: 'name',
  282. value: 'code'
  283. },
  284. cascader: ['district'],
  285. dicFlag: false,
  286. dicUrl: '/api/galaxy-system/region/select?code={{province}}',
  287. span: 24,
  288. },
  289. {
  290. label: '区县',
  291. prop: 'district',
  292. type: 'select',
  293. props: {
  294. label: 'name',
  295. value: 'code'
  296. },
  297. dicFlag: false,
  298. dicUrl: '/api/galaxy-system/region/select?code={{city}}',
  299. span: 24,
  300. }
  301. ]
  302. }
  303. };
  304. },
  305. watch: {
  306. // 'regionForm.subCode'() {
  307. // this.regionForm.code = this.regionForm.parentCode + this.regionForm.subCode;
  308. // },
  309. // 'excelForm.isCovered'() {
  310. // if (this.excelForm.isCovered !== '') {
  311. // const column = this.findObject(this.excelOption.column, "excelFile");
  312. // column.action = `/api/galaxy-system/region/import-region?isCovered=${this.excelForm.isCovered}`;
  313. // }
  314. // }
  315. },
  316. computed: {
  317. ...mapGetters(["permission"]),
  318. permissionList() {
  319. return {
  320. addBtn: this.vaildData(this.permission.region_add, false),
  321. viewBtn: this.vaildData(this.permission.region_view, false),
  322. delBtn: this.vaildData(this.permission.region_delete, false),
  323. editBtn: this.vaildData(this.permission.region_edit, false)
  324. };
  325. },
  326. ids() {
  327. let ids = [];
  328. this.selectionList.forEach(ele => {
  329. ids.push(ele.id);
  330. });
  331. return ids.join(",");
  332. }
  333. },
  334. created() {
  335. this.initTree();
  336. },
  337. methods: {
  338. initTree() {
  339. this.treeData = [];
  340. getTree().then(res => {
  341. this.treeData = res.data.data.map(item => {
  342. return {
  343. ...item,
  344. leaf: !item.hasChildren
  345. }
  346. })
  347. this.treeOption.defaultExpandedKeys.push(this.treeData[0].id);
  348. });
  349. },
  350. nodeClick(data) {
  351. const column = this.findObject(this.regionOption.column, "parentCode");
  352. column.disabled = true;
  353. this.treeCode = data.id;
  354. this.treeParentCode = data.parentId;
  355. getDetail(this.treeCode).then(res => {
  356. this.regionForm = res.data.data;
  357. this.regionForm.subCode = this.regionForm.code.replace(this.regionForm.parentCode, '');
  358. })
  359. },
  360. addChildren() {
  361. if (validatenull(this.regionForm.code) || validatenull(this.regionForm.name)) {
  362. this.$message.warning("请先选择一项区划");
  363. return;
  364. }
  365. this.regionForm.parentCode = this.regionForm.code;
  366. this.regionForm.parentName = this.regionForm.name;
  367. this.regionForm.code = '';
  368. // this.regionForm.subCode = '';
  369. this.regionForm.name = '';
  370. this.regionForm.regionLevel = (this.regionForm.regionLevel === 5) ? 5 : this.regionForm.regionLevel + 1;
  371. },
  372. handleSubmit(form, done, loading) {
  373. // const parentCode = form.parentCode === this.topCode ? '' : form.parentCode;
  374. // form.code = parentCode + form.subCode;
  375. submit(form).then(() => {
  376. this.$message({
  377. type: "success",
  378. message: "操作成功!"
  379. });
  380. this.initTree();
  381. // this.regionForm.subCode = '';
  382. this.$refs.form.resetForm();
  383. done();
  384. }, error => {
  385. loading();
  386. window.console.log(error);
  387. });
  388. },
  389. handleDelete() {
  390. if (validatenull(this.regionForm.code)) {
  391. this.$message.warning("请先选择一项区划");
  392. return;
  393. }
  394. this.$confirm(`确定将 [${this.regionForm.name}] 数据删除?`, {
  395. confirmButtonText: "确定",
  396. cancelButtonText: "取消",
  397. type: "warning"
  398. })
  399. .then(() => {
  400. return remove(this.treeCode);
  401. })
  402. .then(() => {
  403. this.$message({
  404. type: "success",
  405. message: "操作成功!"
  406. });
  407. this.initTree();
  408. // this.regionForm.subCode = '';
  409. this.$refs.form.resetForm();
  410. });
  411. },
  412. // uploadAfter(res, done, loading, column) {
  413. // window.console.log(column);
  414. // this.excelBox = false;
  415. // this.initTree();
  416. // done();
  417. // },
  418. handleDebug() {
  419. this.debugBox = true;
  420. },
  421. handleImport() {
  422. this.excelBox = true;
  423. },
  424. handleExport() {
  425. this.$confirm("是否导出行政区划数据?", "提示", {
  426. confirmButtonText: "确定",
  427. cancelButtonText: "取消",
  428. type: "warning"
  429. }).then(() => {
  430. NProgress.start();
  431. exportBlob(`/api/galaxy-system/region/export-region?${this.website.tokenHeader}=${getToken()}`).then(res => {
  432. downloadXls(res.data, `行政区划数据${dateNow()}.xlsx`);
  433. NProgress.done();
  434. })
  435. });
  436. },
  437. handleImportSubmit(form, done, loading) {
  438. importSubmit(form).then(() => {
  439. this.$message({
  440. type: "success",
  441. message: "操作成功!"
  442. });
  443. this.initTree();
  444. // this.regionForm.subCode = '';
  445. this.$refs.form.resetForm();
  446. this.excelBox = false;
  447. done();
  448. }, error => {
  449. loading();
  450. window.console.log(error);
  451. });
  452. },
  453. // handleTemplate() {
  454. // exportBlob(`/api/galaxy-system/region/export-template?${this.website.tokenHeader}=${getToken()}`).then(res => {
  455. // downloadXls(res.data, "行政区划模板.xlsx");
  456. // })
  457. // },
  458. }
  459. };
  460. </script>
  461. <style>
  462. .box {
  463. height: 800px;
  464. }
  465. .el-scrollbar {
  466. height: 100%;
  467. }
  468. .box .el-scrollbar__wrap {
  469. overflow: scroll;
  470. }
  471. </style>