index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--机构数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input
  8. v-model="deptName"
  9. placeholder="请输入机构名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. />
  15. </div>
  16. <div class="tree-container">
  17. <div style="margin-bottom: 10px;">
  18. <el-checkbox v-model="queryParams.checkSub" @change="changeCheckBox">是否关联下级机构</el-checkbox>
  19. </div>
  20. <el-tree
  21. :data="deptOptions"
  22. :props="defaultProps"
  23. :expand-on-click-node="false"
  24. :filter-node-method="filterNode"
  25. ref="tree"
  26. node-key="id"
  27. :default-expanded-keys="defaultKeys"
  28. :default-checked-keys="defaultKeys"
  29. @node-click="handleNodeClick"
  30. />
  31. </div>
  32. </el-col>
  33. <!--用户数据-->
  34. <el-col :span="20" :xs="24">
  35. <!-- 搜索条件 -->
  36. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  37. <el-form-item label="机构名称" prop="name">
  38. <el-input
  39. v-model="queryParams.name"
  40. placeholder="请输入机构名称"
  41. clearable
  42. @keyup.enter.native="handleQuery"
  43. />
  44. </el-form-item>
  45. <el-form-item label="状态" prop="status">
  46. <el-select v-model="queryParams.status" placeholder="机构状态" clearable>
  47. <el-option
  48. v-for="dict in dict.type.sys_normal_disable"
  49. :key="dict.value"
  50. :label="dict.label"
  51. :value="dict.value"
  52. />
  53. </el-select>
  54. </el-form-item>
  55. <el-form-item>
  56. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  57. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  58. </el-form-item>
  59. </el-form>
  60. <el-row :gutter="10" class="mb8">
  61. <el-col :span="1.5">
  62. <el-button
  63. type="primary"
  64. plain
  65. icon="el-icon-plus"
  66. size="mini"
  67. @click="handleAdd"
  68. v-hasPermi="['system:dept:add']"
  69. >新增</el-button>
  70. </el-col>
  71. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  72. </el-row>
  73. <el-table v-loading="loading" :data="deptList" @selection-change="handleSelectionChange">
  74. <el-table-column prop="name" label="机构名称" width="260"></el-table-column>
  75. <el-table-column prop="sort" label="排序" width="200"></el-table-column>
  76. <el-table-column prop="isLock" label="状态" width="100">
  77. <template slot-scope="scope">
  78. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.isLock"/>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  82. <template slot-scope="scope">
  83. <span>{{ parseTime(scope.row.createTime) }}</span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  87. <template slot-scope="scope">
  88. <router-link :to="'/system/dept-extend/extend/'+ scope.row.id " class="link-type">
  89. <el-button
  90. size="mini"
  91. type="text"
  92. icon="el-icon-edit"
  93. >扩展</el-button
  94. >
  95. </router-link>
  96. <el-button
  97. size="mini"
  98. type="text"
  99. icon="el-icon-edit"
  100. @click="handleUpdate(scope.row)"
  101. v-hasPermi="['system:dept:edit']"
  102. >修改</el-button>
  103. <el-button
  104. size="mini"
  105. type="text"
  106. icon="el-icon-plus"
  107. @click="handleAdd(scope.row)"
  108. v-hasPermi="['system:dept:add']"
  109. >新增</el-button>
  110. <el-button
  111. v-if="scope.row.parentId != 0"
  112. size="mini"
  113. type="text"
  114. icon="el-icon-delete"
  115. @click="handleDelete(scope.row)"
  116. v-hasPermi="['system:dept:remove']"
  117. >删除</el-button>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <pagination
  122. v-show="total>0"
  123. :total="total"
  124. :page.sync="queryParams.pageNum"
  125. :limit.sync="queryParams.pageSize"
  126. @pagination="getList"
  127. />
  128. </el-col>
  129. </el-row>
  130. <!-- 添加或修改机构对话框 -->
  131. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  132. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  133. <el-row>
  134. <el-col :span="24">
  135. <el-form-item label="上级机构" prop="parentId">
  136. <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级机构" />
  137. </el-form-item>
  138. </el-col>
  139. </el-row>
  140. <el-row>
  141. <el-col :span="12">
  142. <el-form-item label="机构名称" prop="name">
  143. <el-input v-model="form.name" placeholder="请输入机构名称" />
  144. </el-form-item>
  145. </el-col>
  146. <el-col :span="12">
  147. <el-form-item label="显示排序" prop="sort">
  148. <el-input-number v-model="form.sort" controls-position="right" :min="0" />
  149. </el-form-item>
  150. </el-col>
  151. </el-row>
  152. <el-row>
  153. <el-col :span="12">
  154. <el-form-item label="负责人" prop="manager">
  155. <el-input v-model="form.manager" placeholder="请输入负责人" maxlength="20" />
  156. </el-form-item>
  157. </el-col>
  158. <el-col :span="12">
  159. <el-form-item label="联系电话" prop="phone">
  160. <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="11" />
  161. </el-form-item>
  162. </el-col>
  163. </el-row>
  164. <el-row>
  165. <el-col :span="12">
  166. <el-form-item label="邮箱" prop="email">
  167. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  168. </el-form-item>
  169. </el-col>
  170. <el-col :span="12">
  171. <el-form-item label="机构状态">
  172. <el-radio-group v-model="form.isLock">
  173. <el-radio
  174. v-for="dict in dict.type.sys_normal_disable"
  175. :key="dict.value"
  176. :label="dict.value"
  177. >{{dict.label}}</el-radio>
  178. </el-radio-group>
  179. </el-form-item>
  180. </el-col>
  181. </el-row>
  182. </el-form>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button v-if="title == '修改机构'" type="primary" @click="changeSubmitForm">确 定</el-button>
  185. <el-button v-if="title == '添加机构'" type="primary" @click="addSubmitForm">确 定</el-button>
  186. <el-button @click="cancel">取 消</el-button>
  187. </div>
  188. </el-dialog>
  189. </div>
  190. </template>
  191. <script>
  192. import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild} from "@/api/system/dept";
  193. import { deptTreeSelect } from "@/api/system/public";
  194. import { getToken } from "@/utils/auth";
  195. import Treeselect from "@riophae/vue-treeselect";
  196. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  197. export default {
  198. name: "Dept",
  199. dicts: ['sys_normal_disable'],
  200. components: { Treeselect },
  201. data() {
  202. return {
  203. // 遮罩层
  204. loading: true,
  205. // 显示搜索条件
  206. showSearch: true,
  207. // 表格树数据
  208. deptList: [],
  209. // 总条数
  210. total: 0,
  211. // 机构树选项
  212. deptOptions: [],
  213. // 弹出层标题
  214. title: "",
  215. // 是否显示弹出层
  216. open: false,
  217. // 是否展开,默认全部展开
  218. isExpandAll: false,
  219. // 重新渲染表格状态
  220. refreshTable: true,
  221. // 机构名称
  222. deptName: undefined,
  223. //是否关联下级
  224. checked: false,
  225. defaultProps: {
  226. children: "children",
  227. label: "name"
  228. },
  229. // 查询参数
  230. queryParams: {
  231. pageNum: 1,
  232. pageSize: 10,
  233. name: undefined,
  234. status: undefined,
  235. parentId:undefined,
  236. },
  237. // 表单参数
  238. form: {},
  239. // 表单校验
  240. rules: {
  241. parentId: [
  242. { required: true, message: "上级机构不能为空", trigger: "blur" }
  243. ],
  244. deptName: [
  245. { required: true, message: "机构名称不能为空", trigger: "blur" }
  246. ],
  247. orderNum: [
  248. { required: true, message: "显示排序不能为空", trigger: "blur" }
  249. ],
  250. email: [
  251. {
  252. type: "email",
  253. message: "请输入正确的邮箱地址",
  254. trigger: ["blur", "change"]
  255. }
  256. ],
  257. phone: [
  258. {
  259. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  260. message: "请输入正确的手机号码",
  261. trigger: "blur"
  262. }
  263. ]
  264. },
  265. //默认选中节点
  266. defaultKeys:[]
  267. };
  268. },
  269. created() {
  270. this.getDeptTree();
  271. this.getList();
  272. },
  273. methods: {
  274. //自定义数据
  275. tenantIdnormalizer(node, instanceId) {
  276. if (node.children && !node.children.length) {
  277. delete node.children
  278. }
  279. return {
  280. id: node.id,
  281. label: node.name,
  282. children: node.children
  283. }
  284. },
  285. /** 下穿状态改变*/
  286. changeCheckBox(){
  287. this.getList();
  288. },
  289. /** 查询机构下拉树结构 */
  290. getDeptTree() {
  291. deptTreeSelect().then(response => {
  292. this.deptOptions = response.data;
  293. console.log( this.deptOptions,' this.deptOptions')
  294. this.defaultKeys.push(response.data[0].id);
  295. this.queryParams.parentId = response.data[0].id;
  296. this.handleQuery();
  297. });
  298. },
  299. // 筛选节点
  300. filterNode(value, data) {
  301. if (!value) return true;
  302. return data.name.indexOf(value) !== -1;
  303. },
  304. // 节点单击事件
  305. handleNodeClick(data) {
  306. this.queryParams.parentId = data.id;
  307. this.handleQuery();
  308. },
  309. /** 查询机构列表 */
  310. getList() {
  311. this.loading = true;
  312. listDept(this.queryParams).then(response => {
  313. this.deptList = response.rows;
  314. this.total = response.total;
  315. this.loading = false;
  316. });
  317. },
  318. /** 转换机构数据结构 */
  319. normalizer(node) {
  320. if (node.children && !node.children.length) {
  321. delete node.children;
  322. }
  323. return {
  324. id: node.id,
  325. label: node.name,
  326. children: node.children
  327. };
  328. },
  329. // 取消按钮
  330. cancel() {
  331. this.open = false;
  332. this.reset();
  333. },
  334. // 表单重置
  335. reset() {
  336. this.form = {
  337. deptId: undefined,
  338. parentId: undefined,
  339. deptName: undefined,
  340. orderNum: undefined,
  341. leader: undefined,
  342. phone: undefined,
  343. email: undefined,
  344. status: "0"
  345. };
  346. this.resetForm("form");
  347. },
  348. /** 搜索按钮操作 */
  349. handleQuery() {
  350. this.getList();
  351. },
  352. /** 重置按钮操作 */
  353. resetQuery() {
  354. this.resetForm("queryForm");
  355. this.handleQuery();
  356. },
  357. /** 新增按钮操作 */
  358. handleAdd(row) {
  359. this.reset();
  360. if (this.queryParams.parentId != undefined) {
  361. this.form.parentId = this.queryParams.parentId;
  362. }
  363. this.open = true;
  364. this.title = "添加机构";
  365. },
  366. /** 展开/折叠操作 */
  367. toggleExpandAll() {
  368. this.refreshTable = false;
  369. this.isExpandAll = !this.isExpandAll;
  370. this.$nextTick(() => {
  371. this.refreshTable = true;
  372. });
  373. },
  374. /** 修改按钮操作 */
  375. handleUpdate(row) {
  376. this.reset();
  377. getDept(row.id).then(response => {
  378. this.form = response.data;
  379. this.open = true;
  380. this.title = "修改机构";
  381. });
  382. listDeptExcludeChild(row.id).then(response => {
  383. this.deptOptions = this.handleTree(response.data, "id");
  384. });
  385. },
  386. /** 提交按钮 */
  387. changeSubmitForm() {
  388. this.$refs["form"].validate(valid => {
  389. if (valid) {
  390. updateDept(this.form).then(response => {
  391. this.$modal.msgSuccess("修改成功");
  392. this.open = false;
  393. this.getList();
  394. });
  395. }
  396. });
  397. },
  398. addSubmitForm() {
  399. this.$refs["form"].validate(valid => {
  400. if (valid) {
  401. addDept(this.form).then(response => {
  402. this.$modal.msgSuccess("新增成功");
  403. this.open = false;
  404. this.getList();
  405. });
  406. }
  407. });
  408. },
  409. /** 删除按钮操作 */
  410. handleDelete(row) {
  411. this.$modal.confirm('是否确认删除名称为"' + row.name + '"的数据项?').then(function() {
  412. return delDept(row.id);
  413. }).then(() => {
  414. this.getList();
  415. this.$modal.msgSuccess("删除成功");
  416. }).catch(() => {});
  417. },
  418. // 多选框选中数据
  419. handleSelectionChange(selection) {
  420. this.ids = selection.map(item => item.userId);
  421. this.single = selection.length != 1;
  422. this.multiple = !selection.length;
  423. },
  424. },
  425. watch: {
  426. // 根据名称筛选机构树
  427. deptName(val) {
  428. this.$refs.tree.filter(val);
  429. }
  430. }
  431. };
  432. </script>
  433. <style lang="scss" scoped>
  434. </style>