index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <uni-forms ref="valiForm" :rules="rules" :modelValue="form" labelWidth="80px">
  5. <uni-forms-item label="用户名" required name="name">
  6. <uni-easyinput v-model="form.name" placeholder="请输入用户名(厂商可以填写工厂名称)" />
  7. </uni-forms-item>
  8. <uni-forms-item label="性别" required name="gender">
  9. <uni-data-checkbox v-model="form.gender" :localdata="genderList" />
  10. </uni-forms-item>
  11. <uni-forms-item label="联系电话" required name="tel">
  12. <uni-easyinput v-model="form.tel" placeholder="请输入联系电话" />
  13. </uni-forms-item>
  14. <uni-forms-item label="密码" required name="password">
  15. <uni-easyinput type="password" v-model="form.password" placeholder="请输入密码" />
  16. </uni-forms-item>
  17. <uni-forms-item label="角色" required name="role">
  18. <uni-data-select v-model="form.role" :localdata="roleList" @change="rolechange"></uni-data-select>
  19. </uni-forms-item>
  20. <uni-forms-item v-if="disabled" label="所属街道" required name="street">
  21. <uni-data-select v-model="form.street" :localdata="streetList" @change="streetchange">
  22. </uni-data-select>
  23. </uni-forms-item>
  24. <uni-forms-item v-if="disabled" label="所属社区">
  25. <uni-data-select v-model="form.community" :localdata="commList" @change="commchange">
  26. </uni-data-select>
  27. </uni-forms-item>
  28. </uni-forms>
  29. <button class="button" type="primary" @click="submit('valiForm')">注册</button>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. disabled: true,
  38. form: {},
  39. // 校验规则
  40. rules: {
  41. name: {
  42. rules: [{
  43. required: true,
  44. errorMessage: '姓名不能为空'
  45. }]
  46. },
  47. tel: {
  48. rules: [{
  49. required: true,
  50. errorMessage: '联系电话不能为空'
  51. }, {
  52. format: 'number',
  53. errorMessage: '联系电话只能输入数字'
  54. }]
  55. },
  56. password: {
  57. rules: [{
  58. required: true,
  59. errorMessage: '密码不能为空'
  60. }]
  61. },
  62. gender: {
  63. rules: [{
  64. required: true,
  65. errorMessage: '性别不能为空'
  66. }]
  67. },
  68. role: {
  69. rules: [{
  70. required: true,
  71. errorMessage: '角色不能为空'
  72. }]
  73. },
  74. },
  75. // 字典表
  76. roleList: [],
  77. genderList: [],
  78. streetList: [],
  79. commList: []
  80. }
  81. },
  82. async onLoad() {
  83. const that = this;
  84. await that.search();
  85. await that.searchOther();
  86. },
  87. methods: {
  88. async search() {
  89. const that = this;
  90. uni.getStorage({
  91. key: 'openid',
  92. success: function(res) {
  93. that.$set(that.form, `openid`, res.data);
  94. that.$set(that.form, `status`, '0');
  95. },
  96. fail: async function(err) {
  97. uni.showToast({
  98. title: '未获取到opneid',
  99. icon: 'none'
  100. })
  101. },
  102. })
  103. },
  104. // 角色选择
  105. rolechange(role) {
  106. const that = this;
  107. if (role == 'cs') that.$set(that, `disabled`, false);
  108. else that.$set(that, `disabled`, true);
  109. },
  110. // 所属街道选择
  111. async streetchange(belong) {
  112. const that = this;
  113. that.$set(that.form, `street`, belong);
  114. //所属社区
  115. const res = await that.$api('/Office', 'GET', {
  116. belong,
  117. type: '1',
  118. is_use: '0'
  119. })
  120. if (res.errcode == '0') {
  121. let commList = []
  122. for (let val of res.data) {
  123. commList.push({
  124. text: val.name,
  125. value: val._id
  126. })
  127. }
  128. that.$set(that, `commList`, commList);
  129. }
  130. },
  131. // 所属社区
  132. commchange(community) {
  133. const that = this;
  134. that.$set(that.form, `community`, community);
  135. },
  136. // 登录
  137. submit(ref) {
  138. const that = this;
  139. that.$refs[ref].validate().then(async params => {
  140. const res = await that.$api(`/User`, 'POST', that.form);
  141. if (res.errcode == '0') {
  142. uni.showToast({
  143. title: '注册信息成功',
  144. icon: 'none'
  145. })
  146. uni.navigateBack({
  147. delta: 1
  148. })
  149. } else {
  150. uni.showToast({
  151. title: res.errmsg,
  152. icon: 'none'
  153. })
  154. }
  155. }).catch(err => {
  156. console.log('err', err);
  157. })
  158. },
  159. async searchOther() {
  160. const that = this;
  161. let res;
  162. //性别
  163. res = await that.$api('/DictData', 'GET', {
  164. type: 'gender',
  165. is_use: '0'
  166. })
  167. if (res.errcode == '0') {
  168. let genderList = []
  169. for (let val of res.data) {
  170. genderList.push({
  171. text: val.label,
  172. value: val.value
  173. })
  174. }
  175. that.$set(that, `genderList`, genderList);
  176. }
  177. //角色
  178. res = await that.$api('/Role', 'GET', {
  179. is_use: '0'
  180. })
  181. if (res.errcode == '0') {
  182. let roleList = []
  183. for (let val of res.data) {
  184. roleList.push({
  185. text: val.name,
  186. value: val.code
  187. })
  188. }
  189. that.$set(that, `roleList`, roleList);
  190. }
  191. //所属街道
  192. res = await that.$api('/Office', 'GET', {
  193. type: '0',
  194. is_use: '0'
  195. })
  196. if (res.errcode == '0') {
  197. let streetList = []
  198. for (let val of res.data) {
  199. streetList.push({
  200. text: val.name,
  201. value: val._id
  202. })
  203. }
  204. that.$set(that, `streetList`, streetList);
  205. }
  206. },
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .content {
  212. display: flex;
  213. flex-direction: column;
  214. .one {
  215. padding: 3vw;
  216. .button {
  217. background-color: var(--f3CColor);
  218. color: var(--mainColor);
  219. font-size: var(--font14Size);
  220. }
  221. }
  222. }
  223. </style>