useroperation.vue 11 KB

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