addusers.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view>
  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 @clickLeft="clickLeft" left-icon="back" left-text="返回" title="用户新增"></uni-nav-bar>
  7. </view>
  8. <view class="addusers">
  9. <u-form :model="form" 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" required>
  13. <u-input v-model="form.name" :clearable="clearable" input-align="right" placeholder="请输入姓名" />
  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" required>
  19. <u-input v-model="form.intro" :clearable="clearable" input-align="right" placeholder="请输入电话" />
  20. </u-form-item>
  21. </view>
  22. <view class="uFormbg">
  23. <u-form-item label="密码" left-icon="lock" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom"
  24. prop="passwold" required>
  25. <u-input v-model="form.passwold" type="password" :clearable="clearable" input-align="right" placeholder="请输入密码" />
  26. </u-form-item>
  27. </view>
  28. <view class="uFormbg">
  29. <u-form-item label="角色类型" left-icon="account-fill" :left-icon-style="lefticonstyle" label-width="160rpx"
  30. :border-bottom="borderbottom">
  31. <u-input v-model="form.typesofrole" type="select" :clearable="clearable" @click="typesofrole[0].show = true"
  32. input-align="right" placeholder="请选择角色类型" :select-open="typesofrole[0].show" />
  33. </u-form-item>
  34. </view>
  35. <view class="uFormbg">
  36. <u-form-item label="主题" left-icon="calendar" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom">
  37. <u-input v-model="form.theme" :clearable="clearable" type="select" @click="theme_show = true" input-align="right"
  38. placeholder="请选择主题" :select-open="theme_show" />
  39. <u-action-sheet :list="theme" v-model="theme_show" @click="themes" scroll-y="true"></u-action-sheet>
  40. </u-form-item>
  41. </view>
  42. <view class="uFormbg">
  43. <u-form-item label="用户类型" left-icon="grid" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom">
  44. <u-input v-model="form.usersofrole" type="select" :clearable="clearable" @click="usersofrole_show = true"
  45. input-align="right" :placeholder="usersofrole[0].text" :select-open="usersofrole_show" />
  46. <u-action-sheet :list="usersofrole" v-model="usersofrole_show" @click="usersofroles"></u-action-sheet>
  47. </u-form-item>
  48. </view>
  49. <view class="uFormbg">
  50. <u-form-item label="测试用户" left-icon="eye" :left-icon-style="lefticonstyle" label-width="160rpx" :border-bottom="borderbottom">
  51. <u-input v-model="form.testuser" type="select" :clearable="clearable" @click="testuser_show = true" input-align="right"
  52. :placeholder="testuser[0].text" :select-open="testuser_show" />
  53. <u-action-sheet :list="testuser" v-model="testuser_show" @click="testusers"></u-action-sheet>
  54. </u-form-item>
  55. </view>
  56. </u-form>
  57. </view>
  58. <button class="submitbtn" @click="addusers">确 定</button>
  59. <u-popup v-model="typesofrole[0].show" mode="bottom" length="30%" class="pop-up">
  60. <scroll-view scroll-y="true" class="sheet">
  61. <view class="sheet-text" v-for="(item,index) in typesofrole[1]" :key="index">
  62. <p @click="typesofroles(item.role_name,item.role_id)">{{item.role_name}}</p>
  63. </view>
  64. </scroll-view>
  65. <button @click="typesofrole[0].show = false">取消</button>
  66. </u-popup>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. export default {
  72. data() {
  73. return {
  74. borderbottom: false,
  75. clearable: false,
  76. form: {
  77. name: null,
  78. intro: null,
  79. passwold: null,
  80. typesofrole: null,
  81. typesofrole_id: null,
  82. theme: null,
  83. usersofrole: null,
  84. usersofrole_id: null,
  85. testuser: null,
  86. },
  87. rules: {
  88. name: [{
  89. required: true,
  90. message: '请输入姓名',
  91. // 可以单个或者同时写两个触发验证方式
  92. trigger: 'blur,change'
  93. },
  94. {
  95. validator: (rule, value, callback) => {
  96. // 上面有说,返回true表示校验通过,返回false表示不通过
  97. // this.$u.test.mobile()就是返回true或者false的
  98. return value.length < 10 && value.length > 1
  99. },
  100. message: '请输入2-10个字符',
  101. // 触发器可以同时用blur和change
  102. trigger: ['change', 'blur'],
  103. }
  104. ],
  105. intro: [{
  106. required: true,
  107. message: '请输入手机号',
  108. // 可以单个或者同时写两个触发验证方式
  109. trigger: 'blur,change'
  110. }, {
  111. // 自定义验证函数,见上说明
  112. validator: (rule, value, callback) => {
  113. // 上面有说,返回true表示校验通过,返回false表示不通过
  114. // this.$u.test.mobile()就是返回true或者false的
  115. return this.$u.test.mobile(value);
  116. },
  117. message: '手机号格式不正确',
  118. // 触发器可以同时用blur和change
  119. trigger: ['change', 'blur'],
  120. }],
  121. passwold: {
  122. required: true,
  123. message: '请输入密码',
  124. // 可以单个或者同时写两个触发验证方式
  125. trigger: 'blur,change'
  126. }
  127. },
  128. lefticonstyle: {
  129. 'color': '#57C878'
  130. },
  131. typesofrole: [{
  132. show: false
  133. }],
  134. theme_show: false,
  135. theme: [],
  136. usersofrole_show: false,
  137. usersofrole: [{
  138. text: "超级管理员"
  139. }, {
  140. text: "经销商"
  141. }, {
  142. text: "农林政府单位"
  143. }, {
  144. text: "普通用户"
  145. }],
  146. testuser_show: false,
  147. testuser: [{
  148. text: "是"
  149. }, {
  150. text: "否"
  151. }]
  152. }
  153. },
  154. methods: {
  155. typesofroles(value, id) {
  156. this.form.typesofrole = value;
  157. this.form.typesofrole_id = id
  158. this.typesofrole[0].show = false
  159. },
  160. themes(index) {
  161. this.form.theme = this.theme[index].text;
  162. },
  163. usersofroles(index) {
  164. this.form.usersofrole = this.usersofrole[index].text;
  165. this.form.usersofrole_id = index + 1
  166. },
  167. testusers(index) {
  168. this.form.testuser = this.testuser[index].text;
  169. },
  170. async getTypesofroles() {
  171. const res = await this.$myRequest({
  172. url: '/api/api_gateway?method=user.perms.role_list'
  173. })
  174. this.typesofrole.push(res)
  175. console.log(res)
  176. },
  177. async getThemes() {
  178. const res = await this.$myRequest({
  179. url: '/api/api_gateway?method=pest.warning_record.rolemanage_view'
  180. })
  181. console.log(res.data)
  182. for (var i = 0; i < res.data.length; i++) {
  183. let obj = {}
  184. obj.text = res.data[i].role_describe
  185. obj.role_id = res.data[i].id
  186. if(obj.text != ''){
  187. this.theme.push(obj)
  188. }
  189. }
  190. },
  191. async getaddusers() {
  192. const res = await this.$myRequest({
  193. url: '/api/api_gateway?method=user.login.regiest',
  194. data: {
  195. username: this.form.name,
  196. mobile: this.form.intro,
  197. password: this.form.passwold,
  198. role_id: this.form.typesofrole_id ? this.form.typesofrole_id : 1,
  199. user_type: this.form.usersofrole_id ? this.form.usersofrole_id : 1,
  200. cs_user: this.form.testuser == "是" ? 1 : 0
  201. }
  202. })
  203. },
  204. addusers() {
  205. if (this.form.name && this.form.intro && this.form.passwold) {
  206. this.getaddusers()
  207. uni.navigateTo({
  208. url: './index'
  209. });
  210. }
  211. },
  212. clickLeft() {
  213. uni.navigateTo({
  214. url: './index'
  215. });
  216. }
  217. },
  218. onLoad() {
  219. this.getTypesofroles()
  220. this.getThemes()
  221. },
  222. onReady() {
  223. this.$refs.uForm.setRules(this.rules);
  224. }
  225. }
  226. </script>
  227. <style lang="scss">
  228. .addusers {
  229. width: 100%;
  230. display: flex;
  231. justify-content: center;
  232. .uForm {
  233. margin-top: 44px;
  234. width: 90%;
  235. .uFormbg {
  236. width: 100%;
  237. padding: 0 20rpx;
  238. margin: 20rpx 0;
  239. background-color: #F7F8FA;
  240. box-sizing: border-box;
  241. .u-form-item {
  242. padding: 0 10rpx;
  243. }
  244. }
  245. }
  246. }
  247. .submitbtn {
  248. width: 95%;
  249. position: absolute;
  250. bottom: -80rpx;
  251. background-color: $uni-color-success;
  252. color: white;
  253. left: 2.5%;
  254. height: 70rpx;
  255. font-size: 32rpx;
  256. line-height: 70rpx;
  257. }
  258. .pop-up {
  259. .sheet {
  260. background-color: white;
  261. height: 400rpx;
  262. overflow: hidden;
  263. .sheet-text {
  264. height: 80rpx;
  265. p {
  266. text-align: center;
  267. height: 80rpx;
  268. line-height: 80rpx;
  269. color: black;
  270. font-size: 16px;
  271. }
  272. }
  273. }
  274. button {
  275. color: black;
  276. position: absolute;
  277. bottom: 0;
  278. width: 100%;
  279. font-size: 16px;
  280. height: 80rpx;
  281. }
  282. }
  283. </style>