region.vue 13 KB

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