addUser.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view>
  3. <view class="box">
  4. <view class="top">
  5. <text class="title" v-if="!form.id">添加用户</text>
  6. <text class="title" v-else>编辑用户</text>
  7. </view>
  8. <view class="item">
  9. <view class="l">
  10. <text style="color: red;">*</text>
  11. 用户名:
  12. </view>
  13. <view class="r">
  14. <u-input placeholder="用户名" v-model="form.name">
  15. </u-input>
  16. </view>
  17. </view>
  18. <view class="item" v-if="!form.id">
  19. <view class="l">
  20. <text style="color: red;">*</text>
  21. 密码:
  22. </view>
  23. <view class="r">
  24. <u-input placeholder="密码" type="password" v-model="form.password">
  25. </u-input>
  26. </view>
  27. </view>
  28. <view class="item" v-if="!form.id">
  29. <view class="l">
  30. <text style="color: red;">*</text>
  31. 再输一次:
  32. </view>
  33. <view class="r">
  34. <u-input placeholder="再输一次" type="password" v-model="form.againPassword">
  35. </u-input>
  36. </view>
  37. </view>
  38. <view class="item">
  39. <view class="l">
  40. <text style="color: red;">*</text>
  41. 角色:
  42. </view>
  43. </view>
  44. <view class="item">
  45. <view class="l">
  46. <u-checkbox-group v-model="roleList">
  47. <u-checkbox :customStyle="{marginBottom: '10px',marginLeft:'10px'}"
  48. v-for="(item, index) in checkboxList" :key="index" :label="item.name" :name="item.id">
  49. </u-checkbox>
  50. </u-checkbox-group>
  51. </view>
  52. </view>
  53. <view class="item" v-show="form.id">
  54. <view class="l">
  55. 状态:
  56. </view>
  57. <view class="r">
  58. <radio-group @change="statusChange">
  59. <label class="radio">
  60. <radio value="1" :checked="form.status==1"/>
  61. 可用
  62. </label>
  63. <label class="radio" style="margin-left: 20rpx;">
  64. <radio value="2" :checked="form.status==2"/>
  65. 禁用
  66. </label>
  67. </radio-group>
  68. </view>
  69. </view>
  70. </view>
  71. <u-button type="primary" text="确定" @click="saveFn"></u-button>
  72. <!-- ---------------------------------------------------------- -->
  73. <view class="bottom-safety"></view>
  74. </view>
  75. </template>
  76. <script>
  77. export default {
  78. data() {
  79. return {
  80. roleList: [],
  81. checkboxList: [],
  82. form: {
  83. id: '',
  84. status: 1,
  85. customerId: '',
  86. name: '',
  87. password: '',
  88. againPassword: '',
  89. },
  90. perList: []
  91. }
  92. },
  93. onLoad(options) {
  94. this.form.id = options.id;
  95. this.form.name = options.name;
  96. this.form.status = options.status;
  97. this.roleList = options.roleId ? options.roleId.split(',').map(id => parseInt(id)) : [];
  98. console.log(this.roleList)
  99. let info = uni.getStorageSync('userInfo');
  100. let customerId = info.customerId;
  101. this.form.customerId = customerId;
  102. this.getRoleList();
  103. },
  104. onShow() {
  105. this.perList = uni.getStorageSync('perList');
  106. },
  107. onBackPress() {
  108. this.$common.to('/pages/user/user-index');
  109. return true;
  110. },
  111. methods: {
  112. statusChange(e) {
  113. this.form.status = e.detail.value
  114. },
  115. getRoleList() {
  116. this.$api.getRoleList({
  117. customerId: this.form.customerId
  118. }).then(resp => {
  119. this.checkboxList = resp.data;
  120. })
  121. },
  122. saveFn() {
  123. if (!this.form.name) {
  124. this.$common.toast('请填写用户名');
  125. return;
  126. }
  127. if (!this.form.password && !this.form.id) {
  128. this.$common.toast('请填写密码');
  129. return;
  130. }
  131. if (this.form.password != this.form.againPassword) {
  132. this.$common.toast('两次密码不一致');
  133. return;
  134. }
  135. if (this.roleList.length == 0) {
  136. this.$common.toast('请选择用户角色');
  137. return;
  138. }
  139. this.form.roleId = this.roleList.join(',');
  140. if (this.form.id) {
  141. this.$api.editCustomerAdmin(this.$common.removeNull(this.form)).then(resp => {
  142. if (resp.code == 200) {
  143. this.$common.to('/pages/user/addUserSuccess')
  144. }
  145. })
  146. } else {
  147. this.$api.addCustomerAdmin(this.$common.removeNull(this.form)).then(resp => {
  148. if (resp.code == 200) {
  149. this.$common.to('/pages/user/addUserSuccess')
  150. }
  151. })
  152. }
  153. },
  154. },
  155. }
  156. </script>
  157. <style lang="scss">
  158. page {
  159. background-color: #fff;
  160. }
  161. .hs-item {
  162. text-align: center;
  163. }
  164. .item-line {
  165. color: #a2a2a2;
  166. padding: 5px 0 10px 29px;
  167. border-bottom: 1px solid #E5E5E5;
  168. }
  169. .hj {
  170. padding: 50rpx;
  171. font-size: 40rpx;
  172. color: red;
  173. font-weight: bold;
  174. }
  175. .save-btn {
  176. background-color: #ff4200;
  177. height: 88rpx;
  178. display: flex;
  179. justify-content: center;
  180. align-items: center;
  181. margin: 60rpx;
  182. color: #fff;
  183. font-size: 30rpx;
  184. font-weight: bold;
  185. border-radius: 10rpx;
  186. }
  187. @import '@/common/common.scss'
  188. </style>