useroperation.vue 10 KB

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