bd09b4d01bb02d9a440b0d22c991021db60aa812.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button class="success" @click="handleCreate">新增</el-button>
  5. <el-button class="danger" @click="handleDelete">删除</el-button>
  6. </div>
  7. <div class="search">
  8. <el-input v-model="table.getdataListParm.parammaps.empCode" placeholder="用户名称" style="width: 180px;" class="filter-item" clearable />
  9. <el-input v-model="table.getdataListParm.parammaps.empname" placeholder="员工姓名" style="width: 180px;" class="filter-item" clearable />
  10. <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  11. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  12. </el-select>
  13. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  14. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  15. <el-button class="successBorder" @click="handleRefresh">重置</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="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="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="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="250" class-name="small-padding fixed-width" fixed="right">
  80. <template slot-scope="{row}">
  81. <!-- 新增 -->
  82. <el-button v-if="row.isCreate" :disabled="isokDisable" class="miniSuccess" @click="createData(row)">保存</el-button>
  83. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  84. <!-- 编辑 -->
  85. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  86. <el-button v-if="row.isUpdate" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  87. <!-- 编辑保存 -->
  88. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" class="miniSuccess" @click="updateData(row)">保存</el-button>
  89. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  94. </div>
  95. </div>
  96. </template>
  97. <script>
  98. import { GetDataByName, PostDataByName, failproccess, GetDataByNames, ExecDataByConfig } from '@/api/common'
  99. import Cookies from 'js-cookie'
  100. import { parseTime } from '@/utils/index.js'
  101. import { MessageBox } from 'element-ui'
  102. import Pagination from '@/components/Pagination'
  103. export default {
  104. name: 'User',
  105. components: { Pagination },
  106. data() {
  107. return {
  108. requestParams: [
  109. { name: 'getRoleAll', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }}
  110. ],
  111. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  112. roleList: [], // 角色
  113. table: {
  114. getdataListParm: {
  115. name: 'getuserallL',
  116. page: 1,
  117. offset: 1,
  118. pagecount: 10,
  119. returntype: 'Map',
  120. parammaps: {
  121. pastureid: Cookies.get('pastureid'),
  122. empCode: '',
  123. empname: '',
  124. enable: '',
  125. starTime: '',
  126. stopTime: '',
  127. inputDatetime: ''
  128. }
  129. },
  130. tableKey: 0,
  131. list: [],
  132. total: 0,
  133. listLoading: true,
  134. temp: {}
  135. },
  136. requestParam: {},
  137. isokDisable: false,
  138. selectList: [],
  139. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  140. cellStyle: { padding: 0 + 'px' }
  141. }
  142. },
  143. created() {
  144. this.getList()
  145. this.getDownList()
  146. },
  147. methods: {
  148. getDownList() {
  149. GetDataByNames(this.requestParams).then(response => {
  150. this.roleList = response.data.getRoleAll.list
  151. })
  152. },
  153. getList() {
  154. this.table.listLoading = true
  155. GetDataByName(this.table.getdataListParm).then(response => {
  156. console.log('table数据', response.data.list)
  157. if (response.data.list !== null) {
  158. for (let i = 0; i < response.data.list.length; i++) {
  159. this.$set(response.data.list[i], 'Edit', false) // 编辑
  160. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  161. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  162. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  163. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  164. }
  165. this.table.list = response.data.list
  166. this.table.pageNum = response.data.pageNum
  167. this.table.pageSize = response.data.pageSize
  168. this.table.total = response.data.total
  169. } else {
  170. this.table.list = []
  171. }
  172. setTimeout(() => {
  173. this.table.listLoading = false
  174. }, 100)
  175. })
  176. },
  177. handleEnableChange() {
  178. console.log('点击了是否启用')
  179. },
  180. handleSearch() {
  181. console.log('点击了查询')
  182. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  183. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  184. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  185. } else {
  186. this.table.getdataListParm.parammaps.inputDatetime = ''
  187. this.table.getdataListParm.parammaps.startTime = ''
  188. this.table.getdataListParm.parammaps.stopTime = ''
  189. }
  190. this.table.getdataListParm.offset = 1
  191. this.getList()
  192. },
  193. handleRefresh() {
  194. console.log('点击了重置')
  195. this.table.getdataListParm.parammaps.empCode = ''
  196. this.table.getdataListParm.parammaps.empname = ''
  197. this.table.getdataListParm.parammaps.enable = ''
  198. this.table.getdataListParm.parammaps.startTime = ''
  199. this.table.getdataListParm.parammaps.stopTime = ''
  200. this.table.getdataListParm.parammaps.inputDatetime = ''
  201. this.table.getdataListParm.offset = 1
  202. this.getList()
  203. },
  204. handleCreate() {
  205. // 编辑true/不可编辑false
  206. // 新增操true,编辑false,编辑保存false
  207. for (let i = 0; i < this.table.list.length; i++) {
  208. if (this.table.list[i].Edit === true) {
  209. console.log(123)
  210. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  211. return false
  212. }
  213. }
  214. 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': '' })
  215. },
  216. changeRolename(item) {
  217. this.table.temp.rolename = this.roleList.find(obj => obj.id === item).rolename
  218. },
  219. createData(row) {
  220. console.log('点击了新增保存', row)
  221. this.table.temp.pastureid = Cookies.get('pastureid')
  222. this.table.temp.empname = row.empname
  223. this.table.temp.username = row.username
  224. this.table.temp.phone = row.phone
  225. this.table.temp.createmp = row.createmp
  226. this.table.temp.enable = row.enable
  227. this.table.temp.roleid = row.roleid
  228. // 检验用户名称/角色是否为空
  229. if (this.table.temp.username == '' && this.table.temp.roleid == '') {
  230. this.$message({ type: 'error', message: '用户名称/角色不能为空', duration: 2000 })
  231. return false
  232. } else if (this.table.temp.username == '') {
  233. this.$message({ type: 'error', message: '用户名称不能为空', duration: 2000 })
  234. return false
  235. } else if (this.table.temp.roleid == '') {
  236. this.$message({ type: 'error', message: '角色不能为空', duration: 2000 })
  237. return false
  238. }
  239. // 检验手机号是否为11位数字
  240. if (this.table.temp.phone !== undefined && this.table.temp.phone !== '') {
  241. const phone = /^\d{11}$/
  242. if (!phone.test(this.table.temp.phone)) {
  243. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  244. return false
  245. }
  246. }
  247. this.isokDisable = true
  248. setTimeout(() => {
  249. this.isokDisable = false
  250. }, 1000)
  251. this.requestParam.name = 'createUser'
  252. this.requestParam.parammaps = this.table.temp
  253. PostDataByName(this.requestParam).then(response => {
  254. console.log('新增保存发送参数', this.requestParam)
  255. if (response.msg !== 'fail') {
  256. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  257. this.getList()
  258. } else {
  259. failproccess(response, this.$notify)
  260. }
  261. })
  262. },
  263. createCancel(row) {
  264. console.log('点击了新增取消')
  265. for (let i = 0; i < this.table.list.length; i++) {
  266. if (row.myId === this.table.list[i].myId) {
  267. var listIndex = this.table.list.indexOf(this.table.list[i])
  268. }
  269. if (listIndex > -1) {
  270. this.table.list.splice(listIndex, 1)
  271. return
  272. }
  273. }
  274. },
  275. handleUpdate(row) {
  276. for (let i = 0; i < this.table.list.length; i++) {
  277. if (this.table.list[i].Edit == true) {
  278. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  279. return false
  280. }
  281. }
  282. // 编辑true,不可编辑false
  283. row.Edit = true
  284. row.NoEdit = false
  285. // 新增false,编辑false,编辑保存true
  286. row.isCreate = false
  287. row.isUpdate = false
  288. row.isUpdateSave = true
  289. row.roleid = String(row.roleid)
  290. this.table.temp.roleid = row.roleid
  291. this.table.temp.rolename = row.rolename
  292. },
  293. updateData(row) {
  294. console.log('点击了编辑保存', row)
  295. this.table.temp.pastureid = row.pastureid
  296. this.table.temp.empname = row.empname
  297. this.table.temp.username = row.username
  298. this.table.temp.phone = row.phone
  299. this.table.temp.createmp = row.createmp
  300. this.table.temp.enable = row.enable
  301. this.table.temp.roleid = row.roleid
  302. this.table.temp.id = row.id
  303. // 校验用户名称/角色是否为空
  304. if (this.table.temp.username == '' && this.table.temp.roleid == '') {
  305. this.$message({ type: 'error', message: '用户名称/角色不能为空', duration: 2000 })
  306. return false
  307. } else if (this.table.temp.username == '') {
  308. this.$message({ type: 'error', message: '用户名称不能为空', duration: 2000 })
  309. return false
  310. } else if (this.table.temp.roleid == '') {
  311. this.$message({ type: 'error', message: '角色不能为空', duration: 2000 })
  312. return false
  313. }
  314. console.log(this.table.temp.phone)
  315. // 检验手机号是否为11位数字
  316. if (this.table.temp.phone !== undefined && this.table.temp.phone !== '') {
  317. const phone = /^\d{11}$/
  318. if (!phone.test(this.table.temp.phone)) {
  319. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  320. return false
  321. }
  322. }
  323. this.isokDisable = true
  324. setTimeout(() => {
  325. this.isokDisable = false
  326. }, 1000)
  327. this.requestParam.name = 'updateUser'
  328. this.requestParam.parammaps = this.table.temp
  329. PostDataByName(this.requestParam).then(response => {
  330. console.log('新增保存发送参数', this.requestParam)
  331. if (response.msg !== 'fail') {
  332. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  333. this.getList()
  334. } else {
  335. failproccess(response, this.$notify)
  336. }
  337. })
  338. },
  339. updateCancel(row) {
  340. console.log('点击了编辑取消')
  341. // 编辑false,不可编辑true
  342. row.Edit = false
  343. row.NoEdit = true
  344. // 新增false,编辑true,编辑保存false
  345. row.isCreate = false
  346. row.isUpdate = true
  347. row.isUpdateSave = false
  348. },
  349. handleRowDelete(row) {
  350. console.log('点击了行内删除')
  351. MessageBox.confirm('是否确认删除此信息?', {
  352. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  353. }).then(() => {
  354. this.selectList = []
  355. this.requestParam.name = 'deleteUser'
  356. this.requestParam.parammaps = {}
  357. this.requestParam.parammaps.pastureid = row.pastureid
  358. this.requestParam.parammaps.id = row.id
  359. PostDataByName(this.requestParam).then(response => {
  360. if (response.msg === 'fail') {
  361. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  362. } else {
  363. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  364. this.getList()
  365. }
  366. })
  367. }).catch(() => {
  368. this.$message({ type: 'info', message: '已取消删除' })
  369. })
  370. },
  371. handleSelectionChange(val) {
  372. console.log('勾选数据', val)
  373. this.selectList = val
  374. },
  375. handleDelete() {
  376. console.log('点击了删除')
  377. if (this.selectList.length == 0) {
  378. this.$message({ type: 'error', message: '请选择用户信息', duration: 2000 })
  379. } else {
  380. MessageBox.confirm('是否确认删除此信息?', {
  381. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  382. }).then(() => {
  383. console.log(this.selectList)
  384. this.requestParam.common = { 'returnmap': '0' }
  385. this.requestParam.data = []
  386. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  387. this.requestParam.data[0].children = []
  388. this.requestParam.data[0].children[0] = { 'name': 'deleteUser', 'type': 'e', 'parammaps': {
  389. id: '@insertSpotList.id',
  390. pastureid: '@insertSpotList.pastureid'
  391. }}
  392. ExecDataByConfig(this.requestParam).then(response => {
  393. console.log('删除保存发送参数', this.requestParam)
  394. if (response.msg === 'fail') {
  395. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  396. } else {
  397. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  398. this.getList()
  399. }
  400. })
  401. })
  402. }
  403. }
  404. }
  405. }
  406. </script>
  407. <style lang="scss" scoped>
  408. .search{margin-top:10px;}
  409. .table{margin-top:10px;}
  410. </style>