index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <d2-container>
  3. <template slot="header">
  4. <el-form :inline="true"
  5. :model="searchForm"
  6. ref="searchForm"
  7. size="mini"
  8. style="height: 25px; margin-top: -7px;text-align:right;">
  9. <el-form-item label="字典分类名称"
  10. prop="name">
  11. <el-input v-model="searchForm.name"
  12. placeholder="字典分类名称"
  13. style="width: 140px;"
  14. clearable />
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button type="primary"
  18. size="mini"
  19. style="margin-left:10px"
  20. @click="handleSearch">
  21. <d2-icon name="search" /> 查询
  22. </el-button>
  23. <el-button @click="handleSearchFormReset"
  24. type="primary"
  25. size="mini">
  26. <d2-icon name="refresh" /> 重置
  27. </el-button>
  28. <el-button type="primary"
  29. size="mini"
  30. icon="el-icon-circle-plus"
  31. @click="add"> 新增
  32. </el-button>
  33. <el-button type="primary"
  34. size="mini"
  35. icon="el-icon-circle-plus"
  36. :disabled="deleteBtnVisible"
  37. @click="delSelectedIds"> 删除
  38. </el-button>
  39. </el-form-item>
  40. </el-form>
  41. </template>
  42. <ag-grid-vue class="table ag-theme-balham ag-title-center"
  43. style="width: 100%; height: 100%;"
  44. id="myGrid"
  45. :gridOptions="gridOptions"
  46. @gridReady="onGridReady"
  47. :rowData="rowData"
  48. :columnDefs="columnDefs"
  49. rowSelection="multiple">
  50. </ag-grid-vue>
  51. <template slot="footer">
  52. <el-pagination style="margin: -10px;"
  53. @size-change="handleSizeChange"
  54. @current-change="handleCurrentChange"
  55. :current-page="page.current"
  56. :page-size="page.size"
  57. :total="page.total"
  58. :page-sizes="[10, 20]"
  59. layout="total, sizes, prev, pager, next, jumper">
  60. </el-pagination>
  61. </template>
  62. <edit-form :id="id"
  63. v-model="editFormVisible"
  64. @submit="doRefresh" />
  65. </d2-container>
  66. </template>
  67. <script>
  68. import command from './components/command'
  69. import itemApi from '@/api/sysadmin/item'
  70. import editForm from './editForm'
  71. import { AgGridVue } from 'ag-grid-vue'
  72. import 'ag-grid-community/dist/styles/ag-grid.css'
  73. import 'ag-grid-community/dist/styles/ag-theme-balham.css'
  74. export default {
  75. name: 'item',
  76. components: { AgGridVue, editForm },
  77. data () {
  78. return {
  79. // ag-grid相关变量
  80. gridOptions: null,
  81. gridApi: null,
  82. columnApi: null,
  83. rowData: null,
  84. columnDefs: null,
  85. page: {
  86. current: 1,
  87. size: 10,
  88. total: 1
  89. },
  90. sort: {
  91. prop: '',
  92. order: ''
  93. },
  94. id: -1,
  95. rowdata: {},
  96. searchForm: {
  97. name: ''
  98. // code: ''
  99. },
  100. loading: false,
  101. multipleSelection: [],
  102. editFormVisible: false,
  103. deleteBtnVisible: true,
  104. deleteIds: []
  105. }
  106. },
  107. beforeMount () {
  108. this.gridOptions = {
  109. rowHeight: 32, // 设置行高为32px
  110. // 缺省列属性
  111. defaultColDef: {
  112. width: 200,
  113. resizable: true
  114. },
  115. onRowSelected: this.handleSelectionChange, // 行选中
  116. onSortChanged: this.handleSortChange // 排序传递后台
  117. }
  118. this.columnDefs = [
  119. { headerName: '', checkboxSelection: true, headerCheckboxSelection: true, width: 50, 'pinned': 'left' },
  120. {
  121. headerName: '序号',
  122. width: 50,
  123. field: 'OrdNo',
  124. cellRenderer: (params) => {
  125. return params ? params.node.rowIndex + 1 + '' : ''
  126. }
  127. }, {
  128. headerName: '分类名称',
  129. field: 'FullName',
  130. sortable: true
  131. }, {
  132. headerName: '分类编码',
  133. field: 'Code',
  134. sortable: true
  135. }, {
  136. headerName: '关联表',
  137. field: 'TargetTable',
  138. sortable: true
  139. }, {
  140. headerName: '使用分类名',
  141. field: 'UseItemName',
  142. valueFormatter (params) {
  143. return params.value === 0 ? '否' : '是'
  144. }
  145. },
  146. {
  147. headerName: '使用分类编码',
  148. field: 'UseItemCode',
  149. valueFormatter (params) {
  150. return params.value === 0 ? '否' : '是'
  151. }
  152. },
  153. {
  154. headerName: '树结构',
  155. field: 'IsTree',
  156. valueFormatter (params) {
  157. return params.value === 0 ? '否' : '是'
  158. },
  159. sortable: true
  160. },
  161. { headerName: '排序', field: 'SortCode' },
  162. { headerName: '备注', field: 'Description' },
  163. { headerName: '创建时间', field: 'CreateOn', sortable: true },
  164. { headerName: '更新时间', field: 'ModifiedOn', sortable: true },
  165. { headerName: '操作', field: 'operation', width: 160, 'pinned': 'right', cellRendererFramework: command }
  166. ]
  167. },
  168. created () {
  169. },
  170. mounted () {
  171. this.gridOptions.context = { page: this }
  172. this.gridApi = this.gridOptions.api
  173. this.gridColumnApi = this.gridOptions.columnApi
  174. this.doRefresh()
  175. },
  176. methods: {
  177. // 表格就绪后后执行
  178. onGridReady (params) {
  179. // 调整表格列宽大小自适应
  180. this.gridApi.sizeColumnsToFit()
  181. },
  182. // 执行刷新(获取数据)
  183. doRefresh () {
  184. let _this = this
  185. let query = {
  186. // 分页信息
  187. size: this.page.size,
  188. current: this.page.current,
  189. // 排序信息
  190. prop: this.sort.prop,
  191. order: this.sort.order,
  192. // 搜索名称
  193. name: this.searchForm.name
  194. }
  195. itemApi.getList(query)
  196. .then(res => {
  197. _this.rowData = res.records
  198. _this.page.total = res.total
  199. _this.deleteBtnVisible = true
  200. })
  201. .catch(err => {
  202. console.error(err)
  203. })
  204. },
  205. // 分页-改变分页大小
  206. handleSizeChange (value) {
  207. this.page.size = value
  208. this.page.current = 1
  209. this.doRefresh()
  210. },
  211. // 分页-改变当前页
  212. handleCurrentChange (value) {
  213. this.page.current = value
  214. this.doRefresh()
  215. },
  216. // 处理编辑
  217. handleEdit (id) {
  218. this.id = id
  219. this.editFormVisible = true
  220. },
  221. // 处理删除
  222. handleDelete (id) {
  223. const params = {
  224. ids: this.deleteIds
  225. }
  226. itemApi.delete(params).then((res) => {
  227. this.$message({
  228. type: 'success',
  229. message: '删除成功!'
  230. })
  231. this.doRefresh()
  232. })
  233. },
  234. // 查询
  235. handleSearch () {
  236. this.currentPage = 1
  237. this.doRefresh()
  238. },
  239. // 重置
  240. handleSearchFormReset () {
  241. this.searchForm.name = ''
  242. this.doRefresh()
  243. },
  244. // 新建窗口
  245. add () {
  246. this.rowdata = {}
  247. this.id = -1
  248. this.editFormVisible = true
  249. },
  250. // 批量删除
  251. delSelectedIds () {
  252. this.$confirm('此操作将永久删除所选字典分类, 是否继续?', '提示', {
  253. confirmButtonText: '确定',
  254. cancelButtonText: '取消',
  255. type: 'warning'
  256. }).then(() => {
  257. const params = {
  258. ids: this.deleteIds
  259. }
  260. itemApi.delete(params).then((res) => {
  261. this.$message({
  262. type: 'success',
  263. message: '删除成功!'
  264. })
  265. this.doRefresh()
  266. })
  267. }).catch(() => {
  268. this.$message({
  269. type: 'info',
  270. message: '已取消删除'
  271. })
  272. })
  273. },
  274. // 处理列表选择
  275. handleSelectionChange () {
  276. let _this = this
  277. _this.multipleSelection = _this.gridOptions.api.getSelectedRows()
  278. _this.deleteBtnVisible = !_this.multipleSelection || _this.multipleSelection.length === 0
  279. if (!_this.deleteBtnVisible) {
  280. _this.deleteIds = []
  281. // 赋值删除id列表
  282. _this.multipleSelection.forEach((item, k) => {
  283. _this.deleteIds.push(item.Id)
  284. })
  285. } else {
  286. _this.deleteIds = []
  287. }
  288. },
  289. handleSortChange (val) {
  290. var sortState = this.gridApi.getSortModel()
  291. // 获取排序的字段
  292. if (sortState && sortState.length > 0) {
  293. var item = sortState[0]
  294. this.sort.prop = item.colId
  295. this.sort.order = item.sort
  296. }
  297. this.doRefresh()
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss">
  303. .el-pagination {
  304. margin: 1rem 0 2rem;
  305. text-align: right;
  306. }
  307. .plab {
  308. font-size: 13px;
  309. color: #999;
  310. }
  311. .rowequippower .el-checkbox {
  312. margin-left: 1px;
  313. padding: 5px 10px 0 0;
  314. }
  315. .ag-header-cell-text {
  316. text-align: center;
  317. width: 100%;
  318. }
  319. </style>