a43f55bb014dddf340da484abe8326484884d24c.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <div class="app-container">
  3. <div class="app-container">
  4. <div class="filter-container">
  5. <el-input v-model="getdataListParm.parammaps.empCode" placeholder="用户名" style="width: 140px;" class="filter-item" />
  6. <el-input v-model="getdataListParm.parammaps.empname" placeholder="姓名" style="width: 140px;" class="filter-item" />
  7. <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
  8. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate"> 新增 </el-button>
  9. </div>
  10. <el-table
  11. v-loading="listLoading"
  12. element-loading-text="给我一点时间"
  13. :data="list"
  14. border
  15. fit
  16. highlight-current-row
  17. style="width: 100%;"
  18. :row-style="rowStyle"
  19. :cell-style="cellStyle"
  20. class="elTable"
  21. row-key="id"
  22. default-expand-all
  23. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  24. >
  25. <el-table-column label="用户名称" header-align="center" width="120px" align="center">
  26. <template slot-scope="scope">
  27. <span>{{ scope.row.username }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="姓名" min-width="120px" header-align="center" align="center">
  31. <template slot-scope="scope">
  32. <span>{{ scope.row.empname }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="部门" min-width="120px" header-align="center" align="center">
  36. <template slot-scope="scope">
  37. <span>{{ scope.row.deptname }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="角色" min-width="120px" header-align="center" align="center">
  41. <template slot-scope="scope">
  42. <span>{{ scope.row.roleName }}</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="顺序" min-width="80px" header-align="center" align="center">
  46. <template slot-scope="scope">
  47. <span>{{ scope.row.sort }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  51. <template slot-scope="scope">
  52. <el-switch v-model="scope.row.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">
  56. <template slot-scope="{row}">
  57. <el-button type="warning" size="mini" @click="handleRole(row)"> 角色 </el-button>
  58. <el-button type="primary" size="mini" @click="handleUpdate(row)"> 编辑 </el-button>
  59. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)"> 删除 </el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <pagination v-show="total>=0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
  64. <!-- 编辑 -->
  65. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  66. <el-form ref="dataForm" :rules="rules" :model="dataform" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  67. <el-form-item label="职工名" prop="empid">
  68. <el-autocomplete ref="empid" v-model="dataform.empname" value-key="empid" class="inline-input" :fetch-suggestions="formNameSearch" placeholder="请输入内容" style="width:80%" @select="handleformNameSelect">
  69. <template slot-scope="{ item }">
  70. <div class="name" style="display: inline;">姓名: {{ item.empname }}</div>
  71. <span class="addr"> 职位:{{ item.position }}</span>
  72. </template>
  73. </el-autocomplete>
  74. </el-form-item>
  75. <el-form-item label="用户名" prop="username">
  76. <el-input ref="username" v-model="dataform.username" />
  77. </el-form-item>
  78. <el-form-item label="顺序" prop="sort">
  79. <el-input ref="sort" v-model="dataform.sort" />
  80. </el-form-item>
  81. <el-form-item label="启用" prop="enable">
  82. <el-switch ref="enable" v-model="dataform.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer" class="dialog-footer">
  86. <el-button type="primary" @click="updateData()"> 确认 </el-button>
  87. <el-button @click="dialogFormVisible = false"> 关闭 </el-button>
  88. </div>
  89. </el-dialog>
  90. <!-- 新增 -->
  91. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisibleAdd" :close-on-click-modal="false">
  92. <el-form ref="dataForm" :rules="rules" :model="dataform" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  93. <el-form-item label="职工名" prop="empid">
  94. <el-autocomplete ref="empid" v-model="dataform.empname" value-key="empid" class="inline-input" :fetch-suggestions="formNameSearch" placeholder="请输入内容" style="width:100%" @select="handleformNameSelect">
  95. <template slot-scope="{ item }">
  96. <div class="name" style="display: inline;">姓名: {{ item.empname }}</div>
  97. <span class="addr"> 职位:{{ item.position }}</span>
  98. </template>
  99. </el-autocomplete>
  100. </el-form-item>
  101. <el-form-item label="用户名" prop="username">
  102. <el-input ref="username" v-model="dataform.username" />
  103. </el-form-item>
  104. <el-form-item label="角色" prop="rolename">
  105. <el-select v-model="dataform.selectedRole" style="width:500px;" multiple placeholder="请选择">
  106. <el-option v-for="item in rolelist" :key="item.id" :label="item.name" :value="item.id" />
  107. </el-select>
  108. </el-form-item>
  109. <el-form-item label="启用" prop="enable">
  110. <el-switch ref="enable" v-model="dataform.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  111. </el-form-item>
  112. </el-form>
  113. <div slot="footer" class="dialog-footer">
  114. <el-button type="primary" @click="createData()"> 确认 </el-button>
  115. <el-button @click="dialogFormVisibleAdd = false"> 关闭 </el-button>
  116. </div>
  117. </el-dialog>
  118. <!-- 角色 -->
  119. <el-dialog :title="textMap['role']" :visible.sync="dialogRoleVisible" :close-on-click-modal="false">
  120. <el-form :rules="rules" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  121. <el-form-item label="角色" prop="rolename">
  122. <el-select v-model="selectedRole" style="width:500px;" multiple placeholder="请选择">
  123. <el-option v-for="item in rolelist" :key="item.id" :label="item.name" :value="item.id" />
  124. </el-select>
  125. </el-form-item>
  126. </el-form>
  127. <div slot="footer" class="dialog-footer">
  128. <el-button type="primary" @click="updateRole()"> 确认 </el-button>
  129. <el-button @click="dialogRoleVisible = false"> 关闭 </el-button>
  130. </div>
  131. </el-dialog>
  132. </div>
  133. </div>
  134. </template>
  135. <script>
  136. import waves from '@/directive/waves' // waves directive
  137. import { isIntegerZero } from '@/utils/validate'
  138. import { PostDataByName, GetDataByName, GetDataByNames, UpdateDataRelation, ExecDataByConfig } from '@/api/common'
  139. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  140. import { MessageBox } from 'element-ui'
  141. import Cookies from 'js-cookie'
  142. export default {
  143. name: 'User',
  144. components: { Pagination },
  145. directives: { waves },
  146. data() {
  147. return {
  148. tableKey: 0,
  149. list: [{ sqlname: '', id: 0, sqlstr: '' }],
  150. total: 0,
  151. listLoading: true,
  152. requestParam: {
  153. name: 'createapisql',
  154. offset: 0,
  155. pagecount: 0,
  156. params: []
  157. },
  158. requestParams: [
  159. { name: 'getRoleall', offset: 0, pagecount: 0, parammaps: { pastureId: Cookies.get('pastureid') }},
  160. { name: 'getEmpall', offset: 0, pagecount: 0, params: [] }
  161. ],
  162. requestFilterParams: {
  163. returntype: 'Map',
  164. parammaps: {}
  165. },
  166. UpdateDataRelationParam: {
  167. name: '',
  168. dataname: '',
  169. datavalue: '',
  170. valuename: '',
  171. values: []
  172. },
  173. dataform: {
  174. empname: '',
  175. position: '',
  176. username: '',
  177. fullname: '',
  178. empid: '',
  179. id: '',
  180. sort: '',
  181. enable: 1,
  182. selectedRole: ''
  183. },
  184. temp1: {
  185. empname: '',
  186. empid: '',
  187. position: ''
  188. },
  189. rolelist: [],
  190. emplist: [],
  191. getdataListParm: {
  192. name: 'getuserallL',
  193. offset: 1,
  194. pagecount: 10,
  195. returntype: 'Map',
  196. parammaps: {
  197. pastureId: Cookies.get('pastureid'),
  198. empCode: '',
  199. empname: ''
  200. }
  201. },
  202. rules: {
  203. empid: [{ required: true, message: '用户名必填', trigger: 'blur' }],
  204. username: [{ type: 'string', required: true, message: '用户名必填', trigger: 'change' }],
  205. empname: [{ type: 'string', required: true, message: '职工名必填', trigger: 'change' }],
  206. // rolename: [{ required: true, message: '角色必填', trigger: 'blur' }],
  207. sort: [{ validator: isIntegerZero, trigger: 'blur' }]
  208. },
  209. dialogFormVisible: false,
  210. dialogRoleVisible: false,
  211. selectedRole: '',
  212. dialogStatus: '',
  213. textMap: {
  214. update: '编辑',
  215. create: '新增',
  216. role: '选择角色'
  217. },
  218. dialogFormVisibleAdd: false,
  219. postDataPramas: {},
  220. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  221. cellStyle: { padding: 0 + 'px' }
  222. }
  223. },
  224. created() {
  225. this.getList()
  226. },
  227. methods: {
  228. deptenter() {
  229. this.$nextTick(() => {
  230. this.$refs['remark'].focus()
  231. })
  232. },
  233. getList() {
  234. this.listLoading = true
  235. GetDataByNames(this.requestParams).then(response => {
  236. this.rolelist = response.data.getRoleall.list
  237. this.emplist = response.data.getEmpall.list
  238. GetDataByName(this.getdataListParm).then(response => {
  239. this.list = response.data.list
  240. this.total = response.data.total
  241. setTimeout(() => {
  242. this.listLoading = false
  243. }, 0.5 * 1000)
  244. })
  245. })
  246. },
  247. handleFilter() {
  248. this.listLoading = true
  249. this.getdataListParm.offset = 1
  250. this.getList()
  251. },
  252. resetRequestParam() {
  253. this.dataform.username = ''
  254. this.dataform.fullname = ''
  255. this.dataform.empid = ''
  256. this.dataform.id = ''
  257. this.dataform.empname = ''
  258. this.dataform.position = ''
  259. this.dataform.sort = '0'
  260. this.dataform.enable = 1
  261. this.dataform.selectedRole = ''
  262. },
  263. handleCreate() {
  264. this.resetRequestParam()
  265. this.dialogStatus = 'create'
  266. this.dialogFormVisibleAdd = true
  267. },
  268. createData() {
  269. var role_Array = []
  270. for (let i = 0; i < this.dataform.selectedRole.length; i++) {
  271. var role_obj = {}
  272. this.$set(role_obj, 'role_id', this.dataform.selectedRole[i])
  273. role_Array.push(role_obj)
  274. }
  275. this.dataform.selectedRole = role_Array
  276. console.log(this.dataform)
  277. this.$refs['dataForm'].validate(valid => {
  278. if (valid) {
  279. if (this.dataform.selectedRole.length <= 0) {
  280. this.$message({ type: 'warning', message: '请检查角色是否未填写', duration: 2000 })
  281. return false
  282. } else {
  283. this.postDataPramas.common = { 'returnmap': '0' }
  284. this.postDataPramas.data = []
  285. this.postDataPramas.data[0] = { 'name': 'createUser', 'type': 'e', 'parammaps': {
  286. username: this.dataform.username,
  287. empid: this.dataform.empid,
  288. sort: '0',
  289. enable: this.dataform.enable
  290. }}
  291. this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.dataform.selectedRole }}
  292. this.postDataPramas.data[1].children = []
  293. this.postDataPramas.data[1].children[0] = { 'name': 'insertUserRole', 'type': 'e', 'parammaps': {
  294. user_id: '@createUser.LastInsertId',
  295. role_id: '@insertSpotList.role_id'
  296. }}
  297. ExecDataByConfig(this.postDataPramas).then(response => {
  298. console.log('新增保存发送参数', this.postDataPramas)
  299. if (response.msg === 'fail') {
  300. var username = new RegExp('username')
  301. if (username.test(response.data)) {
  302. this.$notify({
  303. title: '',
  304. message: '该用户名称已存在',
  305. type: 'warning',
  306. duration: 2000
  307. })
  308. } else {
  309. this.$notify({
  310. title: '失败',
  311. message: response.data,
  312. type: 'warning',
  313. duration: 2000
  314. })
  315. }
  316. } else {
  317. this.dialogFormVisibleAdd = false
  318. this.getList()
  319. this.$notify({
  320. title: '',
  321. message: '保存成功',
  322. type: 'success',
  323. duration: 2000
  324. })
  325. }
  326. })
  327. }
  328. }
  329. })
  330. },
  331. createData_again() {
  332. this.$refs['dataForm'].validate(valid => {
  333. if (valid) {
  334. this.requestParam.name = 'createUser'
  335. this.requestParam.params = []
  336. this.requestParam.params[0] = this.dataform.username
  337. this.requestParam.params[1] = this.dataform.empid
  338. this.requestParam.params[2] = this.dataform.sort
  339. this.requestParam.params[3] = this.dataform.enable
  340. PostDataByName(this.requestParam).then(response => {
  341. if (response.msg !== 'fail') {
  342. this.getList()
  343. this.resetRequestParam()
  344. this.$notify({
  345. title: '成功',
  346. message: '新增成功',
  347. type: 'success',
  348. duration: 2000
  349. })
  350. } else {
  351. var username = new RegExp('username')
  352. if (username.test(response.data)) {
  353. this.$notify({
  354. title: '',
  355. message: '该用户名称已存在',
  356. type: 'warning',
  357. duration: 2000
  358. })
  359. } else {
  360. this.$notify({
  361. title: '失败',
  362. message: response.data,
  363. type: 'warning',
  364. duration: 2000
  365. })
  366. }
  367. }
  368. })
  369. }
  370. })
  371. },
  372. handleRole(row) {
  373. this.requestParam.name = 'getRoleByUser'
  374. this.requestParam.params = []
  375. this.requestParam.params[0] = row.id
  376. this.requestParam.pagecount = 0
  377. this.requestParam.returntype = 'list'
  378. this.dataform.id = row.id
  379. this.dialogRoleVisible = true
  380. GetDataByName(this.requestParam).then(response => {
  381. this.selectedRole = response.data.lists.role_id
  382. })
  383. },
  384. updateRole() {
  385. this.UpdateDataRelationParam.name = 'user_role'
  386. this.UpdateDataRelationParam.dataname = 'user_id'
  387. this.UpdateDataRelationParam.datavalue = this.dataform.id
  388. this.UpdateDataRelationParam.valuename = 'role_id'
  389. this.UpdateDataRelationParam.values = this.selectedRole
  390. UpdateDataRelation(this.UpdateDataRelationParam).then(() => {
  391. this.dialogRoleVisible = false
  392. this.$notify({
  393. title: '成功',
  394. message: '修改成功',
  395. type: 'success',
  396. duration: 2000
  397. })
  398. this.getList()
  399. })
  400. },
  401. handleUpdate(row) {
  402. this.dataform.id = row.id
  403. this.dataform.username = row.username
  404. this.dataform.empid = row.empid
  405. this.dataform.sort = row.sort
  406. this.dataform.enable = row.enable
  407. this.dataform.empname = row.empname
  408. this.dataform.position = row.position
  409. this.dialogStatus = 'update'
  410. this.dialogFormVisible = true
  411. this.$nextTick(() => {
  412. this.$refs['dataForm'].clearValidate()
  413. })
  414. },
  415. updateData() {
  416. this.$refs['dataForm'].validate(valid => {
  417. if (valid) {
  418. this.requestParam.name = 'updateUser'
  419. this.requestParam.params = []
  420. this.requestParam.params[0] = this.dataform.username
  421. this.requestParam.params[1] = this.dataform.empid
  422. this.requestParam.params[2] = this.dataform.sort
  423. this.requestParam.params[3] = this.dataform.enable
  424. this.requestParam.params[4] = this.dataform.id
  425. PostDataByName(this.requestParam).then(() => {
  426. this.$nextTick(() => {
  427. this.getList()
  428. this.resetRequestParam()
  429. })
  430. this.dialogFormVisible = false
  431. })
  432. }
  433. })
  434. },
  435. handleEnableChange(index, row) {
  436. this.requestParam.name = 'updateUser'
  437. this.requestParam.params = []
  438. this.requestParam.params[0] = row.username
  439. this.requestParam.params[1] = row.empid
  440. this.requestParam.params[2] = row.sort
  441. this.requestParam.params[3] = row.enable
  442. this.requestParam.params[4] = row.id
  443. PostDataByName(this.requestParam).then(() => {
  444. this.$notify({
  445. title: '成功',
  446. message: '修改成功',
  447. type: 'success',
  448. duration: 2000
  449. })
  450. })
  451. },
  452. handleDelete(row) {
  453. MessageBox.confirm('确认删除?', {
  454. confirmButtonText: '确认',
  455. cancelButtonText: '取消',
  456. type: 'warning'
  457. }).then(() => {
  458. this.requestParam.name = 'deleteUser'
  459. this.requestParam.params = []
  460. this.requestParam.params[0] = row.id
  461. PostDataByName(this.requestParam).then(() => {
  462. this.getList()
  463. this.resetRequestParam()
  464. this.dialogFormVisible = false
  465. this.$notify({
  466. title: '成功',
  467. message: '删除成功',
  468. type: 'success',
  469. duration: 2000
  470. })
  471. })
  472. })
  473. },
  474. formNameSearch(queryString, cb) {
  475. this.requestFilterParams.name = 'userSolr'
  476. this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
  477. this.requestFilterParams.parammaps['empname'] = queryString
  478. GetDataByName(this.requestFilterParams).then(response => {
  479. cb(response.data.list)
  480. })
  481. },
  482. handleformNameSelect(item) {
  483. this.dataform.username = item.empCode
  484. this.dataform.empid = item.id
  485. this.$set(this.dataform, 'empname', item.empname)
  486. this.$set(this.dataform, 'position', item.position)
  487. // this.dataform.empname = item.empname
  488. // this.dataform.position = item.position
  489. }
  490. }
  491. }
  492. </script>