addusers.vue 8.3 KB

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