index.vue 33 KB

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