index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never" v-loading="loading">
  4. <!-- 数据表格 -->
  5. <ele-pro-table
  6. ref="table"
  7. row-key="id"
  8. :columns="columns"
  9. :datasource="datasource"
  10. :default-expand-all="false"
  11. :need-page="false"
  12. cache-key="systemMenuTable"
  13. @done=""
  14. >
  15. <!-- 表头工具栏 -->
  16. <template v-slot:toolbar>
  17. <el-button
  18. size="small"
  19. type="primary"
  20. icon="el-icon-plus"
  21. class="ele-btn-icon"
  22. @click="openEdit('add')"
  23. >
  24. 添加
  25. </el-button>
  26. <el-button class="ele-btn-icon" size="small" @click="expandAll">
  27. 展开全部
  28. </el-button>
  29. <el-button class="ele-btn-icon" size="small" @click="foldAll">
  30. 折叠全部
  31. </el-button>
  32. </template>
  33. <!-- 标题列 -->
  34. <template v-slot:areaImg="{ row }">
  35. <el-button v-if="row.areaImg.length" @click="downloadFile(row.areaImg[0])" type="text">查看</el-button>
  36. </template>
  37. <!-- 操作列 -->
  38. <template v-slot:action="{ row }">
  39. <el-link
  40. type="primary"
  41. :underline="false"
  42. icon="el-icon-edit"
  43. @click="openEdit('update',row)"
  44. >
  45. 修改
  46. </el-link>
  47. <el-popconfirm
  48. class="ele-action"
  49. title="确定要删除吗?"
  50. @confirm="remove(row)"
  51. v-if="row.id != 99999"
  52. >
  53. <template v-slot:reference>
  54. <el-link type="danger" :underline="false" icon="el-icon-delete">
  55. 删除
  56. </el-link>
  57. </template>
  58. </el-popconfirm>
  59. </template>
  60. </ele-pro-table>
  61. </el-card>
  62. <!-- 编辑弹窗 -->
  63. <area-edit
  64. v-if="showEdit"
  65. :visibleFlag.sync="showEdit"
  66. ref="areaEditRef"
  67. :data="editData"
  68. :parent-id="parentId"
  69. :organization-list="dataTree"
  70. @done="reload"
  71. />
  72. </div>
  73. </template>
  74. <script>
  75. import areaEdit from './components/area-edit.vue';
  76. import {
  77. listOrganizations,
  78. removeOrganization
  79. } from '@/api/system/organization';
  80. import {basicAreaDeleteAPI, basicAreaPageAPI} from "@/api/regionalManage";
  81. import {getByCode} from "@/api/system/dictionary-data";
  82. import {getFile} from "@/api/system/file";
  83. export default {
  84. name: 'SystemOrganization',
  85. components: {areaEdit},
  86. data() {
  87. return {
  88. // 加载状态
  89. loading: false,
  90. // 列表数据
  91. data: [],
  92. dataTree: [],
  93. // 选中数据
  94. current: null,
  95. // 是否显示表单弹窗
  96. showEdit: false,
  97. // 编辑回显数据
  98. editData: null,
  99. // 上级id
  100. parentId: null,
  101. dictList:{}
  102. };
  103. },
  104. computed: {
  105. // 表格列配置
  106. columns() {
  107. return [
  108. {
  109. columnKey: 'index',
  110. type: 'index',
  111. width: 45,
  112. align: 'center',
  113. showOverflowTooltip: true,
  114. fixed: 'left'
  115. },
  116. {
  117. prop: 'name',
  118. label: '区域名称',
  119. showOverflowTooltip: true,
  120. align: 'center',
  121. minWidth: 110,
  122. slot: 'name'
  123. },
  124. {
  125. prop: 'areaCode',
  126. label: '区域编码',
  127. showOverflowTooltip: true,
  128. align: 'center',
  129. minWidth: 110,
  130. },
  131. {
  132. prop: 'areaImg',
  133. label: '地图/示意图',
  134. showOverflowTooltip: true,
  135. align: 'center',
  136. minWidth: 110,
  137. slot: 'areaImg'
  138. },
  139. {
  140. prop: 'areaLevel',
  141. label: '区域等级',
  142. showOverflowTooltip: true,
  143. align: 'center',
  144. formatter: (row, column) => {
  145. return this.getDictV('main_area_level',row.areaLevel) ;
  146. },
  147. minWidth: 110,
  148. },
  149. {
  150. prop: 'areaType',
  151. label: '区域类型',
  152. showOverflowTooltip: true,
  153. align: 'center',
  154. formatter: (row, column) => {
  155. return this.getDictV('main_area_type',row.areaType) ;
  156. },
  157. minWidth: 110,
  158. },
  159. {
  160. prop: 'areaSort',
  161. label: '排序',
  162. showOverflowTooltip: true,
  163. align: 'center',
  164. width: 60
  165. },
  166. {
  167. columnKey: 'action',
  168. label: '操作',
  169. width: 190,
  170. align: 'center',
  171. resizable: false,
  172. slot: 'action',
  173. showOverflowTooltip: true
  174. }
  175. ]
  176. },
  177. },
  178. created() {
  179. //this.query();
  180. },
  181. methods: {
  182. getDictV(code, val) {
  183. if (!this.dictList[code]) return '';
  184. return this.dictList[code].find(item => item.value == val)?.label
  185. },
  186. async getDictList(code) {
  187. let {data: res} = await getByCode(code)
  188. this.dictList[code] = res.map(item => {
  189. let values = Object.keys(item)
  190. return {
  191. value: values[0],
  192. label: item[values[0]]
  193. }
  194. })
  195. },
  196. downloadFile(file) {
  197. getFile({objectName: file.storePath}, file.type);
  198. },
  199. /* 查询 */
  200. async datasource() {
  201. await this.getDictList('main_area_level')
  202. await this.getDictList('main_area_type')
  203. const data = await basicAreaPageAPI(
  204. {
  205. pageNum: 1,
  206. size: 9999
  207. }
  208. )
  209. this.data = this.$util.toTreeData({
  210. data: data,
  211. idField: 'id',
  212. parentIdField: 'parentId'
  213. });
  214. this.dataTree = [{
  215. name:'顶级区域',
  216. id: '0',
  217. children: this.data,
  218. }]
  219. return this.data
  220. },
  221. /* 刷新表格 */
  222. reload(where) {
  223. this.$refs.table.reload();
  224. },
  225. /* 展开全部 */
  226. expandAll() {
  227. this.$refs.table.toggleRowExpansionAll(true);
  228. },
  229. /* 折叠全部 */
  230. foldAll() {
  231. this.$refs.table.toggleRowExpansionAll(false);
  232. },
  233. /* 显示编辑 */
  234. openEdit(type,row) {
  235. this.showEdit = true;
  236. this.$nextTick(() => {
  237. this.$refs.areaEditRef.init(type,row);
  238. });
  239. },
  240. /* 删除 */
  241. remove(row) {
  242. this.$confirm('确定要删除选中的区域吗?', '提示', {
  243. type: 'warning'
  244. }).then(() => {
  245. const loading = this.$loading({lock: true});
  246. basicAreaDeleteAPI([row.id])
  247. .then((msg) => {
  248. loading.close();
  249. this.$message.success(msg);
  250. this.reload();
  251. })
  252. .catch((e) => {
  253. loading.close();
  254. // this.$message.error(e.message);
  255. });
  256. })
  257. .catch(() => {
  258. });
  259. }
  260. }
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .sys-organization-list {
  265. height: calc(100vh - 264px);
  266. box-sizing: border-box;
  267. border-width: 1px;
  268. border-style: solid;
  269. overflow: auto;
  270. }
  271. .sys-organization-list :deep(.el-tree-node__content) {
  272. height: 30px;
  273. & > .el-tree-node__expand-icon {
  274. margin-left: 10px;
  275. }
  276. }
  277. </style>