employee.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <!-- 员工管理 -->
  3. <div>
  4. <actionBar menuTitle="员工管理" :operateList="operateList" :formList="formList" :ruleForm="searchRuleForm"
  5. @openModel="openModel" @searchProtocol="searchProtocol"></actionBar>
  6. <tables :key="Math.random()" :suspension="true" :tableList="tableList" :tableData="tableData"
  7. @buttonData="buttonData"></tables>
  8. <!-- 分页 -->
  9. <div class="paging_bottom" v-if="Total">
  10. <pagination :total="Total" :currentPage="Pagination.PageIndex" @changeSize="changeSize"
  11. @changeCurrent="changeCurrent">
  12. </pagination>
  13. </div>
  14. <el-dialog :title="staffTitle" :visible.sync="staffDialogVisible" width="60%" :close-on-click-modal="false"
  15. @close="closeDialog">
  16. <form-employee ref="outlet" :staffDialogVisible="staffDialogVisible" :ruleForm="ruleForm" :menuData="menuData"
  17. :operationType="operationType" :forbid="forbid"></form-employee>
  18. <span slot="footer" class="dialog-footer" v-if="operationType == 'add' || operationType == 'edit'">
  19. <el-button plain @click="staffDialogVisible = false">取 消</el-button>
  20. <el-button type="primary" :loading="fillingLoading" @click="postgres">确 定</el-button>
  21. </span>
  22. </el-dialog>
  23. </div>
  24. </template>
  25. <script>
  26. import {
  27. getUser,
  28. getUserDetails,
  29. addUser,
  30. putUser,
  31. putResetUser,
  32. delUser
  33. } from '@/api/user'
  34. import {
  35. getRole
  36. } from '@/api/power'
  37. import actionBar from '@/components/actionBar'
  38. import tables from '@/components/tables'
  39. import pagination from '@/components/pagination'
  40. import formEmployee from '@/components/formEmployee'
  41. import {
  42. employee
  43. } from "./shopTable.js";
  44. export default {
  45. components: {
  46. actionBar,
  47. tables,
  48. pagination,
  49. formEmployee
  50. },
  51. data() {
  52. return {
  53. staffTitle: '添加',
  54. staffDialogVisible: false,
  55. Pagination: {
  56. PageIndex: 1,
  57. PageSize: 10,
  58. },
  59. formList: [{
  60. type: 'input',
  61. label: '用户编码',
  62. field: 'uuid',
  63. placeholder: '用户编码',
  64. }, {
  65. type: 'input',
  66. label: '登录账号',
  67. field: 'username',
  68. placeholder: '登录账号',
  69. }, {
  70. type: 'input',
  71. label: '姓名',
  72. field: 'name',
  73. placeholder: '姓名',
  74. }],
  75. searchRuleForm: {
  76. uuid: '',
  77. username: '',
  78. name: '',
  79. },
  80. operateList: [{
  81. type: 'add',
  82. title: '添加',
  83. icon: 'el-icon-plus',
  84. }],
  85. tableList: employee(),
  86. tableData: [],
  87. Total: 0,
  88. operationType: '',
  89. userinfo: {},
  90. ruleForm: {
  91. username: '',
  92. password: '',
  93. roleId: null,
  94. provUser: {
  95. name: '',
  96. idCard: '',
  97. no: '',
  98. phone: '',
  99. userType: null,
  100. isorders: 0,
  101. hireStatus: '',
  102. hireTime: '',
  103. education: '',
  104. jobCategory: '',
  105. personQual: '',
  106. description: '',
  107. },
  108. provTruck: {
  109. certificateNo: '',
  110. type: 1,
  111. issueAuthority: '',
  112. issueTime: '',
  113. firstIssueTime: '',
  114. expireTime: '',
  115. remarks: '',
  116. }
  117. },
  118. menuData: [],
  119. fillingLoading: false,
  120. searchValue: {},
  121. forbid: false,
  122. }
  123. },
  124. mounted() {
  125. this.getList()
  126. },
  127. methods: {
  128. // 搜索
  129. searchProtocol(value) {
  130. this.searchValue = value
  131. this.getList()
  132. },
  133. // 获取用户列表
  134. getList() {
  135. var params = {
  136. page: this.Pagination.PageIndex,
  137. pageSize: this.Pagination.PageSize,
  138. ...this.searchValue
  139. }
  140. getUser(params).then(res => {
  141. if (res.code == 200) {
  142. this.tableData = res.data.list
  143. this.Total = res.data.count
  144. }
  145. })
  146. },
  147. // 获取所有权限角色
  148. getRoleList() {
  149. getRole().then(res => {
  150. if (res.code == 200) {
  151. this.menuData = res.data.list
  152. }
  153. })
  154. },
  155. // 添加用户
  156. postgres() {
  157. let flag = this.$refs['outlet'].validateForm();
  158. if (flag) {
  159. const arrList = JSON.parse(JSON.stringify(this.ruleForm))
  160. if (arrList.provUser.userType == 3) {
  161. arrList.provStoreUserBindCertificate = arrList.provTruck
  162. delete arrList.provTruck
  163. } else if (arrList.provUser.userType == 4) {
  164. arrList.provTruckUserBindCertificate = arrList.provTruck
  165. delete arrList.provTruck
  166. } else if (arrList.provUser.userType == 5) {
  167. delete arrList.provTruck
  168. }
  169. if (this.operationType == 'add') {
  170. this.addUsers(arrList)
  171. } else if (this.operationType == 'edit') {
  172. arrList.id = this.userinfo.id
  173. this.modifyUser(arrList)
  174. }
  175. // console.log(arrList, 26)
  176. }
  177. },
  178. // 添加用户
  179. addUsers(params) {
  180. this.fillingLoading = true
  181. addUser(params).then(res => {
  182. if (res.code == 200) {
  183. this.$message({
  184. message: res.msg,
  185. type: 'success'
  186. });
  187. this.getList()
  188. // 清空表单内容
  189. this.$refs.outlet.clearForm();
  190. this.staffDialogVisible = false
  191. }
  192. this.fillingLoading = false
  193. }).catch(() => {
  194. this.fillingLoading = false
  195. })
  196. },
  197. // 修改用户信息
  198. modifyUser(params) {
  199. this.fillingLoading = true
  200. putUser(params).then(res => {
  201. if (res.code == 200) {
  202. this.$message({
  203. message: res.msg,
  204. type: 'success'
  205. });
  206. this.getList()
  207. // 清空表单内容
  208. this.$refs.outlet.clearForm();
  209. this.staffDialogVisible = false
  210. }
  211. this.fillingLoading = false
  212. }).catch(() => {
  213. this.fillingLoading = false
  214. })
  215. },
  216. // 右侧按钮
  217. openModel(type) {
  218. this.forbid = false
  219. this.operationType = type
  220. if (type == 'add') {
  221. this.getRoleList()
  222. this.staffTitle = '添加'
  223. }
  224. this.staffDialogVisible = true
  225. },
  226. buttonData(row, type) {
  227. this.forbid = false
  228. // console.log(row,type,667)
  229. this.getRoleList()
  230. this.userinfo = row
  231. this.operationType = type
  232. if (type == 'edit') {
  233. this.staffTitle = '编辑'
  234. this.$nextTick(() => {
  235. this.assignment(row)
  236. })
  237. this.staffDialogVisible = true
  238. } else if (type == 'logs') {
  239. this.forbid = true
  240. this.staffTitle = '详情'
  241. this.$nextTick(() => {
  242. this.assignment(row)
  243. })
  244. this.staffDialogVisible = true
  245. } else if (type == 'del') {
  246. this.deleteUser(row.id)
  247. } else if (type == 'reset') {
  248. this.resetPasswords()
  249. }
  250. },
  251. // 删除用户
  252. deleteUser(id) {
  253. this.$confirm('此操作将永久删除用户, 是否继续?', '提示', {
  254. confirmButtonText: '确定',
  255. cancelButtonText: '取消',
  256. type: 'warning'
  257. }).then(() => {
  258. delUser({
  259. id: id,
  260. }).then(res => {
  261. if (res.code == 200) {
  262. this.$message({
  263. message: '操作成功',
  264. type: 'success'
  265. });
  266. this.getList()
  267. }
  268. })
  269. }).catch(() => {});
  270. },
  271. // 重置密码
  272. resetPasswords() {
  273. this.$prompt('请输入新密码', '重置密码', {
  274. confirmButtonText: '确定',
  275. cancelButtonText: '取消',
  276. }).then(({
  277. value
  278. }) => {
  279. putResetUser({
  280. id: this.userinfo.id,
  281. password: value
  282. }).then(res => {
  283. if (res.code == 200) {
  284. this.$message({
  285. type: 'success',
  286. message: '重置成功'
  287. });
  288. }
  289. })
  290. }).catch(() => {});
  291. },
  292. // 编辑赋值
  293. assignment(value) {
  294. const arr = JSON.parse(JSON.stringify(value))
  295. this.ruleForm.username = arr.username
  296. this.ruleForm.roleId = arr.roleId
  297. if (arr.provUser.userType == 3) {
  298. delete arr.provUser.userId
  299. delete arr.provStoreUserBindCertificate.userId
  300. this.ruleForm.provUser = arr.provUser
  301. this.ruleForm.provTruck = arr.provStoreUserBindCertificate
  302. } else if (arr.provUser.userType == 4) {
  303. delete arr.provUser.userId
  304. delete arr.provTruckUserBindCertificate.userId
  305. this.ruleForm.provUser = arr.provUser
  306. this.ruleForm.provTruck = arr.provTruckUserBindCertificate
  307. } else if (arr.provUser.userType == 5) {
  308. delete arr.provUser.userId
  309. this.ruleForm.provUser = arr.provUser
  310. }
  311. },
  312. changeSize(val) {
  313. this.Pagination.PageSize = val
  314. this.getList()
  315. },
  316. changeCurrent(val) {
  317. this.Pagination.PageIndex = val
  318. this.getList()
  319. },
  320. // 清空表单
  321. closeDialog() {
  322. this.$nextTick(() => {
  323. this.ruleForm.provUser.cmpCode = ''
  324. this.ruleForm.provUser.description = ''
  325. this.ruleForm.provUser.personQual = ''
  326. this.ruleForm.provTruck.certificateNo = ''
  327. this.ruleForm.provTruck.issueAuthority = ''
  328. this.ruleForm.provTruck.issueTime = ''
  329. this.ruleForm.provTruck.firstIssueTime = ''
  330. this.ruleForm.provTruck.expireTime = ''
  331. this.ruleForm.provTruck.remarks = ''
  332. this.ruleForm.provTruck.imgUrl = ''
  333. this.$refs.outlet.clearForm();
  334. })
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="scss" scoped>
  340. </style>