image.png

    1. /**
    2. * 系统管理 公司管理
    3. */
    4. <template>
    5. <div class="app-container">
    6. <!-- 面包屑导航 -->
    7. <!-- <el-breadcrumb separator-class="el-icon-arrow-right">
    8. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    9. <el-breadcrumb-item>公司管理</el-breadcrumb-item>
    10. </el-breadcrumb> -->
    11. <!-- 搜索筛选 -->
    12. <el-form :inline="true" :model="formInline" class="user-search">
    13. <el-form-item label="搜索:">
    14. <el-input size="small" v-model="formInline.deptName" placeholder="输入部门名称"></el-input>
    15. </el-form-item>
    16. <el-form-item label="">
    17. <el-input size="small" v-model="formInline.deptNo" placeholder="输入部门代码"></el-input>
    18. </el-form-item>
    19. <el-form-item>
    20. <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
    21. <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()">添加</el-button>
    22. </el-form-item>
    23. </el-form>
    24. <!--列表-->
    25. <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
    26. <el-table-column align="center" type="selection" width="60">
    27. </el-table-column>
    28. <el-table-column align="center" type="index" label="序号" width="60">
    29. </el-table-column>
    30. <el-table-column sortable prop="deptName" label="部门名称" width="300">
    31. </el-table-column>
    32. <el-table-column sortable prop="deptNo" label="部门代码" width="300">
    33. </el-table-column>
    34. <el-table-column sortable prop="editTime" label="修改时间" width="300">
    35. <!-- <template slot-scope="scope">
    36. <div>{{scope.row.editTime|timestampToTime}}</div>
    37. </template> -->
    38. </el-table-column>
    39. <el-table-column sortable prop="editUser" label="修改人" width="300">
    40. </el-table-column>
    41. <el-table-column align="center" label="操作" min-width="300">
    42. <template slot-scope="scope">
    43. <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
    44. <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
    45. </template>
    46. </el-table-column>
    47. </el-table>
    48. <!-- 分页组件 -->
    49. <!-- <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination> -->
    50. <pagination v-show="pageparm.total>0" :total="pageparm.total" :page.sync="pageparm.currentPage" :limit.sync="pageparm.pageSize" @pagination="getdata" />
    51. <!-- 编辑界面 -->
    52. <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
    53. <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
    54. <el-form-item label="部门名称" prop="deptName">
    55. <el-input size="small" v-model="editForm.deptName" auto-complete="off" placeholder="请输入部门名称"></el-input>
    56. </el-form-item>
    57. <el-form-item label="部门代码" prop="deptNo">
    58. <el-input size="small" v-model="editForm.deptNo" auto-complete="off" placeholder="请输入部门代码"></el-input>
    59. </el-form-item>
    60. </el-form>
    61. <div slot="footer" class="dialog-footer">
    62. <el-button size="small" @click="closeDialog">取消</el-button>
    63. <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
    64. </div>
    65. </el-dialog>
    66. </div>
    67. </template>
    68. <script>
    69. // import { deptList, deptSave, deptDelete } from '../../api/userMG'
    70. import Pagination from '@/components/Pagination'
    71. export default {
    72. data() {
    73. return {
    74. nshow: true, //switch开启
    75. fshow: false, //switch关闭
    76. loading: false, //是显示加载
    77. editFormVisible: false, //控制编辑页面显示与隐藏
    78. title: '添加',
    79. editForm: {
    80. deptId: '',
    81. deptName: '',
    82. deptNo: '',
    83. token: localStorage.getItem('logintoken')
    84. },
    85. // rules表单验证
    86. rules: {
    87. deptName: [
    88. { required: true, message: '请输入部门名称', trigger: 'blur' }
    89. ],
    90. deptNo: [{ required: true, message: '请输入部门代码', trigger: 'blur' }]
    91. },
    92. formInline: {
    93. page: 1,
    94. limit: 10,
    95. varLable: '',
    96. varName: '',
    97. token: localStorage.getItem('logintoken')
    98. },
    99. // 删除部门
    100. seletedata: {
    101. ids: '',
    102. token: localStorage.getItem('logintoken')
    103. },
    104. userparm: [], //搜索权限
    105. listData: [], //用户数据
    106. // 分页参数
    107. pageparm: {
    108. currentPage: 1,
    109. pageSize: 10,
    110. total: 10
    111. }
    112. }
    113. },
    114. // 注册组件
    115. components: {
    116. Pagination
    117. },
    118. /**
    119. * 数据发生改变
    120. */
    121. /**
    122. * 创建完毕
    123. */
    124. created() {
    125. this.getdata(this.formInline)
    126. },
    127. /**
    128. * 里面的方法只有被调用才会执行
    129. */
    130. methods: {
    131. // 获取公司列表
    132. getdata(parameter) {
    133. this.loading = true
    134. // 模拟数据
    135. let res = {
    136. code: 0,
    137. msg: null,
    138. count: 5,
    139. data: [
    140. {
    141. addUser: null,
    142. editUser: null,
    143. addTime: 1521062371000,
    144. editTime: 1526700200000,
    145. deptId: 2,
    146. deptName: '上海分公司',
    147. deptNo: '1',
    148. parentId: 1
    149. },
    150. {
    151. addUser: null,
    152. editUser: null,
    153. addTime: 1521063247000,
    154. editTime: 1526652291000,
    155. deptId: 3,
    156. deptName: '上海测试',
    157. deptNo: '02',
    158. parentId: 1
    159. },
    160. {
    161. addUser: null,
    162. editUser: null,
    163. addTime: 1526349555000,
    164. editTime: 1526349565000,
    165. deptId: 12,
    166. deptName: '1',
    167. deptNo: '11',
    168. parentId: 1
    169. },
    170. {
    171. addUser: null,
    172. editUser: null,
    173. addTime: 1526373178000,
    174. editTime: 1526373178000,
    175. deptId: 13,
    176. deptName: '5',
    177. deptNo: '5',
    178. parentId: 1
    179. },
    180. {
    181. addUser: null,
    182. editUser: null,
    183. addTime: 1526453107000,
    184. editTime: 1526453107000,
    185. deptId: 17,
    186. deptName: 'v',
    187. deptNo: 'v',
    188. parentId: 1
    189. }
    190. ]
    191. }
    192. this.loading = false
    193. this.listData = res.data
    194. // 分页赋值
    195. this.pageparm.currentPage = this.formInline.page
    196. this.pageparm.pageSize = this.formInline.limit
    197. this.pageparm.total = res.count
    198. // 模拟数据结束
    199. /***
    200. * 调用接口,注释上面模拟数据 取消下面注释
    201. */
    202. // deptList(parameter)
    203. // .then(res => {
    204. // this.loading = false
    205. // if (res.success == false) {
    206. // this.$message({
    207. // type: 'info',
    208. // message: res.msg
    209. // })
    210. // } else {
    211. // this.listData = res.data
    212. // // 分页赋值
    213. // this.pageparm.currentPage = this.formInline.page
    214. // this.pageparm.pageSize = this.formInline.limit
    215. // this.pageparm.total = res.count
    216. // }
    217. // })
    218. // .catch(err => {
    219. // this.loading = false
    220. // this.$message.error('菜单加载失败,请稍后再试!')
    221. // })
    222. },
    223. // 分页插件事件
    224. callFather(parm) {
    225. this.formInline.page = parm.currentPage
    226. this.formInline.limit = parm.pageSize
    227. this.getdata(this.formInline)
    228. },
    229. // 搜索事件
    230. search() {
    231. this.getdata(this.formInline)
    232. },
    233. //显示编辑界面
    234. handleEdit: function(index, row) {
    235. this.editFormVisible = true
    236. if (row != undefined && row != 'undefined') {
    237. this.title = '修改'
    238. this.editForm.deptId = row.deptId
    239. this.editForm.deptName = row.deptName
    240. this.editForm.deptNo = row.deptNo
    241. } else {
    242. this.title = '添加'
    243. this.editForm.deptId = ''
    244. this.editForm.deptName = ''
    245. this.editForm.deptNo = ''
    246. }
    247. },
    248. // 编辑、增加页面保存方法
    249. submitForm(editData) {
    250. this.$refs[editData].validate(valid => {
    251. if (valid) {
    252. deptSave(this.editForm)
    253. .then(res => {
    254. this.editFormVisible = false
    255. this.loading = false
    256. if (res.success) {
    257. this.getdata(this.formInline)
    258. this.$message({
    259. type: 'success',
    260. message: '公司保存成功!'
    261. })
    262. } else {
    263. this.$message({
    264. type: 'info',
    265. message: res.msg
    266. })
    267. }
    268. })
    269. .catch(err => {
    270. this.editFormVisible = false
    271. this.loading = false
    272. this.$message.error('公司保存失败,请稍后再试!')
    273. })
    274. } else {
    275. return false
    276. }
    277. })
    278. },
    279. // 删除公司
    280. deleteUser(index, row) {
    281. this.$confirm('确定要删除吗?', '信息', {
    282. confirmButtonText: '确定',
    283. cancelButtonText: '取消',
    284. type: 'warning'
    285. })
    286. .then(() => {
    287. deptDelete(row.deptId)
    288. .then(res => {
    289. if (res.success) {
    290. this.$message({
    291. type: 'success',
    292. message: '公司已删除!'
    293. })
    294. this.getdata(this.formInline)
    295. } else {
    296. this.$message({
    297. type: 'info',
    298. message: res.msg
    299. })
    300. }
    301. })
    302. .catch(err => {
    303. this.loading = false
    304. this.$message.error('公司删除失败,请稍后再试!')
    305. })
    306. })
    307. .catch(() => {
    308. this.$message({
    309. type: 'info',
    310. message: '已取消删除'
    311. })
    312. })
    313. },
    314. // 关闭编辑、增加弹出框
    315. closeDialog() {
    316. this.editFormVisible = false
    317. }
    318. }
    319. }
    320. </script>
    321. <style scoped>
    322. .user-search {
    323. margin-top: 20px;
    324. }
    325. .userRole {
    326. width: 100%;
    327. }
    328. </style>