db8ecab45db2c1756a497dc2d9c6c23f97e53841.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.empCode" placeholder="用户名称" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.empname" placeholder="员工姓名" style="width: 180px;" class="filter-item" clearable />
  6. <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  7. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  8. </el-select>
  9. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  10. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  11. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  12. </div>
  13. <div class="operation">
  14. <el-button v-if="isRoleEdit" icon="el-icon-plus" class="success" @click="handleCreate">新增</el-button>
  15. <el-button v-if="isRoleEdit" icon="el-icon-delete" class="danger" @click="handleDelete">删除</el-button>
  16. </div>
  17. <div class="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. element-loading-text="给我一点时间"
  22. :data="table.list"
  23. border
  24. fit
  25. highlight-current-row
  26. style="width: 100%;"
  27. :row-style="rowStyle"
  28. :cell-style="cellStyle"
  29. class="elTable table-fixed"
  30. @selection-change="handleSelectionChange"
  31. >
  32. <el-table-column type="selection" align="center" width="50" />
  33. <el-table-column label="序号" align="center" type="index" width="50px">
  34. <template slot-scope="scope">
  35. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="用户名称" min-width="180px" align="center">
  39. <template slot-scope="scope">
  40. <span v-if="scope.row.NoEdit">{{ scope.row.username }}</span>
  41. <el-input v-if="scope.row.Edit" v-model.trim="scope.row.username" placeholder="建议使用手机号" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="员工姓名" min-width="130px" align="center">
  45. <template slot-scope="scope">
  46. <span v-if="scope.row.NoEdit">{{ scope.row.empname }}</span>
  47. <el-input v-if="scope.row.Edit" v-model.trim="scope.row.empname" placeholder="1-32字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="手机号" min-width="180px" align="center">
  51. <template slot-scope="scope">
  52. <span v-if="scope.row.NoEdit">{{ scope.row.phone }}</span>
  53. <el-input v-if="scope.row.Edit" v-model.trim="scope.row.phone" placeholder="请输入11位手机号" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="11" style="width:95%;padding:10px 0;" />
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="角色" min-width="150px" align="center">
  57. <template slot-scope="scope">
  58. <span v-if="scope.row.NoEdit">{{ scope.row.rolename }}</span>
  59. <el-select v-if="scope.row.Edit" v-model="scope.row.roleid" placeholder="角色" class="filter-item" style="width:90%;padding:10px 0;" filterable @change="changeRolename">
  60. <el-option v-for="item in roleList" :key="item.id" :label="item.rolename" :value="item.id" />
  61. </el-select>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="创建时间" min-width="110px" align="center">
  65. <template slot-scope="scope">
  66. <span>{{ scope.row.createdtime }}</span>
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="创建人" min-width="110px" align="center">
  70. <template slot-scope="scope">
  71. <span>{{ scope.row.createmp }}</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="是否启用" min-width="110px" align="center">
  75. <template slot-scope="scope">
  76. <el-switch v-model="scope.row.enable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width" fixed="right">
  80. <template slot-scope="{row}">
  81. <!-- 新增 -->
  82. <el-button v-if="row.isCreate && isRoleEdit" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData(row)" />
  83. <span v-if="row.isCreate && isRoleEdit" class="centerSpan">|</span>
  84. <el-button v-if="row.isCreate && isRoleEdit" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
  85. <!-- 重置密码 -->
  86. <a v-if="row.isUpdate && isRoleEdit" class="correcting" size="mini" style="width: 80px;" @click="handleResetPassword(row)">重置密码</a>
  87. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  88. <!-- 编辑 -->
  89. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  90. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  91. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  92. <!-- 编辑保存 -->
  93. <el-button v-if="row.isUpdateSave && isRoleEdit" :disabled="isokDisable" class="miniSuccess" icon="el-icon-folder-checked" @click="updateData(row)" />
  94. <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
  95. <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  100. </div>
  101. </div>
  102. </template>
  103. <script>
  104. import { GetDataByName, PostDataByName, failproccess, GetDataByNames, ExecDataByConfig, checkButtons } from '@/api/common'
  105. import Cookies from 'js-cookie'
  106. import { parseTime } from '@/utils/index.js'
  107. import { MessageBox } from 'element-ui'
  108. import Pagination from '@/components/Pagination'
  109. export default {
  110. name: 'User',
  111. components: { Pagination },
  112. data() {
  113. return {
  114. isRoleEdit: [],
  115. requestParams: [
  116. { name: 'getRoleAll', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }}
  117. ],
  118. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  119. roleList: [], // 角色
  120. table: {
  121. getdataListParm: {
  122. name: 'getuserallL',
  123. page: 1,
  124. offset: 1,
  125. pagecount: 10,
  126. returntype: 'Map',
  127. parammaps: {
  128. pastureid: Cookies.get('pastureid'),
  129. empCode: '',
  130. empname: '',
  131. enable: '',
  132. startTime: '',
  133. stopTime: '',
  134. inputDatetime: ''
  135. }
  136. },
  137. tableKey: 0,
  138. list: [],
  139. total: 0,
  140. listLoading: true,
  141. temp: {}
  142. },
  143. requestParam: {},
  144. isokDisable: false,
  145. selectList: [],
  146. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  147. cellStyle: { padding: 0 + 'px' }
  148. }
  149. },
  150. created() {
  151. this.getList()
  152. this.getDownList()
  153. this.getButtons()
  154. },
  155. methods: {
  156. getButtons() {
  157. const Edit = 'User'
  158. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  159. this.isRoleEdit = isRoleEdit
  160. },
  161. getDownList() {
  162. GetDataByNames(this.requestParams).then(response => {
  163. this.roleList = response.data.getRoleAll.list
  164. })
  165. },
  166. getList() {
  167. this.table.listLoading = true
  168. GetDataByName(this.table.getdataListParm).then(response => {
  169. console.log('table数据', response.data.list)
  170. if (response.data.list !== null) {
  171. for (let i = 0; i < response.data.list.length; i++) {
  172. this.$set(response.data.list[i], 'Edit', false) // 编辑
  173. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  174. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  175. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  176. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  177. }
  178. this.table.list = response.data.list
  179. this.table.pageNum = response.data.pageNum
  180. this.table.pageSize = response.data.pageSize
  181. this.table.total = response.data.total
  182. } else {
  183. this.table.list = []
  184. }
  185. setTimeout(() => {
  186. this.table.listLoading = false
  187. }, 100)
  188. })
  189. },
  190. handleEnableChange() {
  191. console.log('点击了是否启用')
  192. },
  193. handleSearch() {
  194. console.log('点击了查询')
  195. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  196. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  197. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  198. } else {
  199. this.table.getdataListParm.parammaps.inputDatetime = ''
  200. this.table.getdataListParm.parammaps.startTime = ''
  201. this.table.getdataListParm.parammaps.stopTime = ''
  202. }
  203. this.table.getdataListParm.offset = 1
  204. this.getList()
  205. },
  206. handleRefresh() {
  207. console.log('点击了重置')
  208. this.table.getdataListParm.parammaps.empCode = ''
  209. this.table.getdataListParm.parammaps.empname = ''
  210. this.table.getdataListParm.parammaps.enable = ''
  211. this.table.getdataListParm.parammaps.startTime = ''
  212. this.table.getdataListParm.parammaps.stopTime = ''
  213. this.table.getdataListParm.parammaps.inputDatetime = ''
  214. this.table.getdataListParm.offset = 1
  215. this.getList()
  216. },
  217. handleCreate() {
  218. // 编辑true/不可编辑false
  219. // 新增操true,编辑false,编辑保存false
  220. for (let i = 0; i < this.table.list.length; i++) {
  221. if (this.table.list[i].Edit === true) {
  222. console.log(123)
  223. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  224. return false
  225. }
  226. }
  227. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'createdtime': parseTime(new Date(), '{y}-{m}-{d}'), 'createmp': Cookies.get('employename'), 'username': '', 'roleid': '' })
  228. },
  229. changeRolename(item) {
  230. this.table.temp.rolename = this.roleList.find(obj => obj.id === item).rolename
  231. },
  232. createData(row) {
  233. console.log('点击了新增保存', row)
  234. this.table.temp.pastureid = Cookies.get('pastureid')
  235. this.table.temp.empname = row.empname
  236. this.table.temp.username = row.username
  237. this.table.temp.phone = row.phone
  238. this.table.temp.createmp = row.createmp
  239. this.table.temp.enable = row.enable
  240. this.table.temp.roleid = row.roleid
  241. // 检验用户名称/角色是否为空
  242. if (this.table.temp.username == '' && this.table.temp.roleid == '') {
  243. this.$message({ type: 'error', message: '用户名称/角色不能为空', duration: 2000 })
  244. return false
  245. } else if (this.table.temp.username == '') {
  246. this.$message({ type: 'error', message: '用户名称不能为空', duration: 2000 })
  247. return false
  248. } else if (this.table.temp.roleid == '') {
  249. this.$message({ type: 'error', message: '角色不能为空', duration: 2000 })
  250. return false
  251. }
  252. // 检验手机号是否为11位数字
  253. if (this.table.temp.phone !== undefined && this.table.temp.phone !== '') {
  254. const phone = /^\d{11}$/
  255. if (!phone.test(this.table.temp.phone)) {
  256. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  257. return false
  258. }
  259. }
  260. this.isokDisable = true
  261. setTimeout(() => {
  262. this.isokDisable = false
  263. }, 1000)
  264. this.requestParam.name = 'createUser'
  265. this.table.temp.isgroups = Cookies.get('ispastureuse')
  266. this.requestParam.parammaps = this.table.temp
  267. PostDataByName(this.requestParam).then(response => {
  268. console.log('新增保存发送参数', this.requestParam)
  269. if (response.msg !== 'fail') {
  270. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  271. this.getList()
  272. } else {
  273. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  274. }
  275. })
  276. },
  277. createCancel(row) {
  278. console.log('点击了新增取消')
  279. for (let i = 0; i < this.table.list.length; i++) {
  280. if (row.myId === this.table.list[i].myId) {
  281. var listIndex = this.table.list.indexOf(this.table.list[i])
  282. }
  283. if (listIndex > -1) {
  284. this.table.list.splice(listIndex, 1)
  285. return
  286. }
  287. }
  288. },
  289. handleUpdate(row) {
  290. for (let i = 0; i < this.table.list.length; i++) {
  291. if (this.table.list[i].Edit == true) {
  292. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  293. return false
  294. }
  295. }
  296. // 编辑true,不可编辑false
  297. row.Edit = true
  298. row.NoEdit = false
  299. // 新增false,编辑false,编辑保存true
  300. row.isCreate = false
  301. row.isUpdate = false
  302. row.isUpdateSave = true
  303. row.roleid = String(row.roleid)
  304. this.table.temp.roleid = row.roleid
  305. this.table.temp.rolename = row.rolename
  306. },
  307. updateData(row) {
  308. console.log('点击了编辑保存', row)
  309. this.table.temp.pastureid = row.pastureid
  310. this.table.temp.empname = row.empname
  311. this.table.temp.username = row.username
  312. this.table.temp.phone = row.phone
  313. this.table.temp.createmp = row.createmp
  314. this.table.temp.enable = row.enable
  315. this.table.temp.roleid = row.roleid
  316. this.table.temp.id = row.id
  317. // 校验用户名称/角色是否为空
  318. if (this.table.temp.username == '' && this.table.temp.roleid == '') {
  319. this.$message({ type: 'error', message: '用户名称/角色不能为空', duration: 2000 })
  320. return false
  321. } else if (this.table.temp.username == '') {
  322. this.$message({ type: 'error', message: '用户名称不能为空', duration: 2000 })
  323. return false
  324. } else if (this.table.temp.roleid == '') {
  325. this.$message({ type: 'error', message: '角色不能为空', duration: 2000 })
  326. return false
  327. }
  328. console.log(this.table.temp.phone)
  329. // 检验手机号是否为11位数字
  330. if (this.table.temp.phone !== undefined && this.table.temp.phone !== '') {
  331. const phone = /^\d{11}$/
  332. if (!phone.test(this.table.temp.phone)) {
  333. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  334. return false
  335. }
  336. }
  337. this.isokDisable = true
  338. setTimeout(() => {
  339. this.isokDisable = false
  340. }, 1000)
  341. this.requestParam.name = 'updateUser'
  342. this.requestParam.parammaps = this.table.temp
  343. PostDataByName(this.requestParam).then(response => {
  344. console.log('新增保存发送参数', this.requestParam)
  345. if (response.msg !== 'fail') {
  346. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  347. this.getList()
  348. } else {
  349. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  350. }
  351. })
  352. },
  353. updateCancel(row) {
  354. console.log('点击了编辑取消')
  355. // 编辑false,不可编辑true
  356. row.Edit = false
  357. row.NoEdit = true
  358. // 新增false,编辑true,编辑保存false
  359. row.isCreate = false
  360. row.isUpdate = true
  361. row.isUpdateSave = false
  362. this.getList()
  363. },
  364. handleRowDelete(row) {
  365. console.log('点击了行内删除')
  366. MessageBox.confirm('是否确认删除此信息?', {
  367. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  368. }).then(() => {
  369. this.selectList = []
  370. this.requestParam.name = 'deleteUser'
  371. this.requestParam.parammaps = {}
  372. this.requestParam.parammaps.pastureid = row.pastureid
  373. this.requestParam.parammaps.id = row.id
  374. PostDataByName(this.requestParam).then(response => {
  375. if (response.msg === 'fail') {
  376. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  377. } else {
  378. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  379. this.getList()
  380. }
  381. })
  382. }).catch(() => {
  383. this.$message({ type: 'info', message: '已取消删除' })
  384. })
  385. },
  386. handleSelectionChange(val) {
  387. console.log('勾选数据', val)
  388. this.selectList = val
  389. },
  390. handleDelete() {
  391. console.log('点击了删除')
  392. if (this.selectList.length == 0) {
  393. this.$message({ type: 'error', message: '请选择用户信息', duration: 2000 })
  394. } else {
  395. MessageBox.confirm('是否确认删除此信息?', {
  396. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  397. }).then(() => {
  398. console.log(this.selectList)
  399. this.requestParam.common = { 'returnmap': '0' }
  400. this.requestParam.data = []
  401. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  402. this.requestParam.data[0].children = []
  403. this.requestParam.data[0].children[0] = { 'name': 'deleteUser', 'type': 'e', 'parammaps': {
  404. id: '@insertSpotList.id',
  405. pastureid: '@insertSpotList.pastureid'
  406. }}
  407. ExecDataByConfig(this.requestParam).then(response => {
  408. console.log('删除保存发送参数', this.requestParam)
  409. if (response.msg === 'fail') {
  410. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  411. } else {
  412. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  413. this.getList()
  414. }
  415. })
  416. })
  417. }
  418. },
  419. handleResetPassword(row) {
  420. MessageBox.confirm('是否确认将此用户密码重置为默认密码123456?', {
  421. confirmButtonText: '确认',
  422. cancelButtonText: '取消',
  423. type: 'warning'
  424. }).then(() => {
  425. this.requestParam.name = 'initPassword'
  426. this.requestParam.parammaps = {}
  427. this.requestParam.parammaps.pastureid = row.pastureid
  428. this.requestParam.parammaps.id = row.id
  429. PostDataByName(this.requestParam).then(() => {
  430. this.getList()
  431. this.resetRequestParam()
  432. this.dialogFormVisible = false
  433. this.$notify({
  434. title: '成功',
  435. message: '重置密码成功',
  436. type: 'success',
  437. duration: 2000
  438. })
  439. })
  440. })
  441. }
  442. }
  443. }
  444. </script>
  445. <style lang="scss" scoped>
  446. .search{margin-top:10px;}
  447. .table{margin-top:10px;}
  448. </style>