Rap 原分销系统代码Web
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

255 lignes
8.6KB

  1. <template>
  2. <div class="app-container">
  3. <!--工具栏-->
  4. <div class="head-container">
  5. <div v-if="crud.props.searchToggle">
  6. <!-- 搜索 -->
  7. <el-input v-model="query.name" clearable size="small" placeholder="输入部门名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
  8. <date-range-picker v-model="query.createTime" class="date-item" />
  9. <el-select v-model="query.enabled" clearable size="small" placeholder="状态" class="filter-item" style="width: 90px" @change="crud.toQuery">
  10. <el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
  11. </el-select>
  12. <rrOperation />
  13. </div>
  14. <crudOperation :permission="permission" />
  15. </div>
  16. <!--表单组件-->
  17. <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
  18. <el-form ref="form" inline :model="form" :rules="rules" size="small" label-width="80px">
  19. <el-form-item label="部门名称" prop="name">
  20. <el-input v-model="form.name" style="width: 370px;" />
  21. </el-form-item>
  22. <el-form-item label="部门排序" prop="deptSort">
  23. <el-input-number
  24. v-model.number="form.deptSort"
  25. :min="0"
  26. :max="999"
  27. controls-position="right"
  28. style="width: 370px;"
  29. />
  30. </el-form-item>
  31. <el-form-item label="顶级部门">
  32. <el-radio-group v-model="form.isTop" style="width: 140px">
  33. <el-radio label="1">是</el-radio>
  34. <el-radio label="0">否</el-radio>
  35. </el-radio-group>
  36. </el-form-item>
  37. <el-form-item label="状态" prop="enabled">
  38. <el-radio v-for="item in dict.dept_status" :key="item.id" v-model="form.enabled" :label="item.value">{{ item.label }}</el-radio>
  39. </el-form-item>
  40. <el-form-item v-if="form.isTop === '0'" style="margin-bottom: 0;" label="上级部门" prop="pid">
  41. <treeselect
  42. v-model="form.pid"
  43. :load-options="loadDepts"
  44. :options="depts"
  45. style="width: 370px;"
  46. placeholder="选择上级类目"
  47. />
  48. </el-form-item>
  49. </el-form>
  50. <div slot="footer" class="dialog-footer">
  51. <el-button type="text" @click="crud.cancelCU">取消</el-button>
  52. <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
  53. </div>
  54. </el-dialog>
  55. <!--表格渲染-->
  56. <el-table
  57. ref="table"
  58. v-loading="crud.loading"
  59. lazy
  60. :load="getDeptDatas"
  61. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  62. :data="crud.data"
  63. row-key="id"
  64. @select="crud.selectChange"
  65. @select-all="crud.selectAllChange"
  66. @selection-change="crud.selectionChangeHandler"
  67. >
  68. <el-table-column :selectable="checkboxT" type="selection" width="55" />
  69. <el-table-column label="名称" prop="name" />
  70. <el-table-column label="排序" prop="deptSort" />
  71. <el-table-column label="状态" align="center" prop="enabled">
  72. <template slot-scope="scope">
  73. <el-switch
  74. v-model="scope.row.enabled"
  75. :disabled="scope.row.id === 1"
  76. active-color="#409EFF"
  77. inactive-color="#F56C6C"
  78. @change="changeEnabled(scope.row, scope.row.enabled,)"
  79. />
  80. </template>
  81. </el-table-column>
  82. <el-table-column prop="createTime" label="创建日期" />
  83. <el-table-column v-if="checkPer(['admin','dept:edit','dept:del'])" label="操作" width="130px" align="center" fixed="right">
  84. <template slot-scope="scope">
  85. <udOperation
  86. :data="scope.row"
  87. :permission="permission"
  88. :disabled-dle="scope.row.id === 1"
  89. msg="确定删除吗,如果存在下级节点则一并删除,此操作不能撤销!"
  90. />
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. </div>
  95. </template>
  96. <script>
  97. import crudDept from '@/api/system/dept'
  98. import Treeselect from '@riophae/vue-treeselect'
  99. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  100. import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
  101. import CRUD, { presenter, header, form, crud } from '@crud/crud'
  102. import rrOperation from '@crud/RR.operation'
  103. import crudOperation from '@crud/CRUD.operation'
  104. import udOperation from '@crud/UD.operation'
  105. import DateRangePicker from '@/components/DateRangePicker'
  106. const defaultForm = { id: null, name: null, isTop: '1', subCount: 0, pid: null, deptSort: 999, enabled: 'true' }
  107. export default {
  108. name: 'Dept',
  109. components: { Treeselect, crudOperation, rrOperation, udOperation, DateRangePicker },
  110. cruds() {
  111. return CRUD({ title: '部门', url: 'api/dept', crudMethod: { ...crudDept }})
  112. },
  113. mixins: [presenter(), header(), form(defaultForm), crud()],
  114. // 设置数据字典
  115. dicts: ['dept_status'],
  116. data() {
  117. return {
  118. depts: [],
  119. rules: {
  120. name: [
  121. { required: true, message: '请输入名称', trigger: 'blur' }
  122. ],
  123. deptSort: [
  124. { required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
  125. ]
  126. },
  127. permission: {
  128. add: ['admin', 'dept:add'],
  129. edit: ['admin', 'dept:edit'],
  130. del: ['admin', 'dept:del']
  131. },
  132. enabledTypeOptions: [
  133. { key: 'true', display_name: '正常' },
  134. { key: 'false', display_name: '禁用' }
  135. ]
  136. }
  137. },
  138. methods: {
  139. getDeptDatas(tree, treeNode, resolve) {
  140. const params = { pid: tree.id }
  141. setTimeout(() => {
  142. crudDept.getDepts(params).then(res => {
  143. resolve(res.content)
  144. })
  145. }, 100)
  146. },
  147. // 新增与编辑前做的操作
  148. [CRUD.HOOK.afterToCU](crud, form) {
  149. if (form.pid !== null) {
  150. form.isTop = '0'
  151. } else if (form.id !== null) {
  152. form.isTop = '1'
  153. }
  154. form.enabled = `${form.enabled}`
  155. if (form.id != null) {
  156. this.getSupDepts(form.id)
  157. } else {
  158. this.getDepts()
  159. }
  160. },
  161. getSupDepts(id) {
  162. crudDept.getDeptSuperior(id).then(res => {
  163. const date = res.content
  164. this.buildDepts(date)
  165. this.depts = date
  166. })
  167. },
  168. buildDepts(depts) {
  169. depts.forEach(data => {
  170. if (data.children) {
  171. this.buildDepts(data.children)
  172. }
  173. if (data.hasChildren && !data.children) {
  174. data.children = null
  175. }
  176. })
  177. },
  178. getDepts() {
  179. crudDept.getDepts({ enabled: true }).then(res => {
  180. this.depts = res.content.map(function(obj) {
  181. if (obj.hasChildren) {
  182. obj.children = null
  183. }
  184. return obj
  185. })
  186. })
  187. },
  188. // 获取弹窗内部门数据
  189. loadDepts({ action, parentNode, callback }) {
  190. if (action === LOAD_CHILDREN_OPTIONS) {
  191. crudDept.getDepts({ enabled: true, pid: parentNode.id }).then(res => {
  192. parentNode.children = res.content.map(function(obj) {
  193. if (obj.hasChildren) {
  194. obj.children = null
  195. }
  196. return obj
  197. })
  198. setTimeout(() => {
  199. callback()
  200. }, 100)
  201. })
  202. }
  203. },
  204. // 提交前的验证
  205. [CRUD.HOOK.afterValidateCU]() {
  206. if (this.form.pid !== null && this.form.pid === this.form.id) {
  207. this.$message({
  208. message: '上级部门不能为空',
  209. type: 'warning'
  210. })
  211. return false
  212. }
  213. if (this.form.isTop === '1') {
  214. this.form.pid = null
  215. }
  216. return true
  217. },
  218. // 改变状态
  219. changeEnabled(data, val) {
  220. this.$confirm('此操作将 "' + this.dict.label.dept_status[val] + '" ' + data.name + '部门, 是否继续?', '提示', {
  221. confirmButtonText: '确定',
  222. cancelButtonText: '取消',
  223. type: 'warning'
  224. }).then(() => {
  225. crudDept.edit(data).then(res => {
  226. this.crud.notify(this.dict.label.dept_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
  227. }).catch(err => {
  228. data.enabled = !data.enabled
  229. console.log(err.response.data.message)
  230. })
  231. }).catch(() => {
  232. data.enabled = !data.enabled
  233. })
  234. },
  235. checkboxT(row, rowIndex) {
  236. return row.id !== 1
  237. }
  238. }
  239. }
  240. </script>
  241. <style rel="stylesheet/scss" lang="scss" scoped>
  242. ::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
  243. height: 30px;
  244. line-height: 30px;
  245. }
  246. </style>
  247. <style rel="stylesheet/scss" lang="scss" scoped>
  248. ::v-deep .el-input-number .el-input__inner {
  249. text-align: left;
  250. }
  251. </style>