index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="app-container">
  3. <el-card class="fiche">
  4. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList">收起</right-toolbar>
  5. <span style="margin-bottom: 10px;color:#333333;font:14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial,sans-serif">所选条件:</span>
  6. <div style="float: right;margin-right:1%">
  7. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  8. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" style="float: ;">重置</el-button>
  9. </div>
  10. <hr style="margin-top: 16px;">
  11. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
  12. <el-form-item label="部门名称" prop="deptName">
  13. <el-input
  14. v-model="queryParams.deptName"
  15. placeholder="请输入部门名称"
  16. clearable
  17. size="small"
  18. @keyup.enter.native="handleQuery"
  19. />
  20. </el-form-item>
  21. <!-- <el-form-item label="状态" prop="status">
  22. <el-select v-model="queryParams.status" placeholder="部门状态" clearable size="small">
  23. <el-option
  24. v-for="dict in statusOptions"
  25. :key="dict.dictValue"
  26. :label="dict.dictLabel"
  27. :value="dict.dictValue"
  28. />
  29. </el-select>
  30. </el-form-item> -->
  31. </el-form>
  32. </el-card>
  33. <el-row :gutter="10" class="mb8">
  34. <el-col :span="1.5">
  35. <el-button
  36. type="primary"
  37. icon="el-icon-plus"
  38. size="mini"
  39. @click="handleAdd"
  40. v-hasPermi="['system:dept:add']"
  41. >新增</el-button>
  42. </el-col>
  43. </el-row>
  44. <el-table
  45. v-loading="loading"
  46. :data="deptList"
  47. row-key="deptId"
  48. default-expand-all
  49. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  50. border
  51. >
  52. <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
  53. <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
  54. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  55. <template slot-scope="scope">
  56. <span>{{ parseTime(scope.row.createTime) }}</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="状态" align="center" :formatter="stateFormat">
  60. <!-- <template slot-scope="scope">
  61. <el-switch
  62. v-model="scope.row.status"
  63. active-value="0"
  64. inactive-value="1"
  65. @change="handleStatusChange(scope.row)"
  66. ></el-switch>
  67. </template> -->
  68. </el-table-column>
  69. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  70. <template slot-scope="scope">
  71. <el-button
  72. size="mini"
  73. type="text"
  74. icon="el-icon-edit"
  75. @click="handleUpdate(scope.row)"
  76. v-hasPermi="['system:dept:edit']"
  77. >修改</el-button>
  78. <el-button
  79. size="mini"
  80. type="text"
  81. icon="el-icon-plus"
  82. @click="handleAdd(scope.row)"
  83. v-hasPermi="['system:dept:add']"
  84. >新增</el-button>
  85. <el-button
  86. v-if="scope.row.parentId != 0"
  87. size="mini"
  88. type="text"
  89. icon="el-icon-delete"
  90. @click="handleDelete(scope.row)"
  91. v-hasPermi="['system:dept:remove']"
  92. >删除</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <!-- 添加或修改部门对话框 -->
  97. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  98. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  99. <el-row>
  100. <!-- <el-form-item label="公司名称" prop="payroll" v-show="companyId == '000000'">
  101. <el-select v-model="form.companyId">
  102. <el-option
  103. v-for="(item,index) in companyList"
  104. :key="index"
  105. :label="item.scyName"
  106. :value="item.scyId"
  107. ></el-option>
  108. </el-select>
  109. </el-form-item> -->
  110. <el-col :span="24" v-if="form.parentId !== 0">
  111. <el-form-item label="上级部门" prop="parentId">
  112. <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" />
  113. </el-form-item>
  114. </el-col>
  115. <el-col :span="12">
  116. <el-form-item label="部门名称" prop="deptName">
  117. <el-input v-model="form.deptName" placeholder="请输入部门名称" maxlength="50"/>
  118. </el-form-item>
  119. </el-col>
  120. <el-col :span="12">
  121. <el-form-item label="显示排序" prop="orderNum">
  122. <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="12">
  126. <el-form-item label="负责人" prop="leader">
  127. <el-input v-model="form.leader" placeholder="请输入负责人" maxlength="20" />
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="12">
  131. <el-form-item label="联系电话" prop="phone">
  132. <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="11" />
  133. </el-form-item>
  134. </el-col>
  135. <el-col :span="12">
  136. <el-form-item label="邮箱" prop="email">
  137. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  138. </el-form-item>
  139. </el-col>
  140. <!-- <el-col :span="12">
  141. <el-form-item label="部门状态" v-if="leave">
  142. <el-radio-group v-model="form.status">
  143. <el-radio
  144. v-for="dict in statusOptions"
  145. :key="dict.dictValue"
  146. :label="dict.dictValue"
  147. >{{dict.dictLabel}}</el-radio>
  148. </el-radio-group>
  149. </el-form-item>
  150. </el-col> -->
  151. </el-row>
  152. </el-form>
  153. <div slot="footer" class="dialog-footer">
  154. <el-button type="primary" @click="submitForm">确 定</el-button>
  155. <el-button @click="cancel">取 消</el-button>
  156. </div>
  157. </el-dialog>
  158. </div>
  159. </template>
  160. <script>
  161. import { listDept, getDept, delDept, addDept, updateDept, changeDeptStatus,listDeptExcludeChild } from "@/api/system/dept";
  162. import Treeselect from "@riophae/vue-treeselect";
  163. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  164. import {
  165. companyList
  166. } from "@/api/system/company";
  167. import { getUserProfile } from "@/api/system/user";
  168. export default {
  169. name: "Dept",
  170. components: { Treeselect },
  171. data() {
  172. return {
  173. // 遮罩层
  174. loading: true,
  175. companyId:'',
  176. companyList: [],
  177. // 显示搜索条件
  178. showSearch: true,
  179. // 表格树数据
  180. deptList: [],
  181. // 部门树选项
  182. deptOptions: [],
  183. // 弹出层标题
  184. title: "",
  185. // 是否显示弹出层
  186. open: false,
  187. //是否显示状态
  188. leave: false,
  189. // 状态数据字典
  190. statusOptions: [],
  191. // 查询参数
  192. queryParams: {
  193. deptName: undefined,
  194. status: undefined
  195. },
  196. // 表单参数
  197. form: {},
  198. // 表单校验
  199. rules: {
  200. // parentId: [
  201. // { required: true, message: "上级部门不能为空", trigger: "blur" }
  202. // ],
  203. deptName: [
  204. { required: true, message: "部门名称不能为空", trigger: "blur" }
  205. ],
  206. orderNum: [
  207. { required: true, message: "菜单顺序不能为空", trigger: "blur" }
  208. ],
  209. email: [
  210. {
  211. // type: "email",
  212. pattern:/^([a-z0-9A-Z]+[-|_|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$/,
  213. message: "邮箱格式不正确",
  214. trigger: ["blur", "change"]
  215. }
  216. ],
  217. phone: [
  218. {
  219. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  220. message: "请输入正确的手机号码",
  221. trigger: "blur"
  222. }
  223. ]
  224. },
  225. statusOptions:[
  226. {
  227. value: "0",
  228. label: "正常"
  229. },
  230. {
  231. value: "1",
  232. label: "停用"
  233. },]
  234. };
  235. },
  236. created() {
  237. this.getList();
  238. this.getCompanyList();
  239. this.getUserProfile();
  240. this.getDicts("sys_normal_disable").then(response => {
  241. this.statusOptions = response.data;
  242. });
  243. },
  244. methods: {
  245. /** 查询部门列表 */
  246. getCompanyList(){
  247. companyList().then(response => {
  248. this.companyList = response.data
  249. });
  250. },
  251. getUserProfile(){
  252. getUserProfile().then(response => {
  253. this.companyId = response.data.companyId;
  254. });
  255. },
  256. getList() {
  257. this.loading = true;
  258. listDept(this.queryParams).then(response => {
  259. this.deptList = this.handleTree(response.data, "deptId");
  260. this.loading = false;
  261. });
  262. },
  263. /** 转换部门数据结构 */
  264. normalizer(node) {
  265. if (node.children && !node.children.length) {
  266. delete node.children;
  267. }
  268. return {
  269. id: node.deptId,
  270. label: node.deptName,
  271. children: node.children
  272. };
  273. },
  274. // 字典状态字典翻译
  275. statusFormat(row, column) {
  276. return this.selectDictLabel(this.statusOptions, row.status);
  277. },
  278. // 取消按钮
  279. cancel() {
  280. this.open = false;
  281. this.reset();
  282. },
  283. // 表单重置
  284. reset() {
  285. this.form = {
  286. deptId: undefined,
  287. parentId: undefined,
  288. deptName: undefined,
  289. orderNum: undefined,
  290. leader: undefined,
  291. phone: undefined,
  292. email: undefined,
  293. status: "0"
  294. };
  295. this.resetForm("form");
  296. },
  297. /** 搜索按钮操作 */
  298. handleQuery() {
  299. this.getList();
  300. },
  301. /** 重置按钮操作 */
  302. resetQuery() {
  303. this.resetForm("queryForm");
  304. this.handleQuery();
  305. },
  306. /** 新增按钮操作 */
  307. handleAdd(row) {
  308. this.reset();
  309. if (row != undefined) {
  310. this.form.parentId = row.deptId;
  311. }
  312. this.leave = false;
  313. this.open = true;
  314. this.title = "添加部门";
  315. listDept().then(response => {
  316. this.deptOptions = this.handleTree(response.data, "deptId");
  317. });
  318. },
  319. /** 修改按钮操作 */
  320. handleUpdate(row) {
  321. this.reset();
  322. getDept(row.deptId).then(response => {
  323. this.form = response.data;
  324. this.leave = true;
  325. this.open = true;
  326. this.title = "修改部门";
  327. });
  328. listDeptExcludeChild(row.deptId).then(response => {
  329. this.deptOptions = this.handleTree(response.data, "deptId");
  330. });
  331. },
  332. /** 提交按钮 */
  333. submitForm: function() {
  334. this.$refs["form"].validate(valid => {
  335. if (valid) {
  336. if (this.form.deptId != undefined) {
  337. const loading = this.$loading({
  338. lock: true,
  339. text: "Loading",
  340. spinner: "el-icon-loading",
  341. background: "rgba(0, 0, 0, 0.7)",
  342. })
  343. updateDept(this.form).then(response => {
  344. loading.close();
  345. this.msgSuccess("修改成功");
  346. this.open = false;
  347. this.getList();
  348. }).catch((response)=>{
  349. loading.close();
  350. });
  351. } else {
  352. const loading = this.$loading({
  353. lock: true,
  354. text: "Loading",
  355. spinner: "el-icon-loading",
  356. background: "rgba(0, 0, 0, 0.7)",
  357. })
  358. addDept(this.form).then(response => {
  359. loading.close();
  360. this.msgSuccess("新增成功");
  361. this.open = false;
  362. this.getList();
  363. }).catch((response)=>{
  364. loading.close();
  365. });
  366. }
  367. }
  368. });
  369. },
  370. // 部门状态修改
  371. handleStatusChange(row) {
  372. let text = row.status === "0" ? "启用" : "停用";
  373. this.$confirm('确认要"' + text + '""' + row.deptName + '"用户吗?', "警告", {
  374. confirmButtonText: "确定",
  375. cancelButtonText: "取消",
  376. type: "warning"
  377. }).then(function() {
  378. return changeDeptStatus(row.deptId, row.status);
  379. }).then(() => {
  380. this.msgSuccess(text + "成功");
  381. }).catch(function() {
  382. row.status = row.status === "0" ? "1" : "0";
  383. });
  384. },
  385. /** 删除按钮操作 */
  386. handleDelete(row) {
  387. this.$confirm('是否确认删除名称为"' + row.deptName + '"的数据项?', "警告", {
  388. confirmButtonText: "确定",
  389. cancelButtonText: "取消",
  390. type: "warning"
  391. }).then(function() {
  392. return delDept(row.deptId);
  393. }).then(() => {
  394. this.getList();
  395. this.msgSuccess("删除成功");
  396. })
  397. .catch(() => {
  398. this.$message({
  399. type: "warning",
  400. message: "已取消删除",
  401. });
  402. });
  403. },
  404. /** 状态字典 */
  405. stateFormat(row, column){
  406. return this.selectDictLabel(this.statusOptions, row.status);
  407. },
  408. }
  409. };
  410. </script>