index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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-input v-model="getdataListParm.parammaps.roleName" placeholder="角色" style="width: 140px;" class="filter-item" />
  8. <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
  9. <el-button v-if="isUserAdd" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="form_add"> 新增 </el-button>
  10. </div>
  11. <el-table
  12. v-loading="listLoading"
  13. element-loading-text="给我一点时间"
  14. :data="list"
  15. border
  16. fit
  17. highlight-current-row
  18. style="width: 100%;"
  19. :row-style="rowStyle"
  20. :cell-style="cellStyle"
  21. class="elTable"
  22. row-key="id"
  23. default-expand-all
  24. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  25. @sort-change="tableSort"
  26. >
  27. <el-table-column label="用户名称" header-align="center" width="120px" align="center">
  28. <template slot-scope="scope">
  29. <span>{{ scope.row.username }}</span>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="姓名" min-width="120px" header-align="center" align="center">
  33. <template slot-scope="scope">
  34. <span>{{ scope.row.empname }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="部门" min-width="120px" header-align="center" align="center">
  38. <template slot-scope="scope">
  39. <span>{{ scope.row.deptname }}</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="角色" min-width="120px" header-align="center" align="center">
  43. <template slot-scope="scope">
  44. <span>{{ scope.row.roleName }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="顺序" sortable prop="sort" min-width="80px" header-align="center" align="center">
  48. <template slot-scope="scope">
  49. <span>{{ scope.row.sort }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  53. <template slot-scope="scope">
  54. <el-switch v-model="scope.row.enable" disabled active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="操作" header-align="center" align="center" width="330" class-name="small-padding fixed-width" fixed="right">
  58. <template slot-scope="{row}">
  59. <el-button v-if="isUserRole" type="warning" size="mini" @click="handleRole(row)"> 角色 </el-button>
  60. <el-button v-if="isUserEdit" type="primary" size="mini" @click="form_edit(row)"> 编辑 </el-button>
  61. <el-button v-if="isUserResetpassword" type="warning" size="mini" style="padding: 7px 5px;" @click="handleResetPassword(row)"> 重置密码 </el-button>
  62. <el-button v-if="row.status !== '已删' && isUserDelete" size="mini" type="danger" @click="form_delete(row)"> 删除 </el-button>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <pagination v-show="total>0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
  67. <!-- 编辑 -->
  68. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  69. <el-form ref="dataForm" :rules="rules" :model="dataform" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  70. <el-form-item label="职工名" prop="empid">
  71. <el-autocomplete ref="empid" v-model="dataform.empname" value-key="empid" class="inline-input" :fetch-suggestions="formNameSearch" placeholder="请输入内容" style="width:80%" @select="handleformNameSelect">
  72. <template slot-scope="{ item }">
  73. <div class="name" style="display: inline;">姓名: {{ item.empname }}</div>
  74. <span class="addr"> 职位:{{ item.position }}</span>
  75. </template>
  76. </el-autocomplete>
  77. </el-form-item>
  78. <el-form-item label="用户名" prop="username">
  79. <el-input ref="username" v-model="dataform.username" />
  80. </el-form-item>
  81. <el-form-item label="顺序" prop="sort">
  82. <el-input ref="sort" v-model="dataform.sort" />
  83. </el-form-item>
  84. <el-form-item label="启用" prop="enable">
  85. <el-switch ref="enable" v-model="dataform.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  86. </el-form-item>
  87. <el-form-item label="记录仪账号" prop="deviceId">
  88. <el-select v-model="dataform.deviceId" style="width:500px;" placeholder="请选择" @change="change_deviceId">
  89. <el-option v-for="item in viedoAccountList" :key="item.deviceId" :label="item.deviceId" :value="item.deviceId" />
  90. </el-select>
  91. </el-form-item>
  92. <el-form-item label="是否保养工" prop="keeper">
  93. <el-switch ref="keeper" v-model="dataform.keeper" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  94. </el-form-item>
  95. <el-form-item label="是否维修工" prop="maintenancePerson">
  96. <el-switch ref="maintenancePerson" v-model="dataform.maintenancePerson" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="changeMaintenanceWorker" />
  97. </el-form-item>
  98. <el-form-item label="维修工类型" prop="maintenanceTypeId">
  99. <el-select v-model="dataform.maintenanceTypeId" :disabled="disabled" style="width:500px;" multiple placeholder="请选择">
  100. <el-option v-for="item in repairmanTypeList" :key="item.id" :label="item.typeName" :value="item.id" />
  101. </el-select>
  102. </el-form-item>
  103. <!-- <el-form-item label="记录仪账号" prop="deviceId">
  104. <el-select v-model="dataform.deviceId" style="width:500px;" placeholder="请选择" @change="change_deviceId">
  105. <el-option v-for="item in viedoAccountList" :key="item.deviceId" :label="item.deviceId" :value="item.deviceId" />
  106. </el-select>
  107. </el-form-item> -->
  108. </el-form>
  109. <div slot="footer" class="dialog-footer">
  110. <el-button type="primary" @click="edit_dialog_save()"> 确认 </el-button>
  111. <el-button @click="dialogFormVisible = false"> 关闭 </el-button>
  112. </div>
  113. </el-dialog>
  114. <!-- 新增 -->
  115. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisibleAdd" :close-on-click-modal="false">
  116. <el-form ref="dataForm" :rules="rules" :model="dataform" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  117. <el-form-item label="职工名" prop="empid">
  118. <el-autocomplete ref="empid" v-model="dataform.empname" value-key="empid" class="inline-input" :fetch-suggestions="formNameSearch" placeholder="请输入内容" style="width:100%" @select="handleformNameSelect">
  119. <template slot-scope="{ item }">
  120. <div class="name" style="display: inline;">姓名: {{ item.empname }}</div>
  121. <span class="addr"> 职位:{{ item.position }}</span>
  122. </template>
  123. </el-autocomplete>
  124. </el-form-item>
  125. <el-form-item label="用户名" prop="username">
  126. <el-input ref="username" v-model="dataform.username" />
  127. </el-form-item>
  128. <el-form-item label="角色" prop="rolename">
  129. <el-select v-model="dataform.selectedRole" style="width:500px;" multiple placeholder="请选择">
  130. <el-option v-for="item in rolelist" :key="item.id" :label="item.name" :value="item.id" />
  131. </el-select>
  132. </el-form-item>
  133. <el-form-item label="启用" prop="enable">
  134. <el-switch ref="enable" v-model="dataform.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  135. </el-form-item>
  136. <el-form-item label="记录仪账号" prop="deviceId">
  137. <el-select v-model="dataform.deviceId" style="width:500px;" placeholder="请选择" @change="change_deviceId">
  138. <el-option v-for="item in viedoAccountList" :key="item.deviceId" :label="item.deviceId" :value="item.deviceId" />
  139. </el-select>
  140. </el-form-item>
  141. <el-form-item label="是否保养工" prop="keeper">
  142. <el-switch ref="keeper" v-model="dataform.keeper" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  143. </el-form-item>
  144. <el-form-item label="是否维修工" prop="maintenancePerson">
  145. <el-switch ref="maintenancePerson" v-model="dataform.maintenancePerson" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="changeMaintenanceWorker" />
  146. </el-form-item>
  147. <el-form-item label="维修工类型" prop="maintenanceTypeId">
  148. <el-select v-model="dataform.maintenanceTypeId" :disabled="disabled" style="width:500px;" multiple placeholder="请选择">
  149. <el-option v-for="item in repairmanTypeList" :key="item.id" :label="item.typeName" :value="item.id" />
  150. </el-select>
  151. </el-form-item>
  152. <!-- <el-form-item label="记录仪账号" prop="deviceId">
  153. <el-select v-model="dataform.deviceId" style="width:500px;" placeholder="请选择">
  154. <el-option v-for="item in viedoAccountList" :key="item.deviceId" :label="item.deviceId" :value="item.deviceId" />
  155. </el-select>
  156. </el-form-item> -->
  157. </el-form>
  158. <div slot="footer" class="dialog-footer">
  159. <el-button type="primary" @click="add_dialog_save()"> 确认 </el-button>
  160. <el-button @click="dialogFormVisibleAdd = false"> 关闭 </el-button>
  161. </div>
  162. </el-dialog>
  163. <!-- 角色 -->
  164. <el-dialog :title="textMap['role']" :visible.sync="dialogRoleVisible" :close-on-click-modal="false">
  165. <el-form :rules="rules" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  166. <el-form-item label="角色" prop="rolename">
  167. <el-select v-model="selectedRole" style="width:500px;" multiple placeholder="请选择">
  168. <el-option v-for="item in rolelist" :key="item.id" :label="item.name" :value="item.id" />
  169. </el-select>
  170. </el-form-item>
  171. </el-form>
  172. <div slot="footer" class="dialog-footer">
  173. <el-button type="primary" @click="updateRole()"> 确认 </el-button>
  174. <el-button @click="dialogRoleVisible = false"> 关闭 </el-button>
  175. </div>
  176. </el-dialog>
  177. </div>
  178. </div>
  179. </template>
  180. <script>
  181. import waves from '@/directive/waves' // waves directive
  182. import { isIntegerZero } from '@/utils/validate'
  183. import { PostDataByName, GetDataByName, GetDataByNames, UpdateDataRelation, ExecDataByConfig,checkButtons } from '@/api/common'
  184. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  185. import { MessageBox } from 'element-ui'
  186. import Cookies from 'js-cookie'
  187. import { sortChange } from '@/utils/index.js'
  188. export default {
  189. name: 'User',
  190. components: { Pagination },
  191. directives: { waves },
  192. data() {
  193. return {
  194. isUserDelete:[],isUserResetpassword:[],isUserEdit:[],isUserRole:[],isUserAdd:[],
  195. tableKey: 0,
  196. list: [{ sqlname: '', id: 0, sqlstr: '' }],
  197. total: 0,
  198. listLoading: true,
  199. requestParam: { name: 'createapisql', offset: 0, pagecount: 0, params: [] },
  200. requestParam2: {},
  201. repairmanTypeList: [],
  202. requestParams: [
  203. { name: 'getRoleall', offset: 0, pagecount: 0, parammaps: { pastureId: Cookies.get('pastureid') }},
  204. { name: 'getEmpall', offset: 0, pagecount: 0, params: [] },
  205. { name: 'getMaintenanceTypeList', offset: 0, pagecount: 0, params: [] },
  206. { name: 'getMcsAccounts', offset: 0, pagecount: 0, params: [] },
  207. ],
  208. requestFilterParams: { returntype: 'Map', parammaps: {}},
  209. UpdateDataRelationParam: { name: '', dataname: '', datavalue: '', valuename: '', values: [] },
  210. dataform: { empname: '', position: '', username: '', fullname: '', empid: '', id: '', sort: '', enable: 1, maintenancePerson: 1, keeper: 1, maintenanceTypeId: '', selectedRole: '' },
  211. temp1: { empname: '', empid: '', position: '' },
  212. rolelist: [],
  213. emplist: [],
  214. viedoAccountList: [
  215. // { deviceId: '92301', uId: 'gxlf', pwd: '000000' },
  216. // { deviceId: 'apptest2', uId: 'PC', pwd: 'mcs8@666' }
  217. ],
  218. getdataListParm: {
  219. name: 'getuserallL', offset: 1, pagecount: 10, returntype: 'Map',
  220. parammaps: { pastureId: Cookies.get('pastureid'), empCode: '', empname: '' }
  221. },
  222. updateParam: {
  223. name: 'getMaintenanceTypeByUser', offset: 1, pagecount: 0, returntype: 'list',
  224. params: []
  225. },
  226. rules: {
  227. empid: [{ required: true, message: '用户名必填', trigger: 'blur' }],
  228. username: [{ type: 'string', required: true, message: '用户名必填', trigger: 'change' }],
  229. empname: [{ type: 'string', required: true, message: '职工名必填', trigger: 'change' }],
  230. sort: [{ validator: isIntegerZero, trigger: 'blur' }]
  231. },
  232. dialogFormVisible: false,
  233. dialogRoleVisible: false,
  234. selectedRole: '',
  235. dialogStatus: '',
  236. textMap: { update: '编辑', create: '新增', role: '选择角色' },
  237. dialogFormVisibleAdd: false,
  238. postDataPramas: {},
  239. disabled: false,
  240. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  241. cellStyle: { padding: 0 + 'px' }
  242. }
  243. },
  244. created() {
  245. const that = this
  246. GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': Cookies.get('name') }}).then(response => {
  247. that.buttons = response.data.list
  248. that.getButtons()
  249. })
  250. this.getList()
  251. },
  252. methods: {
  253. tableSort(column) {
  254. sortChange(column, this.list)
  255. },
  256. getButtons() {
  257. // 新增
  258. const UserAdd = 'console:user:add'
  259. const isUserAdd = checkButtons(this.$store.state.user.buttons, UserAdd)
  260. this.isUserAdd = isUserAdd
  261. // 角色
  262. const UserRole = 'console:user:role'
  263. const isUserRole = checkButtons(this.$store.state.user.buttons, UserRole)
  264. this.isUserRole = isUserRole
  265. // 编辑
  266. const UserEdit = 'console:user:edit'
  267. const isUserEdit = checkButtons(this.$store.state.user.buttons, UserEdit)
  268. this.isUserEdit = isUserEdit
  269. // 重置密码
  270. const UserResetpassword = 'console:user:resetpassword'
  271. const isUserResetpassword = checkButtons(this.$store.state.user.buttons, UserResetpassword)
  272. this.isUserResetpassword = isUserResetpassword
  273. // 删除
  274. const UserDelete = 'console:user:delete'
  275. const isUserDelete = checkButtons(this.$store.state.user.buttons, isUserDelete)
  276. this.isUserDelete = isUserDelete
  277. },
  278. getList() {
  279. this.listLoading = true
  280. GetDataByNames(this.requestParams).then(response => {
  281. this.rolelist = response.data.getRoleall.list
  282. this.emplist = response.data.getEmpall.list
  283. this.repairmanTypeList = response.data.getMaintenanceTypeList.list
  284. this.viedoAccountList = response.data.getMcsAccounts.list
  285. GetDataByName(this.getdataListParm).then(response => {
  286. this.list = response.data.list
  287. if (response.data.total) {
  288. this.total = response.data.total
  289. }
  290. setTimeout(() => {
  291. this.listLoading = false
  292. }, 1000)
  293. })
  294. })
  295. },
  296. form_search() {
  297. this.listLoading = true
  298. this.getdataListParm.offset = 1
  299. this.getList()
  300. },
  301. resetRequestParam() {
  302. this.dataform = { username: '', fullname: '', empid: '', id: '', empname: '', position: '', sort: '', enable: 1, selectedRole: '',selectedRole2:'', maintenancePerson: 1, keeper: 1, maintenanceTypeId: '' }
  303. },
  304. form_add() {
  305. this.resetRequestParam()
  306. this.dialogStatus = 'create'
  307. this.dialogFormVisibleAdd = true
  308. },
  309. changeMaintenanceWorker(item) {
  310. if (item == 1) {
  311. this.disabled = false
  312. } else {
  313. this.disabled = true
  314. this.dataform.maintenanceTypeId = []
  315. }
  316. },
  317. add_dialog_save() {
  318. var role_Array = []
  319. for (let i = 0; i < this.dataform.selectedRole.length; i++) {
  320. var role_obj = {}
  321. this.$set(role_obj, 'role_id', this.dataform.selectedRole[i])
  322. role_Array.push(role_obj)
  323. }
  324. this.dataform.selectedRole2 = role_Array
  325. var maintenanceTypeId_Array = []
  326. for (let i = 0; i < this.dataform.maintenanceTypeId.length; i++) {
  327. var maintenanceTypeId = {}
  328. this.$set(maintenanceTypeId, 'maintenanceTypeId', this.dataform.maintenanceTypeId[i])
  329. maintenanceTypeId_Array.push(maintenanceTypeId)
  330. }
  331. this.dataform.maintenanceTypeId = maintenanceTypeId_Array
  332. this.$refs['dataForm'].validate(valid => {
  333. if (valid) {
  334. if (this.dataform.selectedRole2.length <= 0) {
  335. this.$message({ type: 'warning', message: '请检查角色是否未填写', duration: 2000 })
  336. return false
  337. } else {
  338. this.postDataPramas.common = { 'returnmap': '0' }
  339. this.postDataPramas.data = []
  340. this.postDataPramas.data[0] = { 'name': 'createUser', 'type': 'e', 'parammaps': {
  341. username: this.dataform.username,
  342. empid: this.dataform.empid,
  343. sort: '0',
  344. enable: this.dataform.enable,
  345. maintenancePerson: this.dataform.maintenancePerson,
  346. keeper: this.dataform.keeper
  347. }}
  348. this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.dataform.selectedRole2 }}
  349. this.postDataPramas.data[1].children = []
  350. this.postDataPramas.data[1].children[0] = { 'name': 'insertUserRole', 'type': 'e', 'parammaps': {
  351. user_id: '@createUser.LastInsertId',
  352. role_id: '@insertSpotList.role_id'
  353. }}
  354. this.postDataPramas.data[2] = { 'name': 'insertSpotList1', 'resultmaps': { 'list': this.dataform.maintenanceTypeId }}
  355. this.postDataPramas.data[2].children = []
  356. this.postDataPramas.data[2].children[0] = { 'name': 'insertUserMaintenance', 'type': 'e', 'parammaps': {
  357. user_id: '@createUser.LastInsertId',
  358. maintenance_id: '@insertSpotList1.maintenanceTypeId'
  359. }}
  360. console.log('新增保存发送参数', this.postDataPramas)
  361. ExecDataByConfig(this.postDataPramas).then(response => {
  362. console.log('新增保存发送参数', this.postDataPramas)
  363. if (response.msg === 'fail') {
  364. var username = new RegExp('username')
  365. if (username.test(response.data)) {
  366. this.$notify({ title: '', message: '该用户名称已存在', type: 'warning', duration: 2000 })
  367. } else {
  368. this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
  369. }
  370. } else {
  371. // 没有记录的内容
  372. this.$notify({ title: '成功', message: '成功', type: 'success', duration: 2000 })
  373. this.getList()
  374. this.dialogFormVisibleAdd = false
  375. // 没有记录的内容
  376. var pastureId = Cookies.get('pastureid')
  377. console.log(pastureid)
  378. var deviceId = this.dataform.deviceId
  379. var uId = this.dataform.uId
  380. var pwd = this.dataform.pwd
  381. console.log('pastureId', pastureId)
  382. var send_data = {
  383. 'common': {
  384. 'returnmap': '0'
  385. },
  386. 'data': [
  387. {
  388. 'name': 'checkDeviceId',
  389. 'type': 'v',
  390. 'parammaps': {
  391. 'deviceId': deviceId
  392. }
  393. },
  394. {
  395. 'name': 'addDeviceInformation',
  396. 'type': 'e',
  397. 'parammaps': {
  398. 'empId': this.dataform.empid,
  399. 'uId': uId,
  400. 'deviceId': deviceId,
  401. 'pwd': pwd
  402. }
  403. },
  404. {
  405. 'name': 'updateUserDevice',
  406. 'type': 'e',
  407. 'parammaps': {
  408. 'empId': this.dataform.empid
  409. }
  410. }
  411. ]
  412. }
  413. console.log('记录仪保存发送参数===========', send_data)
  414. ExecDataByConfig(send_data).then(response => {
  415. console.log('记录仪保存结果===========', response)
  416. if (response.msg === 'fail') {
  417. if (response.data == '已被绑定') {
  418. var send_data3 = {
  419. 'name': 'updateDeviceInformation',
  420. 'type': 'e',
  421. 'parammaps': {
  422. 'empId': this.dataform.empid,
  423. 'deviceId': this.dataform.deviceId
  424. }
  425. }
  426. MessageBox.confirm('该设备已经绑定,是否重新绑定?', {
  427. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  428. }).then(() => {
  429. PostDataByName(send_data3).then(() => {
  430. this.$notify({ title: '成功', message: '修改成功', type: 'success', duration: 2000 })
  431. this.getList()
  432. this.dialogFormVisible = false
  433. })
  434. })
  435. } else {
  436. this.dialogFormVisibleAdd = false
  437. this.getList()
  438. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  439. }
  440. } else {
  441. this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
  442. }
  443. })
  444. }
  445. })
  446. }
  447. }
  448. })
  449. },
  450. handleRole(row) {
  451. this.requestParam.name = 'getRoleByUser'
  452. this.requestParam.params = []
  453. this.requestParam.params[0] = row.id
  454. this.requestParam.pagecount = 0
  455. this.requestParam.returntype = 'list'
  456. this.dataform.id = row.id
  457. this.dialogRoleVisible = true
  458. GetDataByName(this.requestParam).then(response => {
  459. this.selectedRole = response.data.lists.role_id
  460. })
  461. },
  462. updateRole() {
  463. this.UpdateDataRelationParam.name = 'user_role'
  464. this.UpdateDataRelationParam.dataname = 'user_id'
  465. this.UpdateDataRelationParam.datavalue = this.dataform.id
  466. this.UpdateDataRelationParam.valuename = 'role_id'
  467. this.UpdateDataRelationParam.values = this.selectedRole
  468. UpdateDataRelation(this.UpdateDataRelationParam).then(() => {
  469. this.dialogRoleVisible = false
  470. this.$notify({ title: '成功', message: '修改成功', type: 'success', duration: 2000 })
  471. this.getList()
  472. })
  473. },
  474. form_edit(row) {
  475. console.log(row)
  476. if (row.maintenancePerson == 1) {
  477. this.updateParam.params[0] = row.id
  478. GetDataByName(this.updateParam).then(response => {
  479. console.log(response.data)
  480. if (response.data.lists !== null) {
  481. this.$set(row, 'maintenanceTypeId', response.data.lists.maintenance_id)
  482. } else {
  483. this.$set(row, 'maintenanceTypeId', [])
  484. }
  485. this.dialogStatus = 'update'
  486. this.dialogFormVisible = true
  487. this.disabled = false
  488. })
  489. } else {
  490. this.disabled = true
  491. this.dialogStatus = 'update'
  492. this.dialogFormVisible = true
  493. this.$set(row, 'maintenanceTypeId', [])
  494. }
  495. this.dataform = Object.assign(row, {})
  496. this.$nextTick(() => {
  497. this.$refs['dataForm'].clearValidate()
  498. })
  499. },
  500. edit_dialog_save() {
  501. this.$refs['dataForm'].validate(valid => {
  502. if (valid) {
  503. this.requestParam = {}
  504. this.requestParam.name = 'updateUser'
  505. this.requestParam.params = []
  506. this.requestParam.params[0] = this.dataform.username
  507. this.requestParam.params[1] = this.dataform.empid
  508. this.requestParam.params[2] = this.dataform.sort
  509. this.requestParam.params[3] = this.dataform.enable
  510. if(this.dataform.maintenancePerson == null || this.dataform.maintenancePerson == undefined){
  511. this.requestParam.params[4] = 0
  512. } else {
  513. this.requestParam.params[4] = this.dataform.maintenancePerson
  514. }
  515. this.requestParam.params[5] = this.dataform.keeper
  516. this.requestParam.params[6] = this.dataform.deviceId
  517. this.requestParam.params[7] = this.dataform.id
  518. PostDataByName(this.requestParam).then(response => {
  519. if (response.msg !== 'fail') {
  520. this.requestParam2 = {}
  521. this.requestParam2.name = 'user_mainthenance'
  522. this.requestParam2.dataname = 'user_id'
  523. this.requestParam2.datavalue = this.dataform.id
  524. this.requestParam2.valuename = 'maintenance_id'
  525. this.requestParam2.values = this.dataform.maintenanceTypeId
  526. UpdateDataRelation(this.requestParam2).then(response => {
  527. if (response.msg !== 'fail') {
  528. // this.getList()
  529. // this.dialogFormVisible = false
  530. var send_data = {
  531. 'common': {
  532. 'returnmap': '0'
  533. },
  534. 'data': [
  535. {
  536. 'name': 'checkDeviceId',
  537. 'type': 'v',
  538. 'parammaps': {
  539. 'deviceId': this.dataform.deviceId
  540. }
  541. },
  542. {
  543. 'name': 'addDeviceInformation',
  544. 'type': 'e',
  545. 'parammaps': {
  546. 'empId': this.dataform.empid,
  547. 'uId': this.dataform.uId,
  548. 'deviceId': this.dataform.deviceId,
  549. 'pwd': this.dataform.pwd
  550. }
  551. },
  552. {
  553. 'name': 'updateUserDevice',
  554. 'type': 'e',
  555. 'parammaps': {
  556. 'empId': this.dataform.empid
  557. }
  558. }
  559. ]
  560. }
  561. console.log('记录仪保存发送参数===========', send_data)
  562. ExecDataByConfig(send_data).then(response => {
  563. console.log('记录仪保存结果===========', response)
  564. if (response.msg === 'fail') {
  565. if (response.data == '已被绑定') {
  566. var send_data3 = {
  567. 'name': 'updateDeviceInformation',
  568. 'type': 'e',
  569. 'parammaps': {
  570. 'empId': this.dataform.empid,
  571. 'deviceId': this.dataform.deviceId
  572. }
  573. }
  574. MessageBox.confirm('该设备已经绑定,是否重新绑定?', {
  575. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  576. }).then(() => {
  577. PostDataByName(send_data3).then(() => {
  578. this.$notify({ title: '成功', message: '修改成功', type: 'success', duration: 2000 })
  579. this.getList()
  580. this.dialogFormVisible = false
  581. })
  582. })
  583. } else {
  584. this.getList()
  585. this.dialogFormVisible = false
  586. }
  587. } else {
  588. this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
  589. }
  590. })
  591. } else {
  592. this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
  593. }
  594. })
  595. } else {
  596. this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
  597. }
  598. })
  599. }
  600. })
  601. },
  602. handleEnableChange(index, row) {
  603. this.requestParam.name = 'updateUser'
  604. this.requestParam.params = []
  605. this.requestParam.params[0] = row.username
  606. this.requestParam.params[1] = row.empid
  607. this.requestParam.params[2] = row.sort
  608. this.requestParam.params[3] = row.enable
  609. this.requestParam.params[4] = row.id
  610. PostDataByName(this.requestParam).then(() => {
  611. this.$notify({ title: '成功', message: '修改成功', type: 'success', duration: 2000 })
  612. })
  613. },
  614. form_delete(row) {
  615. MessageBox.confirm('确认删除?', {
  616. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  617. }).then(() => {
  618. this.requestParam.name = 'deleteUser'
  619. this.requestParam.params = []
  620. this.requestParam.params[0] = row.id
  621. PostDataByName(this.requestParam).then(() => {
  622. this.getList()
  623. this.resetRequestParam()
  624. this.dialogFormVisible = false
  625. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  626. })
  627. })
  628. },
  629. formNameSearch(queryString, cb) {
  630. this.requestFilterParams.name = 'userSolr'
  631. this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
  632. this.requestFilterParams.parammaps['empname'] = queryString
  633. GetDataByName(this.requestFilterParams).then(response => {
  634. cb(response.data.list)
  635. })
  636. },
  637. handleformNameSelect(item) {
  638. this.dataform.username = item.empCode
  639. this.dataform.empid = item.id
  640. this.$set(this.dataform, 'empname', item.empname)
  641. this.$set(this.dataform, 'position', item.position)
  642. },
  643. handleResetPassword(row) {
  644. MessageBox.confirm('是否确认将此用户密码重置为默认密码123456?', {
  645. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  646. }).then(() => {
  647. this.requestParam.name = 'initPassword'
  648. this.requestParam.parammaps = {}
  649. this.requestParam.parammaps.id = row.id
  650. PostDataByName(this.requestParam).then(() => {
  651. this.getList()
  652. this.resetRequestParam()
  653. this.dialogFormVisible = false
  654. this.$notify({ title: '成功', message: '重置密码成功', type: 'success', duration: 2000 })
  655. })
  656. })
  657. },
  658. change_deviceId(e) {
  659. console.log(e)
  660. var deviceId = e
  661. var pwd = ''
  662. var uId = ''
  663. var viedoAccountList = this.viedoAccountList
  664. viedoAccountList.forEach(function(io) {
  665. if (io.deviceId == deviceId) {
  666. uId = io.uId
  667. pwd = io.pwd
  668. }
  669. })
  670. this.dataform.uId = uId
  671. this.dataform.pwd = pwd
  672. this.dataform.deviceId = deviceId
  673. }
  674. }
  675. }
  676. </script>