useroperation.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="">
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  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 />
  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="alterTF" :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="alterTF"
  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="40%" 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. }
  117. },
  118. methods: {
  119. async getForbidden() { //获取用户的使用状态
  120. const res = await this.$myRequest({
  121. url: '/api/api_gateway?method=user.login.users_statu_updata',
  122. data: {
  123. uid: this.user_meg.uid,
  124. state: this.user_meg.state == '1' ? 4 : 1 //1是正常 4是禁用
  125. }
  126. })
  127. console.log(res)
  128. if (this.user_meg.state == "1" && res == true) {
  129. this.user_meg.state = '4'
  130. console.log(this.user_meg.state)
  131. } else {
  132. this.user_meg.state = '1'
  133. console.log(this.user_meg.state)
  134. }
  135. if (this.user_meg.state == '1') {
  136. this.tf = "正常"
  137. this.forbiddenTF = true
  138. } else if (this.user_meg.state == '4') {
  139. this.tf = "禁止使用"
  140. this.forbiddenTF = false
  141. }
  142. },
  143. async getGroup() { //获取用户的主题信息
  144. const res = await this.$myRequest({
  145. url: '/api/api_gateway?method=pest.warning_record.rolemanage_view'
  146. })
  147. for (var i = 0; i < res.data.length; i++) {
  148. let obj = {}
  149. obj.text = res.data[i].role_describe
  150. obj.id = res.data[i].id
  151. this.theme.push(obj)
  152. if (this.user_meg.user_group_id == res.data[i].id) { //根据主题id更改主题
  153. this.theme_items = res.data[i].role_describe
  154. }
  155. }
  156. },
  157. async getThemes() { //获取用户角色
  158. const res = await this.$myRequest({
  159. url: '/api/api_gateway?method=user.perms.role_list'
  160. })
  161. for (var i = 0; i < res.length; i++) {
  162. let obj = {}
  163. obj.text = res[i].role_name
  164. obj.id = res[i].role_id
  165. this.roles.push(obj)
  166. }
  167. },
  168. compile() { //编辑按钮
  169. this.btnTF = !this.btnTF
  170. this.alterTF = false
  171. },
  172. forbidden() { //禁用按钮
  173. this.getForbidden()
  174. },
  175. themes(index) { //主题下拉框
  176. this.theme_items = this.theme[index].text;
  177. this.user_meg.user_group_id_index = this.theme[index].id;
  178. },
  179. async getModification() { //修改用户
  180. const res = await this.$myRequest({
  181. url: '/api/api_gateway?method=user.login.users_info_updata',
  182. data: {
  183. uid: this.user_meg.uid,
  184. mobile: this.user_meg.mobile,
  185. user_group_id: this.user_meg.user_group_id_index || '',
  186. user_type: this.user_meg.user_type,
  187. role_id: this.roles_id || this.user_meg.role_id
  188. },
  189. })
  190. },
  191. modification() { //修改用户确认按钮
  192. this.getModification()
  193. this.btnTF = true
  194. this.alterTF = true
  195. },
  196. typesofroles(idnex) { //主题下拉框选项按钮
  197. this.user_meg.role_name = this.roles[idnex].text
  198. this.users_type_show = false
  199. this.roles_id = this.roles[idnex].id
  200. },
  201. bluechange(str) { //手机号框失去焦点时检测手机号
  202. let regexp = /^1[23456789]\d{9}$/
  203. this.tishitf = !regexp.test(str)
  204. if (regexp.test(str)) {
  205. this.tijiaotf = !regexp.test(str)
  206. } else {
  207. this.tijiaotf = regexp.test(str)
  208. }
  209. },
  210. clickLeft() { //返回上一页按钮
  211. uni.navigateTo({
  212. url: './index'
  213. });
  214. },
  215. changePassword() { //修改密码
  216. uni.navigateTo({
  217. url: './changepasswold?item=' + JSON.stringify(this.user_meg)
  218. });
  219. },
  220. assignment() { //分配设备
  221. uni.navigateTo({
  222. url: './assignment?item=' + JSON.stringify(this.user_meg)
  223. });
  224. },
  225. async getRecharge() { //修改用户
  226. const res = await this.$myRequest({
  227. url: '/api/api_gateway?method=user.login.user_add_package_time',
  228. data: {
  229. uid: this.user_meg.uid,
  230. user_test: 1
  231. },
  232. })
  233. },
  234. recharge() { //充值按钮
  235. uni.showModal({
  236. title: '提示',
  237. content: '是否向该用户充值一年费用?',
  238. success: function(res) {
  239. if (res.confirm) {
  240. this.getRecharge()
  241. console.log('用户点击确定');
  242. } else if (res.cancel) {
  243. console.log('用户点击取消');
  244. }
  245. }
  246. });
  247. }
  248. },
  249. onLoad(option) {
  250. this.user_meg = JSON.parse(option.item)
  251. console.log(this.user_meg)
  252. if (this.user_meg.state == '1') {
  253. this.tf = "正常"
  254. this.forbiddenTF = true
  255. } else if (this.user_meg.state == '4') {
  256. this.tf = "禁止使用"
  257. this.forbiddenTF = false
  258. }
  259. this.getGroup()
  260. this.getThemes()
  261. }
  262. }
  263. </script>
  264. <style lang="scss">
  265. .useroperations {
  266. width: 100%;
  267. display: flex;
  268. justify-content: center;
  269. .uForm {
  270. margin-top: 44px;
  271. width: 95%;
  272. .uFormbg {
  273. width: 100%;
  274. background-color: #f3f3f3;
  275. margin-top: 20rpx;
  276. }
  277. .tishi {
  278. text-align: center;
  279. font-size: 24rpx;
  280. color: red;
  281. }
  282. .u-form-item {
  283. width: 95%;
  284. height: 80rpx;
  285. margin: 0 auto;
  286. padding: 5rpx 0;
  287. }
  288. .uuinput {
  289. background-color: white;
  290. }
  291. }
  292. }
  293. .operation_group {
  294. .group_one {
  295. .group_one_top {
  296. width: 90%;
  297. margin: 20rpx auto;
  298. display: flex;
  299. justify-content: space-around;
  300. button {
  301. width: 23%;
  302. height: 60rpx;
  303. line-height: 60rpx;
  304. background-color: $uni-color-success;
  305. color: white;
  306. font-size: 24rpx;
  307. }
  308. }
  309. .group_one_bot {
  310. width: 90%;
  311. margin: 20rpx auto;
  312. button {
  313. height: 60rpx;
  314. line-height: 60rpx;
  315. background-color: $uni-color-success;
  316. color: white;
  317. font-size: 30rpx;
  318. }
  319. }
  320. }
  321. .group_two {
  322. width: 90%;
  323. margin: 20rpx auto;
  324. button {
  325. background-color: $uni-color-success;
  326. color: white;
  327. height: 80rpx;
  328. line-height: 80rpx;
  329. font-size: 30rpx;
  330. }
  331. }
  332. }
  333. .pop-up {
  334. .sheet {
  335. background-color: white;
  336. height: 400rpx;
  337. overflow: hidden;
  338. .sheet-text {
  339. height: 80rpx;
  340. p {
  341. text-align: center;
  342. height: 80rpx;
  343. line-height: 80rpx;
  344. color: black;
  345. font-size: 16px;
  346. }
  347. }
  348. }
  349. button {
  350. color: black;
  351. position: absolute;
  352. bottom: 0;
  353. width: 100%;
  354. font-size: 16px;
  355. height: 80rpx;
  356. }
  357. }
  358. </style>