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

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