1300bea06b88461060abc6fbda96462144c653f4.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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" filterable 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" filterable 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: 30 + 'px', height: 30 + '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. isgroups: Cookies.get('ispastureuse')
  291. }}
  292. this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.dataform.selectedRole }}
  293. this.postDataPramas.data[1].children = []
  294. this.postDataPramas.data[1].children[0] = { 'name': 'insertUserRole', 'type': 'e', 'parammaps': {
  295. user_id: '@createUser.LastInsertId',
  296. role_id: '@insertSpotList.role_id'
  297. }}
  298. ExecDataByConfig(this.postDataPramas).then(response => {
  299. console.log('新增保存发送参数', this.postDataPramas)
  300. if (response.msg === 'fail') {
  301. var username = new RegExp('username')
  302. if (username.test(response.data)) {
  303. this.$notify({
  304. title: '',
  305. message: '该用户名称已存在',
  306. type: 'warning',
  307. duration: 2000
  308. })
  309. } else {
  310. this.$notify({
  311. title: '失败',
  312. message: response.data,
  313. type: 'warning',
  314. duration: 2000
  315. })
  316. }
  317. } else {
  318. this.dialogFormVisibleAdd = false
  319. this.getList()
  320. this.$notify({
  321. title: '',
  322. message: '保存成功',
  323. type: 'success',
  324. duration: 2000
  325. })
  326. }
  327. })
  328. }
  329. }
  330. })
  331. },
  332. handleRole(row) {
  333. this.requestParam.name = 'getRoleByUser'
  334. this.requestParam.params = []
  335. this.requestParam.params[0] = row.id
  336. this.requestParam.pagecount = 0
  337. this.requestParam.returntype = 'list'
  338. this.dataform.id = row.id
  339. this.dialogRoleVisible = true
  340. GetDataByName(this.requestParam).then(response => {
  341. this.selectedRole = response.data.lists.role_id
  342. })
  343. },
  344. updateRole() {
  345. this.UpdateDataRelationParam.name = 'user_role'
  346. this.UpdateDataRelationParam.dataname = 'user_id'
  347. this.UpdateDataRelationParam.datavalue = this.dataform.id
  348. this.UpdateDataRelationParam.valuename = 'role_id'
  349. this.UpdateDataRelationParam.values = this.selectedRole
  350. UpdateDataRelation(this.UpdateDataRelationParam).then(() => {
  351. this.dialogRoleVisible = false
  352. this.$notify({
  353. title: '成功',
  354. message: '修改成功',
  355. type: 'success',
  356. duration: 2000
  357. })
  358. this.getList()
  359. })
  360. },
  361. handleUpdate(row) {
  362. this.dataform.id = row.id
  363. this.dataform.username = row.username
  364. this.dataform.empid = row.empid
  365. this.dataform.sort = row.sort
  366. this.dataform.enable = row.enable
  367. this.dataform.empname = row.empname
  368. this.dataform.position = row.position
  369. this.dialogStatus = 'update'
  370. this.dialogFormVisible = true
  371. this.$nextTick(() => {
  372. this.$refs['dataForm'].clearValidate()
  373. })
  374. },
  375. updateData() {
  376. this.$refs['dataForm'].validate(valid => {
  377. if (valid) {
  378. this.requestParam.name = 'updateUser'
  379. this.requestParam.params = []
  380. this.requestParam.params[0] = this.dataform.username
  381. this.requestParam.params[1] = this.dataform.empid
  382. this.requestParam.params[2] = this.dataform.sort
  383. this.requestParam.params[3] = this.dataform.enable
  384. this.requestParam.params[4] = this.dataform.id
  385. PostDataByName(this.requestParam).then(() => {
  386. this.$nextTick(() => {
  387. this.getList()
  388. this.resetRequestParam()
  389. })
  390. this.dialogFormVisible = false
  391. })
  392. }
  393. })
  394. },
  395. handleEnableChange(index, row) {
  396. this.requestParam.name = 'updateUser'
  397. this.requestParam.params = []
  398. this.requestParam.params[0] = row.username
  399. this.requestParam.params[1] = row.empid
  400. this.requestParam.params[2] = row.sort
  401. this.requestParam.params[3] = row.enable
  402. this.requestParam.params[4] = row.id
  403. PostDataByName(this.requestParam).then(() => {
  404. this.$notify({
  405. title: '成功',
  406. message: '修改成功',
  407. type: 'success',
  408. duration: 2000
  409. })
  410. })
  411. },
  412. handleDelete(row) {
  413. MessageBox.confirm('确认删除?', {
  414. confirmButtonText: '确认',
  415. cancelButtonText: '取消',
  416. type: 'warning'
  417. }).then(() => {
  418. this.requestParam.name = 'deleteUser'
  419. this.requestParam.params = []
  420. this.requestParam.params[0] = row.id
  421. PostDataByName(this.requestParam).then(() => {
  422. this.getList()
  423. this.resetRequestParam()
  424. this.dialogFormVisible = false
  425. this.$notify({
  426. title: '成功',
  427. message: '删除成功',
  428. type: 'success',
  429. duration: 2000
  430. })
  431. })
  432. })
  433. },
  434. formNameSearch(queryString, cb) {
  435. this.requestFilterParams.name = 'userSolr'
  436. this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
  437. this.requestFilterParams.parammaps['empname'] = queryString
  438. GetDataByName(this.requestFilterParams).then(response => {
  439. cb(response.data.list)
  440. })
  441. },
  442. handleformNameSelect(item) {
  443. this.dataform.username = item.empCode
  444. this.dataform.empid = item.id
  445. this.$set(this.dataform, 'empname', item.empname)
  446. this.$set(this.dataform, 'position', item.position)
  447. // this.dataform.empname = item.empname
  448. // this.dataform.position = item.position
  449. }
  450. }
  451. }
  452. </script>