index.vue 5.9 KB

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