index.vue 12 KB

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