addusers.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  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. <view class="hintgroup">
  59. <span v-if="TF.nametf">●请输入姓名</span>
  60. <span v-if="TF.namelongtf">●姓名长度请在2~10个字符</span>
  61. <span v-if="TF.iphonetf">●请输入手机号</span>
  62. <span v-if="TF.iphonetftwo">●请输入正确的手机号</span>
  63. <span v-if="TF.passTF">●请输入密码</span>
  64. </view>
  65. <button class="submitbtn" @click="addusers">确 定</button>
  66. <u-popup v-model="typesofrole[0].show" mode="bottom" length="30%" class="pop-up">
  67. <scroll-view scroll-y="true" class="sheet">
  68. <view class="sheet-text" v-for="(item,index) in typesofrole[1]" :key="index">
  69. <p @click="typesofroles(item.role_name,item.role_id)">{{item.role_name}}</p>
  70. </view>
  71. </scroll-view>
  72. <button @click="typesofrole[0].show = false">取消</button>
  73. </u-popup>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. data() {
  80. return {
  81. borderbottom: false,
  82. clearable: false,
  83. form: {
  84. name: null,
  85. intro: null,
  86. passwold: null,
  87. typesofrole: null,
  88. typesofrole_id: null,
  89. theme: null,
  90. usersofrole: null,
  91. usersofrole_id: null,
  92. testuser: null,
  93. },
  94. rules: {
  95. name: [{
  96. required: true,
  97. message: '请输入姓名',
  98. // 可以单个或者同时写两个触发验证方式
  99. trigger: 'blur,change'
  100. },
  101. {
  102. validator: (rule, value, callback) => {
  103. // 上面有说,返回true表示校验通过,返回false表示不通过
  104. // this.$u.test.mobile()就是返回true或者false的
  105. return value.length < 10 && value.length > 1
  106. },
  107. message: '请输入2-10个字符',
  108. // 触发器可以同时用blur和change
  109. trigger: ['change', 'blur'],
  110. }
  111. ],
  112. intro: [{
  113. required: true,
  114. message: '请输入手机号',
  115. // 可以单个或者同时写两个触发验证方式
  116. trigger: 'blur,change'
  117. }, {
  118. // 自定义验证函数,见上说明
  119. validator: (rule, value, callback) => {
  120. // 上面有说,返回true表示校验通过,返回false表示不通过
  121. // this.$u.test.mobile()就是返回true或者false的
  122. return this.$u.test.mobile(value);
  123. },
  124. message: '手机号格式不正确',
  125. // 触发器可以同时用blur和change
  126. trigger: ['change', 'blur'],
  127. }],
  128. passwold: {
  129. required: true,
  130. message: '请输入密码',
  131. // 可以单个或者同时写两个触发验证方式
  132. trigger: 'blur,change'
  133. }
  134. },
  135. lefticonstyle: {
  136. 'color': '#57C878'
  137. },
  138. typesofrole: [{
  139. show: false
  140. }],
  141. theme_show: false,
  142. theme: [],
  143. usersofrole_show: false,
  144. usersofrole: [{
  145. text: "超级管理员"
  146. }, {
  147. text: "经销商"
  148. }, {
  149. text: "农林政府单位"
  150. }, {
  151. text: "普通用户"
  152. }],
  153. testuser_show: false,
  154. testuser: [{
  155. text: "是"
  156. }, {
  157. text: "否"
  158. }],
  159. TF:{
  160. nametf:false,
  161. namelongtf:false,
  162. iphonetf:false,
  163. iphonetftwo:false,
  164. passTF:false
  165. }
  166. }
  167. },
  168. methods: {
  169. typesofroles(value, id) {
  170. this.form.typesofrole = value;
  171. this.form.typesofrole_id = id
  172. this.typesofrole[0].show = false
  173. },
  174. themes(index) {
  175. this.form.theme = this.theme[index].text;
  176. },
  177. usersofroles(index) {
  178. this.form.usersofrole = this.usersofrole[index].text;
  179. this.form.usersofrole_id = index + 1
  180. },
  181. testusers(index) {
  182. this.form.testuser = this.testuser[index].text;
  183. },
  184. async getTypesofroles() {
  185. const res = await this.$myRequest({
  186. url: '/api/api_gateway?method=user.perms.role_list'
  187. })
  188. this.typesofrole.push(res)
  189. console.log(res)
  190. },
  191. async getThemes() {
  192. const res = await this.$myRequest({
  193. url: '/api/api_gateway?method=pest.warning_record.rolemanage_view'
  194. })
  195. console.log(res.data)
  196. for (var i = 0; i < res.data.length; i++) {
  197. let obj = {}
  198. obj.text = res.data[i].role_describe
  199. obj.role_id = res.data[i].id
  200. if(obj.text != ''){
  201. this.theme.push(obj)
  202. }
  203. }
  204. },
  205. async getaddusers() {
  206. const res = await this.$myRequest({
  207. url: '/api/api_gateway?method=user.login.regiest',
  208. data: {
  209. username: this.form.name,
  210. mobile: this.form.intro,
  211. password: this.form.passwold,
  212. role_id: this.form.typesofrole_id ? this.form.typesofrole_id : 1,
  213. user_type: this.form.usersofrole_id ? this.form.usersofrole_id : 1,
  214. cs_user: this.form.testuser == "是" ? 1 : 0
  215. }
  216. })
  217. if(res){
  218. uni.showToast({
  219. title: "添加成功",
  220. icon: "none"
  221. })
  222. }
  223. },
  224. addusers() {
  225. if(this.form.name==null){
  226. this.TF.nametf = true
  227. }else{
  228. this.TF.nametf = false
  229. if(this.form.name.length<2 || this.form.name.length>10){
  230. this.TF.namelongtf = true
  231. }else{
  232. this.TF.namelongtf = false
  233. }
  234. }
  235. if(this.form.intro==null){
  236. this.TF.iphonetf = true
  237. }else{
  238. this.TF.iphonetf = false
  239. var str = /^1[3-9]\d{9}$/.test(this.form.intro)
  240. if(!str){
  241. this.TF.iphonetftwo = true
  242. }else{
  243. this.TF.iphonetftwo = false
  244. }
  245. }
  246. if(this.form.passwold==null){
  247. console.log(1)
  248. this.TF.passTF = true
  249. }else{
  250. this.TF.passTF = false
  251. }
  252. if (this.form.name && this.form.intro && this.form.passwold) {
  253. this.getaddusers()
  254. uni.navigateTo({
  255. url: './index'
  256. });
  257. }
  258. },
  259. clickLeft() {
  260. uni.navigateTo({
  261. url: './index'
  262. });
  263. }
  264. },
  265. onLoad() {
  266. this.getTypesofroles()
  267. this.getThemes()
  268. },
  269. onReady() {
  270. // this.$refs.uForm.setRules(this.rules);
  271. }
  272. }
  273. </script>
  274. <style lang="scss">
  275. .addusers {
  276. width: 100%;
  277. display: flex;
  278. justify-content: center;
  279. .uForm {
  280. margin-top: 44px;
  281. width: 90%;
  282. .uFormbg {
  283. width: 100%;
  284. padding: 0 20rpx;
  285. margin: 20rpx 0;
  286. background-color: #F7F8FA;
  287. box-sizing: border-box;
  288. .u-form-item {
  289. padding: 0 10rpx;
  290. }
  291. }
  292. }
  293. }
  294. .hintgroup{
  295. width: 90%;
  296. margin: 20rpx auto;
  297. color: #FF0000;
  298. display: flex;
  299. justify-content: space-around;
  300. }
  301. .submitbtn {
  302. width: 95%;
  303. position: absolute;
  304. bottom: -80rpx;
  305. background-color: $uni-color-success;
  306. color: white;
  307. left: 2.5%;
  308. height: 70rpx;
  309. font-size: 32rpx;
  310. line-height: 70rpx;
  311. }
  312. .pop-up {
  313. .sheet {
  314. background-color: white;
  315. height: 400rpx;
  316. overflow: hidden;
  317. .sheet-text {
  318. height: 80rpx;
  319. p {
  320. text-align: center;
  321. height: 80rpx;
  322. line-height: 80rpx;
  323. color: black;
  324. font-size: 16px;
  325. }
  326. }
  327. }
  328. button {
  329. color: black;
  330. position: absolute;
  331. bottom: 0;
  332. width: 100%;
  333. font-size: 16px;
  334. height: 80rpx;
  335. }
  336. }
  337. </style>