index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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="workstationCode">-->
  11. <!-- <el-input-->
  12. <!-- v-model="queryParams.workstationCode"-->
  13. <!-- placeholder="请输入部门编码"-->
  14. <!-- clearable-->
  15. <!-- @keyup.enter.native="handleQuery"-->
  16. <!-- />-->
  17. <!-- </el-form-item>-->
  18. <el-form-item label="岗位名称" prop="workstationName">
  19. <el-input
  20. v-model="queryParams.workstationName"
  21. placeholder="请输入部门名称"
  22. clearable
  23. @keyup.enter.native="handleQuery"
  24. />
  25. </el-form-item>
  26. <el-form-item label="状态" prop="status">
  27. <el-select
  28. v-model="queryParams.status"
  29. placeholder="用户状态"
  30. clearable
  31. style="width: 240px"
  32. >
  33. <el-option
  34. v-for="dict in dict.type.sys_normal_disable"
  35. :key="dict.value"
  36. :label="dict.label"
  37. :value="dict.value"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button
  43. v-no-more-click
  44. type="primary"
  45. icon="el-icon-search"
  46. size="mini"
  47. @click="handleQuery"
  48. >搜索
  49. </el-button>
  50. <el-button
  51. v-no-more-click
  52. icon="el-icon-refresh"
  53. size="mini"
  54. @click="resetQuery"
  55. >重置</el-button
  56. >
  57. </el-form-item>
  58. </el-form>
  59. <el-row :gutter="10" class="mb8">
  60. <el-col :span="1.5">
  61. <el-button
  62. v-no-more-click
  63. type="primary"
  64. plain
  65. icon="el-icon-plus"
  66. size="mini"
  67. @click="handleAdd"
  68. v-hasPermi="['iscs:workstation:add']"
  69. >新增
  70. </el-button>
  71. </el-col>
  72. <!-- <el-col :span="1.5">-->
  73. <!-- <el-button v-no-more-click-->
  74. <!-- type="info"-->
  75. <!-- plain-->
  76. <!-- icon="el-icon-sort"-->
  77. <!-- size="mini"-->
  78. <!-- @click="toggleExpandAll"-->
  79. <!-- >展开/折叠-->
  80. <!-- </el-button>-->
  81. <!-- </el-col>-->
  82. <right-toolbar
  83. :showSearch.sync="showSearch"
  84. @queryTable="getList"
  85. ></right-toolbar>
  86. </el-row>
  87. <el-table
  88. v-if="refreshTable"
  89. v-loading="loading"
  90. :data="deptList"
  91. row-key="workstationId"
  92. :default-expand-all="isExpandAll"
  93. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  94. >
  95. <!-- <el-table-column prop="workstationCode" label="岗位编码" width="260"></el-table-column>-->
  96. <el-table-column
  97. prop="workstationName"
  98. label="岗位名称"
  99. width="300"
  100. ></el-table-column>
  101. <el-table-column
  102. prop="orderNum"
  103. label="排序"
  104. width="260"
  105. ></el-table-column>
  106. <el-table-column prop="status" label="状态" width="260">
  107. <template slot-scope="scope">
  108. <el-switch
  109. v-model="scope.row.status"
  110. active-value="0"
  111. inactive-value="1"
  112. @change="handleStatusChange(scope.row)"
  113. ></el-switch>
  114. </template>
  115. </el-table-column>
  116. <el-table-column prop="workstationType" label="岗位人员" width="100">
  117. <template slot-scope="scope">
  118. <el-button type="text" @click="HandleLookWorkStation(scope.row)"
  119. >查看</el-button
  120. >
  121. </template>
  122. </el-table-column>
  123. <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="200">-->
  124. <!-- <template slot-scope="scope">-->
  125. <!-- <span>{{ parseTime(scope.row.createTime) }}</span>-->
  126. <!-- </template>-->
  127. <!-- </el-table-column>-->
  128. <el-table-column
  129. label="操作"
  130. align="center"
  131. class-name="small-padding fixed-width"
  132. >
  133. <template slot-scope="scope">
  134. <el-button
  135. v-no-more-click
  136. size="mini"
  137. type="text"
  138. icon="el-icon-edit"
  139. @click="handleUpdate(scope.row)"
  140. v-hasPermi="['iscs:workstation:edit']"
  141. >修改
  142. </el-button>
  143. <el-button
  144. v-no-more-click
  145. size="mini"
  146. type="text"
  147. icon="el-icon-plus"
  148. @click="handleAdd(scope.row)"
  149. v-hasPermi="['iscs:workstation:add']"
  150. >新增
  151. </el-button>
  152. <!-- v-if="scope.row.parentId != 0"-->
  153. <el-button
  154. v-no-more-click
  155. size="mini"
  156. type="text"
  157. icon="el-icon-delete"
  158. @click="handleDelete(scope.row)"
  159. v-hasPermi="['iscs:workstation:remove']"
  160. >删除
  161. </el-button>
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. <!-- <pagination-->
  166. <!-- v-show="total > 0"-->
  167. <!-- :total="total"-->
  168. <!-- :page.sync="queryParams.pages"-->
  169. <!-- :limit.sync="queryParams.size"-->
  170. <!-- @pagination="getList"-->
  171. <!-- />-->
  172. <!-- 添加或修改部门对话框 -->
  173. <el-dialog :title="title" :visible.sync="open" width="480px" append-to-body>
  174. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  175. <el-form-item label="上级" prop="parentId" v-if="form.parentId !== 0">
  176. <treeselect
  177. v-model="form.parentId"
  178. :options="deptOptions"
  179. :normalizer="normalizer"
  180. placeholder="选择上级"
  181. />
  182. </el-form-item>
  183. <el-form-item label="岗位名称" prop="workstationName">
  184. <el-input
  185. v-model="form.workstationName"
  186. placeholder="请输入岗位名称"
  187. />
  188. </el-form-item>
  189. <!-- <el-row>-->
  190. <!-- <el-col :span="18">-->
  191. <!-- <el-form-item label="岗位编号" prop="workstationCode">-->
  192. <!-- <el-input-->
  193. <!-- v-model="form.workstationCode"-->
  194. <!-- placeholder="请输入岗位编号"-->
  195. <!-- />-->
  196. <!-- </el-form-item>-->
  197. <!-- </el-col>-->
  198. <!-- <el-col :span="6">-->
  199. <!-- <el-form-item label-width="30">-->
  200. <!-- <el-switch-->
  201. <!-- v-model="autoGenFlag"-->
  202. <!-- active-color="#13ce66"-->
  203. <!-- active-text="自动生成"-->
  204. <!-- @change="handleAutoGenChange(autoGenFlag)"-->
  205. <!-- >-->
  206. <!-- </el-switch>-->
  207. <!-- </el-form-item>-->
  208. <!-- </el-col>-->
  209. <!-- </el-row>-->
  210. <el-form-item label="排序" prop="orderNum">
  211. <el-input-number type="number" v-model="form.orderNum" />
  212. </el-form-item>
  213. <el-form-item label="状态" prop="status">
  214. <el-radio-group v-model="form.status">
  215. <el-radio
  216. v-for="dict in dict.type.sys_normal_disable"
  217. :key="dict.value"
  218. :label="dict.value"
  219. >{{ dict.label }}</el-radio
  220. >
  221. </el-radio-group>
  222. </el-form-item>
  223. <!-- <el-form-item label="岗位类型" prop="workstationType">-->
  224. <!-- <el-input v-model="form.workstationType" placeholder="请输入岗位类型" maxlength="20"/>-->
  225. <!-- </el-form-item>-->
  226. </el-form>
  227. <div slot="footer" class="dialog-footer">
  228. <el-button v-no-more-click type="primary" @click="submitForm"
  229. >确 定</el-button
  230. >
  231. <el-button v-no-more-click @click="cancel">取 消</el-button>
  232. </div>
  233. </el-dialog>
  234. </div>
  235. </template>
  236. <script>
  237. import {
  238. listMarsDept,
  239. listMarsDeptExcludeChild,
  240. getMarsDept,
  241. addMarsDept,
  242. updateMarsDept,
  243. delMarsDept,
  244. updateMarsDeptStatus,
  245. } from "@/api/system/marsdept";
  246. import Treeselect from "@riophae/vue-treeselect";
  247. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  248. import { genCode } from "@/api/system/autocode/rule";
  249. import { listUnit } from "@/api/system/unit";
  250. export default {
  251. name: "Dept",
  252. dicts: ["sys_normal_disable"],
  253. components: { Treeselect },
  254. data() {
  255. return {
  256. // 遮罩层
  257. loading: true,
  258. //自动生成编码
  259. autoGenFlag: false,
  260. // 显示搜索条件
  261. showSearch: true,
  262. total: 0, //
  263. // 表格树数据
  264. deptList: [],
  265. // 部门树选项
  266. deptOptions: [],
  267. // 弹出层标题
  268. title: "",
  269. // 是否显示弹出层
  270. open: false,
  271. // 是否展开,默认全部展开
  272. isExpandAll: true,
  273. // 重新渲染表格状态
  274. refreshTable: true,
  275. // 查询参数
  276. queryParams: {
  277. current: 1,
  278. size: -1,
  279. workstationName: undefined,
  280. status: undefined,
  281. userId: undefined, //勿删
  282. },
  283. // 表单参数
  284. form: {},
  285. // 表单校验
  286. rules: {
  287. parentId: [
  288. { required: true, message: "上级部门不能为空", trigger: "blur" },
  289. ],
  290. workstationName: [
  291. { required: true, message: "部门名称不能为空", trigger: "blur" },
  292. ],
  293. },
  294. };
  295. },
  296. watch: {
  297. "$route.query.userId": {
  298. immediate: true,
  299. handler(val) {
  300. console.log(val, "用户id");
  301. this.queryParams.userId = val;
  302. this.getList();
  303. },
  304. },
  305. },
  306. created() {
  307. this.getList();
  308. },
  309. methods: {
  310. // 用户状态修改
  311. handleStatusChange(row) {
  312. let text = row.status === "0" ? "启用" : "停用";
  313. this.$modal
  314. .confirm('确认要"' + text + '""' + row.workstationName + '"岗位吗?')
  315. .then(function () {
  316. const data = {
  317. workstationId: row.workstationId,
  318. status: row.status,
  319. };
  320. return updateMarsDeptStatus(data);
  321. })
  322. .then(() => {
  323. this.$modal.msgSuccess(text + "成功");
  324. })
  325. .catch(function () {
  326. row.status = row.status === "0" ? "1" : "0";
  327. });
  328. },
  329. /** 查询部门列表 */
  330. getList() {
  331. this.loading = true;
  332. listMarsDept(this.queryParams).then((response) => {
  333. debugger;
  334. this.deptList = this.handleTree(
  335. response.data.records,
  336. "workstationId",
  337. "parentId"
  338. );
  339. console.log(this.deptList, "岗位列表");
  340. this.loading = false;
  341. this.total = response.data.total;
  342. });
  343. },
  344. /** 转换部门数据结构 */
  345. normalizer(node) {
  346. if (node.children && !node.children.length) {
  347. delete node.children;
  348. }
  349. return {
  350. id: node.workstationId,
  351. label: node.workstationName,
  352. children: node.children,
  353. };
  354. },
  355. // 岗位人员查看页面跳转
  356. HandleLookWorkStation(row) {
  357. this.$router.push("/user/user?workstationId=" + row.workstationId);
  358. },
  359. // 取消按钮
  360. cancel() {
  361. this.open = false;
  362. this.reset();
  363. },
  364. // 表单重置
  365. reset() {
  366. this.form = {
  367. workstationId: undefined,
  368. parentId: undefined,
  369. workstationName: undefined,
  370. userId: undefined,
  371. };
  372. this.autoGenFlag = false;
  373. this.resetForm("form");
  374. },
  375. //自动生成编码
  376. handleAutoGenChange(autoGenFlag) {
  377. if (autoGenFlag) {
  378. genCode("MARS_WORKSTATION").then((response) => {
  379. console.log(response, "玛氏编码");
  380. this.form.workstationCode = response;
  381. });
  382. } else {
  383. this.form.workstationCode = null;
  384. }
  385. },
  386. /** 搜索按钮操作 */
  387. handleQuery() {
  388. this.getList();
  389. },
  390. /** 重置按钮操作 */
  391. resetQuery() {
  392. this.queryParams.userId = undefined;
  393. this.queryParams.unitName = "";
  394. this.queryParams.status = undefined;
  395. this.resetForm("queryForm");
  396. this.handleQuery();
  397. this.$router.push("/user/mars");
  398. },
  399. /** 新增按钮操作 */
  400. handleAdd(row) {
  401. this.reset();
  402. if (row != null && row.workstationId) {
  403. this.form.parentId = row.workstationId;
  404. } else {
  405. this.form.parentId = 0;
  406. }
  407. this.open = true;
  408. this.title = "新增岗位";
  409. listMarsDept(this.queryParams).then((response) => {
  410. this.deptOptions = this.handleTree(
  411. response.data.records,
  412. "workstationId",
  413. "parentId"
  414. );
  415. });
  416. },
  417. /** 展开/折叠操作 */
  418. toggleExpandAll() {
  419. this.refreshTable = false;
  420. this.isExpandAll = !this.isExpandAll;
  421. this.$nextTick(() => {
  422. this.refreshTable = true;
  423. });
  424. },
  425. /** 修改按钮操作 */
  426. handleUpdate(row) {
  427. this.reset();
  428. listMarsDept(row.workstationId).then((response) => {
  429. this.deptOptions = this.handleTree(
  430. response.data.records,
  431. "workstationId",
  432. "parentId"
  433. );
  434. });
  435. getMarsDept(row.workstationId).then((response) => {
  436. this.form = response.data;
  437. this.open = true;
  438. this.title = "修改岗位";
  439. });
  440. },
  441. /** 提交按钮 */
  442. submitForm: function () {
  443. this.$refs["form"].validate((valid) => {
  444. if (valid) {
  445. if (this.form.workstationId != undefined) {
  446. updateMarsDept(this.form).then((response) => {
  447. this.$modal.msgSuccess("修改成功");
  448. this.open = false;
  449. this.getList();
  450. });
  451. } else {
  452. addMarsDept(this.form).then((response) => {
  453. this.$modal.msgSuccess("新增成功");
  454. this.open = false;
  455. this.getList();
  456. });
  457. }
  458. }
  459. });
  460. },
  461. /** 删除按钮操作 */
  462. handleDelete(row) {
  463. this.$modal
  464. .confirm('是否确认删除名称为"' + row.workstationName + '"的数据项?')
  465. .then(function () {
  466. return delMarsDept(row.workstationId);
  467. })
  468. .then(() => {
  469. this.getList();
  470. this.$modal.msgSuccess("删除成功");
  471. })
  472. .catch(() => {});
  473. },
  474. },
  475. };
  476. </script>