华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
14 KiB

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