index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  4. <el-form-item label="岗位编码" prop="workstationCode">
  5. <el-input
  6. v-model="queryParams.workstationCode"
  7. placeholder="请输入部门编码"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="岗位名称" prop="workstationName">
  13. <el-input
  14. v-model="queryParams.workstationName"
  15. placeholder="请输入部门名称"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button v-no-more-click type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
  22. </el-button>
  23. <el-button v-no-more-click icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-row :gutter="10" class="mb8">
  27. <el-col :span="1.5">
  28. <el-button v-no-more-click
  29. type="primary"
  30. plain
  31. icon="el-icon-plus"
  32. size="mini"
  33. @click="handleAdd"
  34. v-hasPermi="['iscs:workstation:add']"
  35. >新增
  36. </el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button v-no-more-click
  40. type="info"
  41. plain
  42. icon="el-icon-sort"
  43. size="mini"
  44. @click="toggleExpandAll"
  45. >展开/折叠
  46. </el-button>
  47. </el-col>
  48. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  49. </el-row>
  50. <el-table
  51. v-if="refreshTable"
  52. v-loading="loading"
  53. :data="deptList"
  54. row-key="workstationId"
  55. :default-expand-all="isExpandAll"
  56. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  57. >
  58. <!-- <el-table-column prop="workstationCode" label="岗位编码" width="260"></el-table-column>-->
  59. <el-table-column prop="workstationName" label="岗位名称" width="260"></el-table-column>
  60. <el-table-column prop="workstationType" label="岗位类型" width="260"></el-table-column>
  61. <el-table-column prop="workstationType" label="岗位人员" width="260">
  62. <template slot-scope="scope">
  63. <el-button type="text" @click="HandleLookWorkStation(scope.row)">查看</el-button>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  67. <template slot-scope="scope">
  68. <span>{{ parseTime(scope.row.createTime) }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  72. <template slot-scope="scope">
  73. <el-button v-no-more-click
  74. size="mini"
  75. type="text"
  76. icon="el-icon-edit"
  77. @click="handleUpdate(scope.row)"
  78. v-hasPermi="['iscs:workstation:edit']"
  79. >修改
  80. </el-button>
  81. <el-button v-no-more-click
  82. size="mini"
  83. type="text"
  84. icon="el-icon-plus"
  85. @click="handleAdd(scope.row)"
  86. v-hasPermi="['iscs:workstation:add']"
  87. >新增
  88. </el-button>
  89. <!-- v-if="scope.row.parentId != 0"-->
  90. <el-button v-no-more-click
  91. size="mini"
  92. type="text"
  93. icon="el-icon-delete"
  94. @click="handleDelete(scope.row)"
  95. v-hasPermi="['iscs:workstation:remove']"
  96. >删除
  97. </el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <!-- 添加或修改部门对话框 -->
  102. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  103. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  104. <el-form-item label="上级" prop="parentId" v-if="form.parentId !== 0">
  105. <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级"/>
  106. </el-form-item>
  107. <el-form-item label="岗位名称" prop="workstationName">
  108. <el-input v-model="form.workstationName" placeholder="请输入岗位名称"/>
  109. </el-form-item>
  110. <el-row>
  111. <el-col :span="18">
  112. <el-form-item label="岗位编号" prop="workstationCode">
  113. <el-input
  114. v-model="form.workstationCode"
  115. placeholder="请输入岗位编号"
  116. />
  117. </el-form-item>
  118. </el-col>
  119. <el-col :span="6">
  120. <el-form-item label-width="30">
  121. <el-switch
  122. v-model="autoGenFlag"
  123. active-color="#13ce66"
  124. active-text="自动生成"
  125. @change="handleAutoGenChange(autoGenFlag)"
  126. >
  127. </el-switch>
  128. </el-form-item>
  129. </el-col>
  130. </el-row>
  131. <el-form-item label="岗位类型" prop="workstationType">
  132. <el-input v-model="form.workstationType" placeholder="请输入岗位类型" maxlength="20"/>
  133. </el-form-item>
  134. </el-form>
  135. <div slot="footer" class="dialog-footer">
  136. <el-button v-no-more-click type="primary" @click="submitForm">确 定</el-button>
  137. <el-button v-no-more-click @click="cancel">取 消</el-button>
  138. </div>
  139. </el-dialog>
  140. </div>
  141. </template>
  142. <script>
  143. import {
  144. listMarsDept,
  145. listMarsDeptExcludeChild,
  146. getMarsDept,
  147. addMarsDept,
  148. updateMarsDept,
  149. delMarsDept
  150. } from '@/api/system/marsdept'
  151. import Treeselect from '@riophae/vue-treeselect'
  152. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  153. import { genCode } from '@/api/system/autocode/rule'
  154. import { listUnit } from '@/api/system/unit'
  155. export default {
  156. name: 'Dept',
  157. dicts: ['sys_normal_disable'],
  158. components: { Treeselect },
  159. data() {
  160. return {
  161. // 遮罩层
  162. loading: true,
  163. //自动生成编码
  164. autoGenFlag: false,
  165. // 显示搜索条件
  166. showSearch: true,
  167. // 表格树数据
  168. deptList: [],
  169. // 部门树选项
  170. deptOptions: [],
  171. // 弹出层标题
  172. title: '',
  173. // 是否显示弹出层
  174. open: false,
  175. // 是否展开,默认全部展开
  176. isExpandAll: true,
  177. // 重新渲染表格状态
  178. refreshTable: true,
  179. // 查询参数
  180. queryParams: {
  181. pages:1,
  182. size:-1,
  183. workstationName: undefined,
  184. workstationCode: undefined,
  185. userId:undefined
  186. },
  187. // 表单参数
  188. form: {},
  189. // 表单校验
  190. rules: {
  191. parentId: [
  192. { required: true, message: '上级部门不能为空', trigger: 'blur' }
  193. ],
  194. workstationName: [
  195. { required: true, message: '部门名称不能为空', trigger: 'blur' }
  196. ],
  197. }
  198. }
  199. },
  200. watch: {
  201. "$route.query.userId": {
  202. immediate: true,
  203. handler(val) {
  204. console.log(val,'用户id')
  205. this.queryParams.userId = val;
  206. this.getList();
  207. }
  208. }
  209. },
  210. created() {
  211. this.getList()
  212. },
  213. methods: {
  214. /** 查询部门列表 */
  215. getList() {
  216. this.loading = true
  217. listMarsDept(this.queryParams).then(response => {
  218. debugger;
  219. this.deptList = this.handleTree(response.data.records,"workstationId","parentId")
  220. console.log(this.deptList,'岗位列表')
  221. this.loading = false
  222. })
  223. },
  224. /** 转换部门数据结构 */
  225. normalizer(node) {
  226. if (node.children && !node.children.length) {
  227. delete node.children
  228. }
  229. return {
  230. id: node.workstationId,
  231. label: node.workstationName,
  232. children: node.children
  233. }
  234. },
  235. // 岗位人员查看页面跳转
  236. HandleLookWorkStation(row){
  237. this.$router.push('/user/user?workstationId='+row.workstationId)
  238. },
  239. // 取消按钮
  240. cancel() {
  241. this.open = false
  242. this.reset()
  243. },
  244. // 表单重置
  245. reset() {
  246. this.form = {
  247. workstationId: undefined,
  248. parentId: undefined,
  249. workstationName: undefined,
  250. userId: undefined,
  251. }
  252. this.autoGenFlag = false;
  253. this.resetForm('form')
  254. },
  255. //自动生成编码
  256. handleAutoGenChange(autoGenFlag) {
  257. if (autoGenFlag) {
  258. genCode("MARS_WORKSTATION").then((response) => {
  259. console.log(response,'玛氏编码');
  260. this.form.workstationCode = response;
  261. });
  262. } else {
  263. this.form.workstationCode = null;
  264. }
  265. },
  266. /** 搜索按钮操作 */
  267. handleQuery() {
  268. this.getList()
  269. },
  270. /** 重置按钮操作 */
  271. resetQuery() {
  272. this.queryParams.userId = undefined
  273. this.resetForm('queryForm')
  274. this.handleQuery()
  275. this.$router.push('/user/mars')
  276. },
  277. /** 新增按钮操作 */
  278. handleAdd(row) {
  279. this.reset()
  280. if (row != null && row.workstationId) {
  281. this.form.parentId = row.workstationId;
  282. } else {
  283. this.form.parentId = 0;
  284. }
  285. this.open = true
  286. this.title = '添加部门'
  287. listMarsDept(this.queryParams).then(response => {
  288. this.deptOptions = this.handleTree(response.data.records,"workstationId","parentId")
  289. })
  290. },
  291. /** 展开/折叠操作 */
  292. toggleExpandAll() {
  293. this.refreshTable = false
  294. this.isExpandAll = !this.isExpandAll
  295. this.$nextTick(() => {
  296. this.refreshTable = true
  297. })
  298. },
  299. /** 修改按钮操作 */
  300. handleUpdate(row) {
  301. this.reset()
  302. getMarsDept(row.workstationId).then(response => {
  303. this.form = response.data
  304. this.open = true
  305. this.title = '修改部门'
  306. })
  307. listMarsDeptExcludeChild(row.workstationId).then(response => {
  308. this.deptOptions = this.handleTree(response.data.records,"workstationId","parentId")
  309. })
  310. },
  311. /** 提交按钮 */
  312. submitForm: function() {
  313. this.$refs['form'].validate(valid => {
  314. if (valid) {
  315. if (this.form.workstationId != undefined) {
  316. updateMarsDept(this.form).then(response => {
  317. this.$modal.msgSuccess('修改成功')
  318. this.open = false
  319. this.getList()
  320. })
  321. } else {
  322. addMarsDept(this.form).then(response => {
  323. this.$modal.msgSuccess('新增成功')
  324. this.open = false
  325. this.getList()
  326. })
  327. }
  328. }
  329. })
  330. },
  331. /** 删除按钮操作 */
  332. handleDelete(row) {
  333. this.$modal.confirm('是否确认删除名称为"' + row.workstationName + '"的数据项?').then(function() {
  334. return delMarsDept(row.workstationId)
  335. }).then(() => {
  336. this.getList()
  337. this.$modal.msgSuccess('删除成功')
  338. }).catch(() => {
  339. })
  340. }
  341. }
  342. }
  343. </script>