index改好.vue 31 KB

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