addusers.vue 7.7 KB

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