adduser.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <!-- 新增用户 -->
  2. <template>
  3. <view class="adduser">
  4. <view class="warp">
  5. <view class="item">
  6. <view class="title">账号</view>
  7. <input class="msg" type="text" v-model="userInfo.account" placeholder="请输入账号(系统会自动加上前缀)" placeholder-style="color:#e8e8e8" />
  8. </view>
  9. <view class="item">
  10. <view class="title">用户昵称</view>
  11. <input class="msg" type="text" v-model="userInfo.name" placeholder="请输入真实姓名" placeholder-style="color:#e8e8e8"/>
  12. </view>
  13. <view class="item">
  14. <view class="title">角色</view>
  15. <view class="uni-list-cell">
  16. <view class="uni-list-cell-db">
  17. <picker @change="bindPickerChange" :value="userIndex" :range="userArray" range-key="name" class="uni-upd">
  18. <view class="uni-input" :class=" userIndex === 0 ? '' : 'txtcolor'">{{ userArray[userIndex].name }}</view>
  19. </picker>
  20. <view class="icon-warp">
  21. <image
  22. src="../../../static/images/moreicon.png"
  23. class="iconRight"
  24. ></image>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="item">
  30. <view class="title">手机号</view>
  31. <input class="msg" type="text" v-model="userInfo.phone" placeholder="请输入手机号" placeholder-style="color:#e8e8e8"/>
  32. </view>
  33. <view class="item">
  34. <view class="title">密码</view>
  35. <input class="msg" v-model="passwordone" type="password" placeholder="请输入密码" placeholder-style="color:#e8e8e8"/>
  36. </view>
  37. <view class="item">
  38. <view class="title">确认密码</view>
  39. <input class="msg" v-model="passwordtwo" type="password" placeholder="再次输入密码" placeholder-style="color:#e8e8e8"/>
  40. </view>
  41. </view>
  42. <view class="btn">
  43. <view class="sure" @tap='submitUserInfo'>确认</view>
  44. </view>
  45. <rf-loading v-if="loading"></rf-loading>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. name: 'adduser',
  51. components: {},
  52. data () {
  53. //这里存放数据
  54. return {
  55. loading: false,
  56. userArray: [{ name: '请选择角色', id: '' }],
  57. userIndex: 0,
  58. roleList:[],
  59. // 用户信息
  60. passwordone: null,
  61. passwordtwo: null,
  62. userInfo: {
  63. account: '', // 账号必传
  64. name: '', //昵称必传
  65. roleId: '', // 角色id必传
  66. phone: '', // 手机号必传
  67. password: '', // 密码必传
  68. status: '', // 状态
  69. id: '',
  70. mid: uni.getStorageSync('scenicMessage').id,
  71. }
  72. };
  73. },
  74. onLoad(option) {
  75. console.log(option);
  76. },
  77. onShow () {
  78. this.getRoleList()
  79. },
  80. //方法集合
  81. methods: {
  82. // 角色选择
  83. bindPickerChange(e) {
  84. this.userIndex = e.detail.value
  85. this.userInfo.roleId = this.userArray[this.userIndex].id
  86. },
  87. // 角色列表
  88. async getRoleList () {
  89. await this.$http.get('/mrole/getList',{
  90. mid:this.userInfo.mid
  91. }).then( res=>{
  92. if (res.code === 200 && res.msg==='OK') {
  93. res.data.forEach(element => {
  94. if (element.name) {
  95. this.roleList.push({name: element.name,id: element.id})
  96. this.userArray = this.userArray.concat(this.roleList)
  97. }
  98. });
  99. }
  100. })
  101. },
  102. // 提交表单
  103. submitUserInfo () {
  104. this.verify().then( userInfo =>{
  105. this.loading = true
  106. userInfo.account = uni.getStorageSync('scenicMessage').account + '-' +this.userInfo.account
  107. console.log(userInfo);
  108. this.$http.post('/user/save',userInfo).then( res=>{
  109. console.log(res);
  110. if (res.code === 200 && res.msg === 'OK') {
  111. this.$mHelper.toast('添加成功')
  112. this.loading = false
  113. setTimeout(() => {
  114. this.$mRouter.back()
  115. }, 500);
  116. }
  117. })
  118. })
  119. },
  120. // 表单验证规则
  121. verify () {
  122. return new Promise((resolve,reject) =>{
  123. // 验证
  124. if ( !this.userInfo.account || !this.userInfo.name || !this.userInfo.roleId || !this.userInfo.phone ) {
  125. let obj = this.userInfo
  126. let arr = []
  127. for (let key in obj) {
  128. if (key === 'account' && !this.userInfo.account) {
  129. this.$mHelper.toast('请输入账号')
  130. return
  131. } else if (key === 'name' && !this.userInfo.name) {
  132. this.$mHelper.toast('请输入昵称')
  133. return
  134. } else if (key === 'phone' && !this.userInfo.phone) {
  135. this.$mHelper.toast('请输入手机号')
  136. return
  137. } else if (key === 'roleId' && !this.userInfo.roleId) {
  138. this.$mHelper.toast('请选择角色')
  139. return
  140. }
  141. }
  142. }
  143. if (this.passwordone === this.passwordtwo && this.passwordone && this.passwordtwo) {
  144. this.userInfo.password = this.passwordtwo
  145. } else {
  146. this.passwordone = ''
  147. this.passwordtwo = ''
  148. this.$mHelper.toast('两次密码不一致,请重新输入')
  149. return
  150. }
  151. resolve(this.userInfo)
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang='scss' scoped>
  158. .adduser {
  159. padding-top: 24upx;
  160. .warp {
  161. background-color: #fff;
  162. padding: 0 31upx;
  163. .item {
  164. display: flex;
  165. padding: 30upx 0;
  166. border-bottom: 1px solid #e1e1e1;
  167. &:last-child {
  168. border-bottom: none;
  169. }
  170. .title {
  171. color: #666666;
  172. width: 170upx;
  173. letter-spacing: 2upx;
  174. }
  175. .msg {
  176. flex: 1;
  177. }
  178. .uni-list-cell {
  179. flex: 1;
  180. }
  181. .uni-list-cell-db {
  182. display: flex;
  183. justify-content: space-between;
  184. }
  185. .uni-upd {
  186. width: 100%;
  187. }
  188. .uni-input {
  189. color: #e8e8e8;
  190. }
  191. .txtcolor {
  192. color: #000;
  193. }
  194. .icon-warp {
  195. width: 19upx;
  196. .iconRight {
  197. width: 19upx;
  198. height: 27upx;
  199. }
  200. }
  201. }
  202. }
  203. .btn {
  204. display: flex;
  205. justify-content: center;
  206. align-items: center;
  207. margin-top: 41upx;
  208. .sure {
  209. width: 600upx;
  210. height: 98upx;
  211. background-color: #8064f7;
  212. text-align: center;
  213. line-height: 98upx;
  214. letter-spacing: 2upx;
  215. border-radius: 6upx;
  216. color: #fff;
  217. font-size: 32upx;
  218. }
  219. }
  220. }
  221. </style>