index.vue 33 KB

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