addUser.vue 4.4 KB

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