【前端】智能库房综合管理系统前端项目
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.

166 lines
6.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div class="app-container">
  3. <!--表单组件-->
  4. <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title">
  5. <span class="dialog-right-top" />
  6. <span class="dialog-left-bottom" />
  7. <div class="setting-dialog">
  8. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
  9. <el-form-item label="区域名称" prop="name">
  10. <el-input v-model="form.name" style="width: 370px;" />
  11. </el-form-item>
  12. </el-form>
  13. <div slot="footer" class="dialog-footer">
  14. <el-button type="text" @click="crud.cancelCU">取消</el-button>
  15. <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
  16. </div>
  17. </div>
  18. </el-dialog>
  19. <el-dialog title="删除区域" :visible.sync="deleteVisible" :before-close="handleClose">
  20. <span class="dialog-right-top" />
  21. <span class="dialog-left-bottom" />
  22. <div class="setting-dialog">
  23. <div class="dialog-delt">
  24. <p><span>确定要删除当前区域吗</span></p>
  25. <p v-show="!allowDelete" class="delt-tip"><span>提示该区域已绑定设备不可删除请先删除设备</span></p>
  26. </div>
  27. <div slot="footer" class="dialog-footer">
  28. <el-button type="primary" :disabled="!allowDelete" @click.native="handleConfirm">确定</el-button>
  29. </div>
  30. </div>
  31. </el-dialog>
  32. <!-- 区域列表 -->
  33. <el-row class="container-main" :gutter="20">
  34. <el-col class="curd-in-out" style="height: calc(100vh - 190px)" :xs="10" :sm="8" :md="5" :lg="6" :xl="4">
  35. <div class="crud-opts">
  36. <div class="crud-opts-left">
  37. <el-button v-permission="permission.add" size="mini" icon="el-icon-plus" :disabled="crud.selections[0] && crud.selections[0].id && crud.selections[0].id !== defaultExpandedKeys[0]" @click="crud.toAdd">
  38. 新增
  39. </el-button>
  40. <el-button v-permission="permission.edit" size="mini" icon="el-icon-edit" :disabled="crud.selections.length !== 1 || crud.selections[0].id && crud.selections[0].id === defaultExpandedKeys[0]" @click="crud.toEdit(crud.selections[0])">
  41. 修改
  42. </el-button>
  43. <el-button v-permission="permission.del" icon="el-icon-delete" size="mini" :loading="crud.delAllLoading" :disabled="crud.selections.length !== 1 || crud.selections[0].id && crud.selections[0].id === defaultExpandedKeys[0]" @click="toDelete(crud.selections)">删除</el-button>
  44. </div>
  45. </div>
  46. <!--区域树状结构-->
  47. <div class="container-left" style="min-height: calc(100vh - 242px);margin:20px 0 0 0">
  48. <span class="right-top-line" />
  49. <span class="left-bottom-line" />
  50. <div class="tree-scroll">
  51. <el-tree ref="tree" v-loading="crud.loading" :data="crud.data" :props="defaultProps" node-key="id" :default-expanded-keys="defaultExpandedKeys" highlight-current @node-click="handleNodeClick" />
  52. </div>
  53. </div>
  54. </el-col>
  55. <!-- 设备详情列表 -->
  56. <!-- <el-col class="container-right" :xs="14" :sm="16" :md="19" :lg="18" :xl="20"> -->
  57. <el-col :xs="14" :sm="16" :md="19" :lg="18" :xl="20">
  58. <deviceDetail ref="deviceDetail" :permission="permission" :active-add-btn="activeRightBtn" />
  59. </el-col>
  60. </el-row>
  61. </div>
  62. </template>
  63. <script>
  64. import deviceDetail from './module/deviceDetail'
  65. import crudDevice from '@/api/storeManage/deviceManage/device'
  66. import CRUD, { presenter, form } from '@crud/crud'
  67. import Vue from 'vue'
  68. const defaultForm = { id: null, name: null, sort: null }
  69. export default {
  70. name: 'Device',
  71. components: { deviceDetail },
  72. cruds() {
  73. return [
  74. CRUD({
  75. title: '区域', url: 'api/storeroom/tree',
  76. crudMethod: { ...crudDevice },
  77. sort: ['sort,asc']
  78. })
  79. ]
  80. },
  81. mixins: [presenter(), form(defaultForm)],
  82. data() {
  83. return {
  84. rules: {
  85. name: [
  86. { required: true, message: '请输入区域名称', trigger: 'blur' }
  87. ]
  88. },
  89. permission: {
  90. add: ['admin', 'deviceManage:add'],
  91. edit: ['admin', 'deviceManage:edit'],
  92. del: ['admin', 'deviceManage:del']
  93. },
  94. defaultProps: {
  95. children: 'children',
  96. label: 'name'
  97. },
  98. activeRightBtn: false,
  99. deleteVisible: false,
  100. deleteData: {},
  101. allowDelete: false, // 是否允许删除当前区域
  102. defaultExpandedKeys: []
  103. }
  104. },
  105. methods: {
  106. // 获取数据前设置好接口地址
  107. [CRUD.HOOK.beforeRefresh]() {
  108. if (this.$refs.deviceDetail) {
  109. this.$refs.deviceDetail.query.id = ''
  110. }
  111. return true
  112. },
  113. [CRUD.HOOK.afterRefresh]() {
  114. Vue.set(this.defaultExpandedKeys, 0, this.crud.data[0].id)
  115. this.$refs.tree.setCurrentKey(this.crud.data[0].id)
  116. this.crud.selections = [this.crud.data[0]]
  117. },
  118. // 选中区域后,显示设备详情数据
  119. handleNodeClick(val) {
  120. if (val) {
  121. this.crud.selectionChangeHandler([val])
  122. this.$refs.deviceDetail.query.id = val.id
  123. this.$refs.deviceDetail.dicPid = val.id
  124. this.$refs.deviceDetail.crud.toQuery()
  125. this.activeRightBtn = true
  126. }
  127. },
  128. // 编辑前将区域临时清空,避免日志入库数据过长
  129. [CRUD.HOOK.beforeToEdit](crud, form) {
  130. form.deviceDetails = null
  131. },
  132. [CRUD.HOOK.beforeSubmit]() {
  133. this.crud.form.pid = this.defaultExpandedKeys[0]
  134. this.crud.form.remark = this.crud.form.name
  135. if (!this.crud.form.sort) {
  136. this.crud.form.sort = this.crud.data[0].children.reduce((prev, cur) => { return { sort: Math.max(prev.sort, cur.sort) } }).sort + 1
  137. }
  138. },
  139. toDelete(data) {
  140. this.deleteData = data
  141. this.deleteVisible = true
  142. this.allowDelete = this.$refs.deviceDetail.crud.data && this.$refs.deviceDetail.crud.data.length === 0
  143. },
  144. handleConfirm() {
  145. this.deleteVisible = false
  146. this.crud.delAllLoading = true
  147. this.crud.doDelete(this.deleteData)
  148. },
  149. handleClose(done) {
  150. this.deleteData = {}
  151. done()
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .tree-scroll {
  158. height: calc(100vh - 275px);
  159. overflow-y: scroll;
  160. overflow-x: hidden;
  161. }
  162. </style>