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

423 lines
14 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
3 years ago
3 years ago
3 years ago
3 years ago
3 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 CRUD, { presenter, header, form } from '@crud/crud'
  126. import crudOperation from '@crud/CRUD.operation'
  127. import pagination from '@crud/Pagination'
  128. import Treeselect from '@riophae/vue-treeselect'
  129. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  130. import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
  131. import { mapGetters } from 'vuex'
  132. import { exportFile } from '@/utils/index'
  133. import qs from 'qs'
  134. const defaultForm = { id: null, dictionaryName: null, isTop: '1', dictionaryCode: null, dictionaryOrder: 999, dictionaryRemarks: null, dictionaryParents: null }
  135. export default {
  136. name: 'Dicts',
  137. components: { crudOperation, Treeselect, pagination },
  138. cruds() {
  139. return [
  140. CRUD({
  141. title: '字典', idField: 'dictionaryId', url: 'api/dictionary/initDictionaryList',
  142. crudMethod: { ...crudDict },
  143. sort: [],
  144. optShow: {
  145. add: true,
  146. edit: true,
  147. del: false,
  148. reset: true,
  149. download: false,
  150. group: false
  151. }})
  152. ]
  153. },
  154. mixins: [
  155. presenter(),
  156. header(),
  157. form(function() {
  158. return Object.assign({ dictionaryParents: this.dictionaryParents }, defaultForm)
  159. })
  160. ],
  161. props: {
  162. activeAddBtn: {
  163. type: Boolean
  164. }
  165. },
  166. data() {
  167. return {
  168. dicts: [],
  169. dictionaryParents: null,
  170. rules: {
  171. dictionaryName: [
  172. { required: true, message: '请输入字典名称', trigger: 'blur' }
  173. ],
  174. dictionaryCode: [
  175. { required: true, message: '请输入字典代码', trigger: 'blur' }
  176. ],
  177. isTop: [
  178. { required: true, message: '请选择是否为顶级节点', trigger: 'change' }
  179. ],
  180. dictionaryOrder: [
  181. { required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
  182. ]
  183. },
  184. permission: {
  185. add: ['admin', 'dict:add'],
  186. edit: ['admin', 'dict:edit'],
  187. del: ['admin', 'dict:del']
  188. },
  189. deleteVisible: false,
  190. deleteData: {},
  191. isAllSelect: false
  192. }
  193. },
  194. computed: {
  195. ...mapGetters([
  196. 'baseApi'
  197. ])
  198. },
  199. mounted() {
  200. },
  201. methods: {
  202. // 处理vue-treeSelect回显出现unknown问题
  203. getAutoNameUnknown(name) {
  204. if (name.lastIndexOf('unknown') > -1) {
  205. return name.split('(')[0]
  206. } else {
  207. return name
  208. }
  209. },
  210. getRowKey(row) {
  211. return row.dictionaryId
  212. },
  213. resetQuery() {
  214. this.crud.query.blurry = ''
  215. this.crud.toQuery()
  216. },
  217. // 新增与编辑前做的操作
  218. [CRUD.HOOK.afterToCU](crud, form) {
  219. if (form.dictionaryParents !== null) {
  220. form.isTop = '0'
  221. } else if (form.dictionaryId !== null) {
  222. form.isTop = '1'
  223. }
  224. this.getDictsTreeList()
  225. },
  226. // 获取数据前设置默认参数
  227. [CRUD.HOOK.beforeRefresh]() {
  228. this.tableData = []
  229. },
  230. [CRUD.HOOK.afterRefresh](crud) {
  231. crud.data.forEach(function(item, index) {
  232. if (item.sonNum !== 0) {
  233. item.hasChildren = true
  234. } else {
  235. item.hasChildren = false
  236. }
  237. if (!item.hasChildren) {
  238. item.children = null
  239. }
  240. })
  241. this.tableData = this.crud.data
  242. },
  243. // 编辑前
  244. [CRUD.HOOK.beforeToEdit](crud, form) {
  245. crud.form.id = form.dictionaryId
  246. },
  247. // 提交前的验证
  248. [CRUD.HOOK.afterValidateCU](crud) {
  249. if (crud.form.isTop === '1') {
  250. crud.form.dictionaryParents = null
  251. }
  252. delete crud.form.isTop
  253. console.log(crud.form)
  254. return true
  255. },
  256. changeIsTop(val) {
  257. if (val === '0') {
  258. this.getDictsTreeList()
  259. }
  260. },
  261. selectAll() {
  262. this.isAllSelect = !this.isAllSelect
  263. const data = this.tableData
  264. this.toggleSelect(data, this.isAllSelect, 'all')
  265. console.log(data)
  266. },
  267. // 选择某行
  268. selectTr(selection, row) {
  269. this.$set(row, 'isChecked', !row.isChecked)
  270. this.$nextTick(() => {
  271. this.isAllSelect = row.isChecked
  272. this.toggleSelect(row, row.isChecked, 'tr')
  273. })
  274. },
  275. // 递归子级
  276. toggleSelect(data, flag, type) {
  277. if (type === 'all') {
  278. if (data.length > 0) {
  279. data.forEach((item) => {
  280. this.toggleSelection(item, flag)
  281. if (item.children && item.children.length > 0) {
  282. this.toggleSelect(item.children, flag, type)
  283. }
  284. })
  285. }
  286. } else {
  287. if (data.children && data.children.length > 0) {
  288. data.children.forEach((item) => {
  289. item.isChecked = flag
  290. this.$refs.table.toggleRowSelection(item, flag)
  291. this.toggleSelect(item, flag, type)
  292. })
  293. }
  294. }
  295. },
  296. // 改变选中
  297. toggleSelection(row, flag) {
  298. this.$set(row, 'isChecked', flag)
  299. this.$nextTick(() => {
  300. if (flag) {
  301. this.$refs.table.toggleRowSelection(row, flag)
  302. } else {
  303. this.$refs.table.clearSelection()
  304. }
  305. })
  306. },
  307. clickRowHandler(row) {
  308. this.$refs.table.clearSelection()
  309. this.$refs.table.toggleRowSelection(row)
  310. },
  311. getDictsDatas(tree, treeNode, resolve) {
  312. setTimeout(() => {
  313. console.log(treeNode)
  314. crudDict.FetchSonDictionaryList({ pid: tree.dictionaryId }).then(res => {
  315. const data = res.map(function(obj) {
  316. if (obj.sonNum !== 0) {
  317. obj.hasChildren = true
  318. obj.children = null
  319. } else {
  320. obj.hasChildren = false
  321. }
  322. return obj
  323. })
  324. resolve(data)
  325. })
  326. }, 100)
  327. },
  328. getDictsTreeList() {
  329. crudDict.FetchDictionaryTree().then(res => {
  330. this.dicts = res.map(function(obj) {
  331. if (obj.sonNum !== 0) {
  332. obj.hasChildren = true
  333. } else {
  334. obj.hasChildren = false
  335. }
  336. if (obj.hasChildren) {
  337. obj.children = null
  338. }
  339. return obj
  340. })
  341. this.crud.loading = false
  342. })
  343. },
  344. // 获取弹窗内字典数据
  345. loadDicts({ action, parentNode, callback }) {
  346. if (action === LOAD_CHILDREN_OPTIONS) {
  347. crudDict.FetchDictionaryTree().then(res => {
  348. parentNode.children = res.map(function(obj) {
  349. if (obj.children) {
  350. obj.childMenus = null
  351. }
  352. return obj
  353. })
  354. setTimeout(() => {
  355. callback()
  356. }, 100)
  357. })
  358. }
  359. },
  360. toDelete(datas) {
  361. this.deleteData = datas
  362. this.$confirm('此操作将删除当前所选' + this.crud.title + '<span>你是否还要继续?</span>', '提示', {
  363. confirmButtonText: '继续',
  364. cancelButtonText: '取消',
  365. type: 'warning',
  366. dangerouslyUseHTMLString: true
  367. }).then(() => {
  368. this.crud.delAllLoading = true
  369. const dictionaryIds = []
  370. this.deleteData.forEach(val => {
  371. dictionaryIds.push(val.dictionaryId)
  372. })
  373. crudDict.del(dictionaryIds).then(() => {
  374. this.$message({ message: '删除成功', type: 'success', offset: 8 })
  375. this.crud.delAllLoading = false
  376. this.crud.refresh()
  377. }).catch(err => {
  378. this.crud.delAllLoading = false
  379. console.log(err)
  380. })
  381. }).catch(() => {
  382. })
  383. },
  384. doExport(data) {
  385. console.log(data)
  386. this.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.dictionaryId)
  396. })
  397. const params = {
  398. 'dictionaryIds': ids
  399. }
  400. exportFile(this.baseApi + '/api/dictionary/download?' + qs.stringify(params, { indices: false }))
  401. this.crud.downloadLoading = false
  402. }).catch(() => {
  403. })
  404. },
  405. normalizer(node) {
  406. if (node.childDictionarys == null || node.childDictionarys === 'null') {
  407. delete node.childDictionarys
  408. }
  409. return {
  410. id: node.id,
  411. label: node.dictionaryName,
  412. children: node.childDictionarys
  413. }
  414. }
  415. }
  416. }
  417. </script>
  418. <style lang="scss" scoped>
  419. </style>