index.vue 5.8 KB

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