阅行客电子档案
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.

459 lines
15 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <!--用户数据-->
  3. <div class="elect-cont-right">
  4. <!--工具栏-->
  5. <div class="head-container">
  6. <crudOperation :permission="permission">
  7. <template v-slot:left>
  8. <el-button v-permission="permission.add" size="mini" @click="crud.toAdd">
  9. <i class="iconfont icon-xinzeng" />
  10. 新增
  11. </el-button>
  12. <el-button v-permission="permission.edit" size="mini" :disabled="selections.length !== 1" @click="crud.toEdit(selections[0])">
  13. <i class="iconfont icon-bianji" />
  14. 编辑
  15. </el-button>
  16. <el-button slot="reference" v-permission="permission.del" size="mini" :loading="crud.delAllLoading" :disabled="selections.length === 0" @click="toDelete(selections)">
  17. <i class="iconfont icon-shanchu" />
  18. 删除
  19. </el-button>
  20. </template>
  21. <template v-slot:right>
  22. <el-button :loading="crud.downloadLoading" size="mini" :disabled="selections.length === 0" @click="doExport(selections)">
  23. <i class="iconfont icon-daochu" />
  24. 导出
  25. </el-button>
  26. <span class="tip">注意门类节点下才可新增档案分类</span>
  27. </template>
  28. </crudOperation>
  29. </div>
  30. <!--表单组件-->
  31. <el-dialog
  32. :close-on-click-modal="false"
  33. :modal-append-to-body="false"
  34. append-to-body
  35. :before-close="crud.cancelCU"
  36. :visible.sync="crud.status.cu > 0"
  37. :title="crud.status.title"
  38. >
  39. <div class="setting-dialog">
  40. <el-form ref="form" inline :model="form" :rules="rules" size="small" label-width="90px">
  41. <el-form-item v-if="crud.status.add === 1" label="所属门类" prop="categoryId">
  42. <treeselect
  43. v-model="form.categoryId"
  44. :options="categoryDatas"
  45. placeholder="选择所属门类"
  46. flat
  47. :multiple="false"
  48. :normalizer="normalizer"
  49. @select="selectCategoryTree"
  50. />
  51. </el-form-item>
  52. <el-form-item v-if="crud.status.edit === 1" label="所属门类" prop="categoryId">
  53. <el-input v-model="form.categoryName" disabled />
  54. </el-form-item>
  55. <el-form-item label="分类编码" prop="code">
  56. <el-input v-model="form.code" />
  57. </el-form-item>
  58. <el-form-item label="分类名称" prop="name">
  59. <el-input v-model="form.name" />
  60. </el-form-item>
  61. <el-form-item label="排序" prop="classSeq">
  62. <el-input-number
  63. v-model.number="form.classSeq"
  64. :min="0"
  65. :max="999"
  66. controls-position="right"
  67. />
  68. </el-form-item>
  69. <el-row>
  70. <el-form-item label="顶级分类" prop="isTop">
  71. <el-radio-group v-model="form.isTop" @input="changeIsTop">
  72. <el-radio label="1"></el-radio>
  73. <el-radio label="0"></el-radio>
  74. </el-radio-group>
  75. </el-form-item>
  76. <el-form-item
  77. v-if="form.isTop === '0'"
  78. label="上级分类"
  79. prop="pid"
  80. >
  81. <!-- :load-options="loadClassifyTree" -->
  82. <treeselect
  83. v-model="form.pid"
  84. :options="classifyOptions"
  85. :normalizer="classifyNormalizer"
  86. placeholder="选择门类之后再选择上级范围"
  87. />
  88. </el-form-item>
  89. </el-row>
  90. <el-form-item label="描述信息" prop="remark">
  91. <el-input v-model="form.remark" rows="5" type="textarea" style="width: 586px;" />
  92. </el-form-item>
  93. </el-form>
  94. <div slot="footer" class="dialog-footer">
  95. <el-button type="text" @click="crud.cancelCU">取消</el-button>
  96. <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确定</el-button>
  97. </div>
  98. </div>
  99. </el-dialog>
  100. <!--表格渲染-->
  101. <div class="container-right">
  102. <span class="right-top-line" />
  103. <span class="left-bottom-line" />
  104. <!-- :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" -->
  105. <el-table
  106. ref="table"
  107. v-loading="crud.loading"
  108. lazy
  109. :data="tableData"
  110. :row-key="getRowKey"
  111. :load="getSonClass"
  112. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  113. highlight-current-row
  114. @select-all="selectAll"
  115. @select="selectTr"
  116. @selection-change="selectionChangeHandler"
  117. @row-click="clickRowHandler"
  118. >
  119. <el-table-column type="selection" align="center" width="55" />
  120. <el-table-column label="分类名称" prop="name" />
  121. <el-table-column label="分类编号" prop="code" />
  122. <el-table-column label="排序" prop="classSeq" />
  123. <el-table-column label="所属门类" prop="categoryName" />
  124. <el-table-column prop="createTime" label="创建日期">
  125. <template slot-scope="scope">
  126. <div>{{ scope.row.createTime | parseTime }}</div>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. <!--分页组件-->
  131. <pagination v-if="crud.data.length!==0" />
  132. </div>
  133. </div>
  134. </template>
  135. <script>
  136. import { FetchCategoryMenu } from '@/api/system/category/category'
  137. import crudClassify from '@/api/system/archivesClass'
  138. import CRUD, { presenter, header, form, crud } from '@crud/crud'
  139. import crudOperation from '@crud/CRUD.operation'
  140. import pagination from '@crud/Pagination'
  141. import Treeselect from '@riophae/vue-treeselect'
  142. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  143. import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
  144. import { exportFile } from '@/utils/index'
  145. import qs from 'qs'
  146. import { mapGetters } from 'vuex'
  147. const defaultForm = {
  148. id: null,
  149. categoryId: null,
  150. name: null,
  151. code: null,
  152. isTop: '1',
  153. classSeq: 999,
  154. pid: null,
  155. remark: null
  156. }
  157. export default {
  158. name: 'Classify',
  159. components: { crudOperation, pagination, Treeselect },
  160. cruds() {
  161. return CRUD({ title: '分类', url: 'api/archivesClass/initArchivesClass', crudMethod: { ...crudClassify }, optShow: {
  162. add: false,
  163. edit: false,
  164. del: false,
  165. reset: false,
  166. download: false,
  167. group: false
  168. }})
  169. },
  170. mixins: [presenter(), header(), form(defaultForm), crud()],
  171. props: {
  172. selectedCategory: {
  173. type: Object,
  174. default: function() {
  175. return {}
  176. }
  177. }
  178. },
  179. data() {
  180. return {
  181. tableData: [],
  182. classifyOptions: [],
  183. categoryDatas: [],
  184. selections: [],
  185. isAllSelect: false,
  186. rules: {
  187. categoryId: [{ required: true, message: '请选择所属门类', trigger: 'change' }],
  188. code: [{ required: true, message: '分类编码不可为空', trigger: 'blur' }],
  189. name: [{ required: true, message: '分类名称不可为空', trigger: 'blur' }],
  190. classSeq: [{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }],
  191. isTop: [{ required: true, message: '请选择是否为顶级分类', trigger: 'change' }],
  192. pid: [{ required: true, message: '请选择上级分类', trigger: 'change' }]
  193. },
  194. permission: {
  195. add: ['admin', 'classify:add'],
  196. edit: ['admin', 'classify:edit'],
  197. del: ['admin', 'classify:del']
  198. }
  199. }
  200. },
  201. computed: {
  202. ...mapGetters([
  203. 'baseApi'
  204. ])
  205. },
  206. watch: {
  207. selectedCategory: function(newValue, oldValue) {
  208. this.crud.refresh()
  209. }
  210. },
  211. created() {
  212. },
  213. methods: {
  214. getRowKey(row) {
  215. return row.id
  216. },
  217. // 获取数据前设置默认参数
  218. [CRUD.HOOK.beforeRefresh]() {
  219. this.tableData = []
  220. this.crud.query.categoryId = this.selectedCategory.id
  221. },
  222. [CRUD.HOOK.afterRefresh](crud) {
  223. crud.data.forEach(function(item, index) {
  224. if (item.sonNum !== 0) {
  225. item.hasChildren = true
  226. item.children = null
  227. } else {
  228. item.hasChildren = false
  229. }
  230. })
  231. this.tableData = this.crud.data
  232. },
  233. // 提交前做的操作
  234. [CRUD.HOOK.afterValidateCU](crud) {
  235. console.log(crud.form)
  236. delete crud.form.isTop
  237. return true
  238. },
  239. changeIsTop(val) {
  240. if (this.crud.status.edit) {
  241. if (val === '1') {
  242. this.form.pid = null
  243. }
  244. }
  245. },
  246. // 新增与编辑前做的操作
  247. [CRUD.HOOK.afterToCU](crud, form) {
  248. this.getCategoryDataTree()
  249. if (this.crud.status.edit) {
  250. this.getClassifyTree(this.form.categoryId)
  251. } else {
  252. this.form.categoryId = null
  253. this.classifyOptions = []
  254. }
  255. if (form.id != null) {
  256. if (form.pid === null) {
  257. form.isTop = '1'
  258. } else {
  259. form.isTop = '0'
  260. }
  261. }
  262. },
  263. selectCategoryTree(val) {
  264. console.log(val)
  265. this.getClassifyTree(val.id)
  266. },
  267. filterData(data) {
  268. return data.filter(node => {
  269. if (node.children && node.children.length > 0) {
  270. node.children = this.filterData(node.children) // 递归处理子节点
  271. }
  272. return node.isType !== 3 // 过滤掉isType为3的节点
  273. })
  274. },
  275. getCategoryDataTree() {
  276. FetchCategoryMenu().then(res => {
  277. this.categoryDatas = this.filterData(res)
  278. })
  279. },
  280. getClassifyTree(categoryId) {
  281. crudClassify.FetchArchivesClassTree({ 'categoryId': categoryId }).then(res => {
  282. this.classifyOptions = res.map(function(obj) {
  283. if (obj.childArchivesClass !== null) {
  284. obj.hasChildren = true
  285. } else {
  286. obj.hasChildren = false
  287. }
  288. if (obj.hasChildren) {
  289. obj.children = null
  290. }
  291. return obj
  292. })
  293. })
  294. },
  295. // 获取弹窗内门类数据
  296. loadClassifyTree({ action, parentNode, callback }) {
  297. if (action === LOAD_CHILDREN_OPTIONS) {
  298. crudClassify.FetchArchivesClassTree().then(res => {
  299. parentNode.children = res.map(function(obj) {
  300. if (obj.childArchivesClass !== 0) {
  301. obj.hasChildren = true
  302. } else {
  303. obj.hasChildren = false
  304. }
  305. if (obj.hasChildren) {
  306. obj.children = null
  307. }
  308. return obj
  309. })
  310. setTimeout(() => {
  311. callback()
  312. }, 100)
  313. })
  314. }
  315. },
  316. getSonClass(tree, treeNode, resolve) {
  317. setTimeout(() => {
  318. crudClassify.FetchSonArchivesClass({ pid: tree.id }).then(res => {
  319. const data = res.map(function(obj) {
  320. if (obj.sonNum !== 0 && obj.sonNum) {
  321. obj.hasChildren = true
  322. obj.children = null
  323. } else {
  324. obj.hasChildren = false
  325. }
  326. return obj
  327. })
  328. resolve(data)
  329. })
  330. }, 100)
  331. },
  332. selectAll() {
  333. this.isAllSelect = !this.isAllSelect
  334. const data = this.tableData
  335. this.toggleSelect(data, this.isAllSelect, 'all')
  336. },
  337. // 选择某行
  338. selectTr(selection, row) {
  339. this.$set(row, 'isChecked', !row.isChecked)
  340. this.$nextTick(() => {
  341. this.isAllSelect = row.isChecked
  342. this.toggleSelect(row, row.isChecked, 'tr')
  343. })
  344. },
  345. // 递归子级
  346. toggleSelect(data, flag, type) {
  347. if (type === 'all') {
  348. if (data.length > 0) {
  349. data.forEach((item) => {
  350. this.toggleSelection(item, flag)
  351. if (item.children && item.children.length > 0) {
  352. this.toggleSelect(item.children, flag, type)
  353. }
  354. })
  355. }
  356. } else {
  357. if (data.children && data.children.length > 0) {
  358. data.children.forEach((item) => {
  359. item.isChecked = flag
  360. this.$refs.table.toggleRowSelection(item, flag)
  361. this.toggleSelect(item, flag, type)
  362. })
  363. }
  364. }
  365. },
  366. // 改变选中
  367. toggleSelection(row, flag) {
  368. this.$set(row, 'isChecked', flag)
  369. this.$nextTick(() => {
  370. if (flag) {
  371. this.$refs.table.toggleRowSelection(row, flag)
  372. } else {
  373. this.$refs.table.clearSelection()
  374. }
  375. })
  376. },
  377. // table - 当前选中得row
  378. clickRowHandler(row) {
  379. this.$refs.table.clearSelection()
  380. this.$refs.table.toggleRowSelection(row)
  381. },
  382. selectionChangeHandler(val) {
  383. this.selections = val
  384. },
  385. doExport(data) {
  386. crud.downloadLoading = true
  387. this.$confirm('此操作将导出所选数据' + '<span>你是否还要继续?</span>', '提示', {
  388. confirmButtonText: '继续',
  389. cancelButtonText: '取消',
  390. type: 'warning',
  391. dangerouslyUseHTMLString: true
  392. }).then(() => {
  393. const ids = []
  394. data.forEach(val => {
  395. ids.push(val.id)
  396. })
  397. const params = {
  398. 'classIds': ids
  399. }
  400. exportFile(this.baseApi + '/api/archivesClass/download?' + qs.stringify(params, { indices: false }))
  401. }).catch(() => {
  402. })
  403. },
  404. toDelete(datas) {
  405. this.$confirm('此操作将删除当前所选' + this.crud.title + '<span>你是否还要继续?</span>', '提示', {
  406. confirmButtonText: '继续',
  407. cancelButtonText: '取消',
  408. type: 'warning',
  409. dangerouslyUseHTMLString: true
  410. }).then(() => {
  411. this.crud.delAllLoading = true
  412. const ids = []
  413. datas.forEach(val => {
  414. ids.push(val.id)
  415. })
  416. crudClassify.del(ids).then(() => {
  417. this.crud.notify('删除成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
  418. this.crud.delAllLoading = false
  419. this.crud.refresh()
  420. }).catch(err => {
  421. this.crud.delAllLoading = false
  422. console.log(err)
  423. })
  424. }).catch(() => {
  425. })
  426. },
  427. normalizer(node) {
  428. if (node.children && !node.children.length) {
  429. delete node.children
  430. }
  431. return {
  432. id: node.id,
  433. label: node.cnName,
  434. children: node.children,
  435. isDisabled: node.isType !== 2
  436. }
  437. },
  438. classifyNormalizer(node) {
  439. if (node.childArchivesClass && !node.childArchivesClass.length) {
  440. delete node.childArchivesClass
  441. }
  442. return {
  443. id: node.id,
  444. label: node.name,
  445. children: node.childArchivesClass
  446. }
  447. }
  448. }
  449. }
  450. </script>
  451. <style lang="scss" scoped>
  452. .tip{
  453. line-height: 28px;
  454. }
  455. </style>