index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <div class="app-container">
  3. <div class="app-container">
  4. <div class = "search-bx" >
  5. <div class="search">
  6. <el-row :gutter="0">
  7. <el-col :span="21">
  8. <el-input v-model="get_table_dataParm.parammaps.ename" placeholder="姓名" style="width: 180px;" class="filter-item" clearable />
  9. <el-select v-model="get_table_dataParm.parammaps.departmentId" placeholder="集团" class="filter-item" style="width: 120px;" clearable>
  10. <el-option v-for="(item,index) in departmentList" :key="index" :label="item.name" :value="item.id" />
  11. </el-select>
  12. </el-col>
  13. <el-col :span="3">
  14. <el-button class="successBorder" @click="form_search">查询</el-button>
  15. <el-button class="successBorder" @click="form_clear">重置</el-button>
  16. </el-col>
  17. </el-row>
  18. </div>
  19. <div class="operation">
  20. <el-row :gutter="0">
  21. <el-col :span="21">
  22. <el-button class="success" icon="el-icon-plus" @click="form_add">新增</el-button>
  23. </el-col>
  24. <el-col :span="3">
  25. </el-col>
  26. </el-row>
  27. </div>
  28. </div>
  29. <div class="table" style="margin-top:100px">
  30. <el-table v-loading="listLoading" element-loading-text="给我一点时间" :data="list" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable" row-key="id">
  31. <el-table-column label="序号" align="center" type="index" width="50px">
  32. <template slot-scope="scope">
  33. <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="姓名" header-align="center" align="center" width="200px">
  37. <template slot-scope="scope">
  38. <span>{{ scope.row.ename }}</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="部门" width="200px" header-align="center" align="center">
  42. <template slot-scope="scope">
  43. <span>{{ scope.row.dname }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="电话" width="200px" header-align="center" align="center">
  47. <template slot-scope="scope">
  48. <span>{{ scope.row.telephone }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="备注" width="200px" header-align="center" align="center">
  52. <template slot-scope="scope">
  53. <span>{{ scope.row.remark }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="顺序" width="100px" header-align="center" align="center">
  57. <template slot-scope="scope">
  58. <span>{{ scope.row.sort }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  62. <template slot-scope="scope">
  63. <el-switch v-model="scope.row.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="change_enable(scope.$index, scope.row)" />
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">
  67. <template slot-scope="{row}">
  68. <el-button type="primary" size="mini" @click="form_edit(row)">
  69. 编辑
  70. </el-button>
  71. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)">
  72. 删除
  73. </el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <pagination v-show="total>=0" :total="total" :page.sync="get_table_dataParm.offset" :limit.sync="get_table_dataParm.pagecount" @pagination="get_table_data" />
  78. </div>
  79. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="40%">
  80. <el-form ref="dataForm" :rules="rules" :model="deptform" label-position="left" label-width="100px" style="width: 400px; margin-left:50px;">
  81. <el-form-item label="姓名" prop="ename">
  82. <el-input ref="ename" v-model="deptform.ename" />
  83. </el-form-item>
  84. <el-form-item label="部门" prop="parentid">
  85. <tree-select :disabled="disabled" :height="280" :width="200" size="small" :data="parent" :default-props="defaultProps" clearable :node-key="nodeKey" :checked-keys="defaultCheckedKeys" @popoverHide="popoverHide" />
  86. </el-form-item>
  87. <el-form-item label="电话" prop="telephone">
  88. <el-input ref="telephone" v-model="deptform.telephone" maxlength="11" />
  89. </el-form-item>
  90. <el-form-item label="备注" prop="remark">
  91. <el-input ref="remark" v-model="deptform.remark" />
  92. </el-form-item>
  93. <el-form-item label="顺序" prop="sort">
  94. <el-input ref="sort" v-model="deptform.sort" />
  95. </el-form-item>
  96. <el-form-item label="启用" prop="enable">
  97. <el-switch ref="enable" v-model="deptform.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  98. </el-form-item>
  99. </el-form>
  100. <div slot="footer" class="dialog-footer">
  101. <el-button class="cancelClose" @click="dialogFormVisible = false;get_table_data()">关闭</el-button>
  102. <el-button class="success" @click="dialogStatus==='create'?add_dialog_save():form_edit_save()">确认</el-button>
  103. </div>
  104. </el-dialog>
  105. </div>
  106. </div>
  107. </template>
  108. <script>
  109. import TreeSelect from '@/components/TreeSelect'
  110. import waves from '@/directive/waves' // waves directive
  111. import Cookies from 'js-cookie'
  112. import { isIntegerZero } from '@/utils/validate'
  113. import { PostDataByName, GetDataByName, transData, failproccess, } from '@/api/common'
  114. import { MessageBox } from 'element-ui'
  115. import Pagination from '@/components/Pagination'
  116. export default {
  117. name: 'StaffManagement',
  118. components: { TreeSelect, Pagination },
  119. directives: { waves },
  120. filters: {
  121. menutypeFilter(menutype) {
  122. const menutypeMap = {
  123. menu: '',
  124. button: 'warning'
  125. }
  126. return menutypeMap[menutype]
  127. }
  128. },
  129. data() {
  130. return {
  131. disabled: false,
  132. tableKey: 0,
  133. list: [
  134. { 'deptname': '公司', 'id': 1, 'parentid': -1, 'remark': '' }
  135. ],
  136. parent: [],
  137. parentmenu: [],
  138. parentButton: [],
  139. departmentList: [],
  140. requestParam: {
  141. name: 'insertEmployees',
  142. parammaps: {}
  143. },
  144. deptform: {
  145. id: '',
  146. ename: '',
  147. remark: '',
  148. sort: '',
  149. parentid: '0',
  150. telephone: "",
  151. enable: '1'
  152. },
  153. get_table_dataParm: {
  154. name: 'getEmployees',
  155. page: 1,
  156. offset: 1,
  157. pagecount: parseInt(Cookies.get('pagecount')),
  158. returntype: 'Map',
  159. parammaps: {
  160. ename: "",
  161. departmentId: "",
  162. }
  163. },
  164. listLoading: true,
  165. tableKey: 0,
  166. list: [],
  167. total: 0,
  168. getRecuListParm: { name: 'getDepartmentCascade' },
  169. getRecuListBParm: { name: 'getMenuListBRecu',
  170. idname: 'id',
  171. parammaps: { id: 0 }
  172. },
  173. rules: {
  174. ename: [{ type: 'string', required: true, message: '姓名必填', trigger: 'change' }],
  175. parentid: [{ required: true, message: '部门名称必填', trigger: 'change' }],
  176. telephone: [{ required: true, message: '电话不能为空'},
  177. { min: 11, max: 11, message: '必填11个字符', trigger: 'blur' }],
  178. sort: [{ validator: isIntegerZero, trigger: 'blur' }]
  179. },
  180. dialogFormVisible: false,
  181. dialogStatus: '',
  182. textMap: {
  183. update: '编辑',
  184. create: '新增'
  185. },
  186. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  187. cellStyle: { padding: 0 + 'px' },
  188. defaultProps: {
  189. children: 'children',
  190. label: 'title'
  191. },
  192. nodeKey: 'id',
  193. defaultCheckedKeys: []
  194. }
  195. },
  196. created() {
  197. this.get_table_data()
  198. this.get_select_list()
  199. },
  200. methods: {
  201. popoverHide(checkedIds, checkedData) {
  202. this.deptform.parentid = checkedIds
  203. },
  204. form_search() {
  205. console.log('点击了查询')
  206. this.get_table_dataParm.offset = 1
  207. this.get_table_data()
  208. },
  209. form_clear() {
  210. console.log('点击了重置')
  211. this.get_table_dataParm.parammaps.departmentId = ''
  212. this.get_table_dataParm.parammaps.ename = ''
  213. this.get_table_dataParm.offset = 1
  214. this.get_table_data()
  215. },
  216. get_table_data() {
  217. this.listLoading = true
  218. GetDataByName(this.get_table_dataParm).then(response => {
  219. if (response.data.list !== null) {
  220. console.log(this.list, '-----------------')
  221. for (var i = 0; i < response.data.list.length; i++) {
  222. response.data.list[i].enable = parseInt(response.data.list[i].enable)
  223. }
  224. this.list = response.data.list
  225. this.pageNum = response.data.pageNum
  226. this.pageSize = response.data.pageSize
  227. this.total = response.data.total
  228. } else {
  229. this.list = []
  230. }
  231. setTimeout(() => {
  232. this.listLoading = false
  233. }, 0.5 * 1000)
  234. })
  235. },
  236. get_select_list() {
  237. GetDataByName(this.getRecuListParm).then(response => {
  238. if (response.data.list !== null) {
  239. this.parentmenu = transData(response.data.list, 'id', 'parentid', 'children')
  240. }
  241. })
  242. GetDataByName({ name: 'getDepartmentsSelect', offset: 0, pagecount: 0, parammaps: {} }).then(response => {
  243. console.log("部门下拉框", response)
  244. this.departmentList = response.data.list
  245. })
  246. },
  247. refreshDownList() {
  248. for (var val of this.parentmenu) {
  249. this.parent = []
  250. this.parent.push({ id: val.id, title: val.title, parentid: val.parentid })
  251. }
  252. },
  253. resetRequestParam() {
  254. this.deptform.parentid = '0'
  255. this.deptform.departmentid = '0'
  256. this.deptform.ename = ''
  257. this.deptform.remark = ''
  258. this.deptform.sort = '0'
  259. this.deptform.telephone = ''
  260. this.deptform.id = ''
  261. this.deptform.enable = 1
  262. },
  263. form_add() {
  264. this.resetRequestParam()
  265. this.dialogStatus = 'create'
  266. this.parent = this.parentmenu
  267. this.dialogFormVisible = true
  268. this.$nextTick(() => {
  269. this.$refs['dataForm'].clearValidate()
  270. })
  271. },
  272. add_dialog_save() {
  273. this.$refs['dataForm'].validate((valid) => {
  274. if (valid) {
  275. this.requestParam.name = 'insertEmployees'
  276. if (this.deptform.parentid === '') this.deptform.parentid = '0'
  277. this.requestParam.parammaps = {
  278. id: '',
  279. ename: this.deptform.ename,
  280. telephone: this.deptform.telephone,
  281. remark: this.deptform.remark,
  282. sort: this.deptform.sort,
  283. departmentId: this.deptform.parentid,
  284. enable: this.deptform.enable
  285. }
  286. PostDataByName(this.requestParam).then((response) => {
  287. console.log('新增保存发送参数', this.requestParam)
  288. if (response.msg !== 'fail') {
  289. this.get_table_data()
  290. this.dialogFormVisible = false
  291. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  292. } else {
  293. this.$notify({ title: '失败', message: '保存失败', type: 'error', duration: 2000 })
  294. }
  295. })
  296. }
  297. })
  298. },
  299. form_edit(row) {
  300. this.parent = this.parentmenu
  301. console.log('row=====>', row)
  302. this.defaultCheckedKeys = [row.departmentid]
  303. console.log(this.defaultCheckedKeys)
  304. this.deptform.departmentid = row.departmentid
  305. this.deptform.parentid = row.departmentid
  306. this.deptform.ename = row.ename
  307. this.deptform.remark = row.remark
  308. this.deptform.sort = row.sort
  309. this.deptform.telephone = row.telephone
  310. this.deptform.id = row.id
  311. this.deptform.enable = row.enable
  312. this.dialogStatus = 'update'
  313. this.dialogFormVisible = true
  314. this.$nextTick(() => {
  315. this.$refs['dataForm'].clearValidate()
  316. })
  317. },
  318. form_edit_save() {
  319. this.$refs['dataForm'].validate((valid) => {
  320. if (valid) {
  321. this.requestParam.name = 'updateEmployees'
  322. this.requestParam.parammaps = {
  323. id: this.deptform.id,
  324. ename: this.deptform.ename,
  325. telephone: this.deptform.telephone,
  326. remark: this.deptform.remark,
  327. sort: this.deptform.sort,
  328. departmentId: this.deptform.parentid,
  329. enable: this.deptform.enable
  330. }
  331. console.log(this.requestParam)
  332. PostDataByName(this.requestParam).then((response) => {
  333. console.log('编辑保存发送参数', this.requestParam)
  334. if (response.msg !== 'fail') {
  335. this.get_table_data()
  336. this.dialogFormVisible = false
  337. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  338. } else {
  339. this.$notify({ title: '失败', message: '保存失败', type: 'error', duration: 2000 })
  340. }
  341. })
  342. }
  343. })
  344. },
  345. change_enable(index, row) {
  346. this.requestParam.name = 'updateEmployees'
  347. this.requestParam.parammaps = {
  348. id: row.id,
  349. ename: row.ename,
  350. telephone: row.telephone,
  351. remark: row.remark,
  352. sort: row.sort,
  353. departmentId: row.departmentid,
  354. enable: row.enable
  355. }
  356. PostDataByName(this.requestParam).then((response) => {
  357. console.log('编辑保存发送参数', this.requestParam)
  358. if (response.msg !== 'fail') {
  359. this.get_table_data()
  360. this.dialogFormVisible = false
  361. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  362. } else {
  363. this.$notify({ title: '失败', message: '保存失败', type: 'error', duration: 2000 })
  364. }
  365. })
  366. },
  367. handleDelete(row) {
  368. MessageBox.confirm('确认删除此信息?', {
  369. confirmButtonText: '确认',
  370. cancelButtonText: '取消',
  371. type: 'warning'
  372. }).then(() => {
  373. this.requestParam.name = 'delEmployees'
  374. this.requestParam.parammaps = {
  375. id: row.id,
  376. }
  377. PostDataByName(this.requestParam).then(() => {
  378. this.get_table_data()
  379. this.dialogFormVisible = false
  380. this.$notify({
  381. title: '成功',
  382. message: '删除成功',
  383. type: 'success',
  384. duration: 2000
  385. })
  386. })
  387. })
  388. }
  389. }
  390. }
  391. </script>
  392. <style lang="scss" scoped>
  393. .search {
  394. padding-top: 10px;
  395. clear: both;
  396. }
  397. .table {
  398. margin-top: 10px;
  399. }
  400. </style>