useroperation.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view class="">
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar left-icon="back" left-text="返回" @clickLeft="clickLeft" title="用户详情"></uni-nav-bar>
  7. </view>
  8. <view class="useroperations">
  9. <u-form :model="user_meg" ref="uForm" class="uForm">
  10. <view class="uFormbg">
  11. <u-form-item label="姓名" left-icon="account" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom"
  12. prop="name">
  13. <u-input v-model="user_meg.username" :clearable="clearable" input-align="right" :disabled="alterTF" :class="{'uuinput':alterTF==false}" />
  14. </u-form-item>
  15. </view>
  16. <view class="uFormbg">
  17. <u-form-item label="电话" left-icon="phone" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom"
  18. prop="intro">
  19. <u-input v-model="user_meg.mobile" :clearable="clearable" input-align="right" :disabled="alterTF" :class="{'uuinput':alterTF==false}"
  20. @blur="bluechange(user_meg.mobile)" />
  21. </u-form-item>
  22. <p class="tishi" v-if="tishitf">手机格式错误</p>
  23. </view>
  24. <view class="uFormbg">
  25. <u-form-item label="主题" left-icon="calendar" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom"
  26. prop="passwold">
  27. <u-input v-model="theme_items" :clearable="clearable" input-align="right" :disabled="true" :class="{'uuinput':alterTF==false}"
  28. type="selete" @click="theme_show = !alterTF" />
  29. <u-action-sheet :list="theme" v-model="theme_show" @click="themes" scroll-y="true"></u-action-sheet>
  30. </u-form-item>
  31. </view>
  32. <view class="uFormbg">
  33. <u-form-item label="用户类型" left-icon="grid" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom">
  34. <u-input v-model="users_type[user_meg.user_type-1].text" :clearable="clearable" input-align="right" disabled />
  35. </u-form-item>
  36. </view>
  37. <view class="uFormbg">
  38. <u-form-item label="用户角色" left-icon="account-fill" :left-icon-style="lefticonstyle" label-width="160rpx"
  39. :border-bottom="borderbottom">
  40. <u-input v-model="user_meg.role_name" :clearable="clearable" input-align="right" placeholder="请选择主题" :disabled="true"
  41. :class="{'uuinput':alterTF==false}" @click="users_type_show = !alterTF" />
  42. </u-form-item>
  43. </view>
  44. <view class="uFormbg">
  45. <u-form-item label="是否可用" left-icon="order" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom">
  46. <u-input v-model="tf" :clearable="clearable" input-align="right" disabled />
  47. </u-form-item>
  48. </view>
  49. <view class="uFormbg">
  50. <u-form-item label="创建时间" left-icon="clock" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom">
  51. <u-input :clearable="clearable" input-align="right" disabled :value="user_meg.addtime|timeFormat()" />
  52. </u-form-item>
  53. </view>
  54. </u-form>
  55. </view>
  56. <view class="operation_group">
  57. <view class="group_one" v-if="btnTF">
  58. <view class="group_one_top">
  59. <!-- <button type="default" @click="recharge">充值</button> -->
  60. <button type="default" @click="compile">编辑</button>
  61. <button type="default" @click="forbidden" v-if="forbiddenTF" style="background-color: red;">禁用</button>
  62. <button type="default" @click="forbidden" v-else>可用</button>
  63. <button type="default" @click="changePassword">修改密码</button>
  64. </view>
  65. <view class="group_one_bot">
  66. <button type="default" @click="assignment">分配设备</button>
  67. </view>
  68. </view>
  69. <view class="group_two" v-else>
  70. <button type="default" @click="modification" :disabled="tijiaotf">确定</button>
  71. </view>
  72. </view>
  73. <u-popup v-model="users_type_show" mode="bottom" length="30%" class="pop-up">
  74. <scroll-view scroll-y="true" class="sheet">
  75. <view class="sheet-text" v-for="(item,index) in roles" :key="index">
  76. <p @click="typesofroles(index)">{{item.text}}</p>
  77. </view>
  78. </scroll-view>
  79. <button @click="users_type_show = false">取消</button>
  80. </u-popup>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. user_meg: {},
  89. lefticonstyle: {
  90. 'color': "#57C878"
  91. },
  92. borderbottom: false,
  93. clearable: false,
  94. tf: "",
  95. usersofrole_show: true,
  96. btnTF: true,
  97. users_type: [{
  98. text: '超级管理员'
  99. }, {
  100. text: '经销商'
  101. }, {
  102. text: '农林政府单位'
  103. }, {
  104. text: '普通用户'
  105. }],
  106. users_type_show: false,
  107. forbiddenTF: null,
  108. alterTF: true,
  109. theme: [],
  110. theme_show: false,
  111. theme_items: '--',
  112. roles: [],
  113. roles_id: null,
  114. tishitf: false,
  115. tijiaotf: false,
  116. quanxian:{//权限设置
  117. chongzhi :false,
  118. alters :false,
  119. off :false,
  120. pass: false,
  121. shebeiitems:false
  122. }
  123. }
  124. },
  125. methods: {
  126. async getForbidden() { //获取用户的使用状态
  127. const res = await this.$myRequest({
  128. url: '/api/api_gateway?method=user.login.users_statu_updata',
  129. data: {
  130. uid: this.user_meg.uid,
  131. state: this.user_meg.state == '1' ? 4 : 1 //1是正常 4是禁用
  132. }
  133. })
  134. console.log(res)
  135. if (this.user_meg.state == "1" && res == true) {
  136. this.user_meg.state = '4'
  137. console.log(this.user_meg.state)
  138. } else {
  139. this.user_meg.state = '1'
  140. console.log(this.user_meg.state)
  141. }
  142. if (this.user_meg.state == '1') {
  143. this.tf = "正常"
  144. this.forbiddenTF = true
  145. } else if (this.user_meg.state == '4') {
  146. this.tf = "禁止使用"
  147. this.forbiddenTF = false
  148. }
  149. },
  150. async getGroup() { //获取用户的主题信息
  151. const res = await this.$myRequest({
  152. url: '/api/api_gateway?method=pest.warning_record.rolemanage_view'
  153. })
  154. for (var i = 0; i < res.data.length; i++) {
  155. let obj = {}
  156. obj.text = res.data[i].role_describe
  157. obj.id = res.data[i].id
  158. if(obj.text != ''){
  159. this.theme.push(obj)
  160. }
  161. if (this.user_meg.user_group_id == res.data[i].id) { //根据主题id更改主题
  162. this.theme_items = res.data[i].role_describe
  163. }
  164. console.log(this.theme)
  165. }
  166. },
  167. async getThemes() { //获取用户角色
  168. const res = await this.$myRequest({
  169. url: '/api/api_gateway?method=user.perms.role_list'
  170. })
  171. for (var i = 0; i < res.length; i++) {
  172. let obj = {}
  173. obj.text = res[i].role_name
  174. obj.id = res[i].role_id
  175. this.roles.push(obj)
  176. }
  177. },
  178. compile() { //编辑按钮
  179. if(this.quanxian.alters){
  180. this.btnTF = !this.btnTF
  181. this.alterTF = false
  182. }else{
  183. uni.showToast({
  184. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  185. icon: "none"
  186. })
  187. }
  188. },
  189. forbidden() { //禁用按钮
  190. if(this.quanxian.off){
  191. this.getForbidden()
  192. }else{
  193. uni.showToast({
  194. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  195. icon: "none"
  196. })
  197. }
  198. },
  199. themes(index) { //主题下拉框
  200. this.theme_items = this.theme[index].text;
  201. this.user_meg.user_group_id_index = this.theme[index].id;
  202. },
  203. async getModification() { //修改用户
  204. const res = await this.$myRequest({
  205. url: '/api/api_gateway?method=user.login.users_info_updata',
  206. data: {
  207. username: this.user_meg.username,
  208. uid: this.user_meg.uid,
  209. mobile: this.user_meg.mobile,
  210. user_group_id: this.user_meg.user_group_id_index || '',
  211. user_type: this.user_meg.user_type,
  212. role_id: this.roles_id || this.user_meg.role_id
  213. },
  214. })
  215. },
  216. modification() { //修改用户确认按钮
  217. this.getModification()
  218. this.btnTF = true
  219. this.alterTF = true
  220. },
  221. typesofroles(idnex) { //主题下拉框选项按钮
  222. this.user_meg.role_name = this.roles[idnex].text
  223. this.users_type_show = false
  224. this.roles_id = this.roles[idnex].id
  225. },
  226. bluechange(str) { //手机号框失去焦点时检测手机号
  227. let regexp = /^1[23456789]\d{9}$/
  228. this.tishitf = !regexp.test(str)
  229. if (regexp.test(str)) {
  230. this.tijiaotf = !regexp.test(str)
  231. } else {
  232. this.tijiaotf = regexp.test(str)
  233. }
  234. },
  235. clickLeft() { //返回上一页按钮
  236. uni.navigateTo({
  237. url: './index'
  238. });
  239. },
  240. changePassword() { //修改密码
  241. if(this.quanxian.pass){
  242. uni.navigateTo({
  243. url: './changepasswold?item=' + JSON.stringify(this.user_meg)
  244. });
  245. }else{
  246. uni.showToast({
  247. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  248. icon: "none"
  249. })
  250. }
  251. },
  252. assignment() { //分配设备
  253. if(this.quanxian.shebeiitems){
  254. uni.navigateTo({
  255. url: './assignment?item=' + JSON.stringify(this.user_meg)
  256. });
  257. }else{
  258. uni.showToast({
  259. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  260. icon: "none"
  261. })
  262. }
  263. },
  264. async getRecharge() { //修改用户
  265. const res = await this.$myRequest({
  266. url: '/api/api_gateway?method=user.login.user_add_package_time',
  267. data: {
  268. uid: this.user_meg.uid,
  269. user_test: 1
  270. },
  271. })
  272. },
  273. // recharge() { //充值按钮
  274. // if(this.quanxian.chongzhi){
  275. // uni.showModal({
  276. // title: '提示',
  277. // content: '是否向该用户充值一年费用?',
  278. // success: function(res) {
  279. // if (res.confirm) {
  280. // this.getRecharge()
  281. // console.log('用户点击确定');
  282. // } else if (res.cancel) {
  283. // console.log('用户点击取消');
  284. // }
  285. // }
  286. // });
  287. // }else{
  288. // uni.showToast({
  289. // title: "您暂无权限进行此操作,如有需要,请联系管理员",
  290. // icon: "none"
  291. // })
  292. // }
  293. // }
  294. },
  295. onLoad(option) {
  296. this.user_meg = JSON.parse(option.item)
  297. console.log(this.user_meg)
  298. if (this.user_meg.state == '1') {
  299. this.tf = "正常"
  300. this.forbiddenTF = true
  301. } else if (this.user_meg.state == '4') {
  302. this.tf = "禁止使用"
  303. this.forbiddenTF = false
  304. }
  305. this.getGroup()
  306. this.getThemes()
  307. uni.getStorage({
  308. key:"jurisdiction",
  309. success:(res)=>{
  310. console.log(JSON.parse(res.data))
  311. let items = JSON.parse(res.data).filter((item)=>{
  312. return item.purview_name == "系统管理"
  313. })
  314. let items2 = items[0].children.filter((item)=>{
  315. return item.purview_name == "用户管理"
  316. })
  317. let shebeiitems = JSON.parse(res.data).filter((item)=>{
  318. return item.purview_name == "设备管理"
  319. })
  320. this.quanxian.shebeiitems = shebeiitems[0].children.some((item)=>{
  321. return item.purview_name == "分配设备"
  322. })
  323. var arr = items2[0].children
  324. console.log(items)
  325. for(var i =0;i<arr.length;i++){
  326. switch (arr[i].purview_name){
  327. case "充值":
  328. this.quanxian.chongzhi = true
  329. break
  330. case "编辑":
  331. this.quanxian.alters = true
  332. break
  333. case "禁用":
  334. this.quanxian.off = true
  335. break
  336. case "密码":
  337. this.quanxian.pass = true
  338. break
  339. }
  340. }
  341. },
  342. })
  343. },
  344. onBackPress(options) {
  345. if (options.from === 'navigateBack') {
  346. return false;
  347. }
  348. this.clickLeft();
  349. return true;
  350. },
  351. }
  352. </script>
  353. <style lang="scss">
  354. .useroperations {
  355. width: 100%;
  356. display: flex;
  357. justify-content: center;
  358. .uForm {
  359. margin-top: 44px;
  360. width: 95%;
  361. .uFormbg {
  362. width: 100%;
  363. background-color: #f3f3f3;
  364. margin-top: 20rpx;
  365. }
  366. .tishi {
  367. text-align: center;
  368. font-size: 24rpx;
  369. color: red;
  370. }
  371. .u-form-item {
  372. width: 95%;
  373. height: 80rpx;
  374. margin: 0 auto;
  375. padding: 5rpx 0;
  376. }
  377. .uuinput {
  378. background-color: white;
  379. }
  380. }
  381. }
  382. .operation_group {
  383. .group_one {
  384. .group_one_top {
  385. width: 90%;
  386. margin: 20rpx auto;
  387. display: flex;
  388. justify-content: space-around;
  389. button {
  390. width: 23%;
  391. height: 60rpx;
  392. line-height: 60rpx;
  393. background-color: $uni-color-success;
  394. color: white;
  395. font-size: 24rpx;
  396. }
  397. }
  398. .group_one_bot {
  399. width: 90%;
  400. margin: 20rpx auto;
  401. button {
  402. height: 60rpx;
  403. line-height: 60rpx;
  404. background-color: $uni-color-success;
  405. color: white;
  406. font-size: 30rpx;
  407. }
  408. }
  409. }
  410. .group_two {
  411. width: 90%;
  412. margin: 20rpx auto;
  413. button {
  414. background-color: $uni-color-success;
  415. color: white;
  416. height: 80rpx;
  417. line-height: 80rpx;
  418. font-size: 30rpx;
  419. }
  420. }
  421. }
  422. .pop-up {
  423. .sheet {
  424. background-color: white;
  425. height: 400rpx;
  426. overflow: hidden;
  427. .sheet-text {
  428. height: 80rpx;
  429. p {
  430. text-align: center;
  431. height: 80rpx;
  432. line-height: 80rpx;
  433. color: black;
  434. font-size: 16px;
  435. }
  436. }
  437. }
  438. button {
  439. color: black;
  440. position: absolute;
  441. bottom: 0;
  442. width: 100%;
  443. font-size: 16px;
  444. height: 80rpx;
  445. }
  446. }
  447. </style>